MySQL Gets Perl Stored Procedures
ryarger writes "Woo Hoo! After a seeming eternity of wait, there is finally an implementation of stored procedures for MySQL. It uses Perl as the stored proc language, too!" Also note that this piece of work was done by OSDNs own Krow. Very cool work I must say.
Why didn't they use a Transact-SQL compatible stored proc syntax? This would ease migrating and also enable people who prototype DBs on MySQL to move it to either Sybase or MS-SQL with a minimal of fuss.
I'm not saying Transact-SQL is great or anything but it'd be nice if it was a bit more compatible with other systems.
Could someone enlighten me as to the usefulness of stored procedures? Are they significantly faster? Are they easier to use than the straight jdbc/dbi api?
Unenlightened
My experience has been that someone programming an app doesn't have to learn all the inticacies of Oracle, etc, to get work done. The dba writes procerdures and other people just call that procedure instead of writing huge ugle SQL queries.
Best Slashdot Co
My boss (Windows NT admin) and I were just discussing MySQL. We're running a number of small databases with Oracle on NT (with a University License), but we started talking about MySQL when I mentioned Slashdot was powered by it. Our web server and my workstation are Linux in NT land, and I try to plug Linux wherever I can. My boss is even learning Perl so he can code for our web server.
He liked MySQL until he heard that it couldn't do two things: stored procedures and subselects. He said "I don't see how it could be useful without those things." All of the database apps he's ever written use those.
It's great to see stored procedures being implemented. It would be even better if/when subselects are implemented. I could make a stronger case for moving some things over.
Any chance of it happening?
WoohooO! Now, if they can only work out sub-queries, then I'd be 100% happy! Oh yeah...and get something like SQL*Loader cause I hate doing it the other way!
Wooden armaments to battle your imaginary foes!
Who knows, maybe MySQL will one day be considered a real database product.Until then, though, those of use doing Real Work will continue to use Oracle, DB2, and SQL Server. Of course, these databases already have professional GUI development tools, spatial data modeling, XML table translation, and tons of other fun toys, so the MySQL developers better get to work!
Honestly, besides cheapo webhosts and poorly designed weblogs, who uses MySQL?
DB2 rocks on GNU/Linux, by the way, and it's free as in beer. You should check it out.
--
I like to watch.
Having stored proceedures in any language is better than not having them. The advantages of them are that they can be readily used by other programs, and they don't have to be compiled to be run, so they are faster. Since perl is an interpreted language I'd suspect that the latter benefit is lost. So what I'm hoping for is the future inclusion of stored proceedures written in SQL itself like what is offered in other DBMS systems.
Lee
Muslim community leaders warn of backlash from tomorrow morning's terrorist attack.
What I find extremely funny about this all is that Microsoft is doing the same thing in SQL Server 9.0, by putting the CLR in the SQL Server database. This way you can write your procedures for SQL Server in many languages, including Perl. OUCH. It causes more overhead than you realize to have an interpreter for more than SQL in the database.
:).
:).
I'm a DBA. I have seen the last few versions of Oracle with their Java Stored Procedure and SQLJ support, which is pretty bad. Oracle can't even get their PL/SQL running right between queries and views and stored procedures (the engine has not changed for PL/SQL since 7.3 in 8i, and 9i does not change it that much. Yes, they run 2 engines, one for SQL and one for PL/SQL. It makes Oracle perf tuning a complete nightmare). Yet they find it necessary to shoehorn a complete JVM in. No, no one really uses it, because it doesn't provide advantages.
It only makes the code completely unmaintainable since it's nothing more than code that calls the internal JDBC driver rather than an external one.
PL/SQL, T-SQL, and the other stored procedure languages at least are written in a superset of the main DML/DDL language. This allows you to use the same language optimizer, which reduces code size, and allows for code consistency across the entire project. In other words, all the queries, including parts of stored procedures, get the same optimization treatment.
Having ONE optimizer means that you can make it run really well, and share query plans and cached information. Pretty cool
The other important reason you have stored procedures is because if they are written in the main language, you can leverage the optimizer for query plans and caching of frequently-used or prototyped statements. That's part of the other reason for stored procedures. You can share queries and query prototypes with views and user queries, and have optmization that is better than what writing a procedure in X language can do.
Now we've got Microsoft coming in with their CLR, and mySQL using Perl. This is going to lead to even more unmaintainable code, because you're going to have people coding business logic that can be optimized in the DDL/DML language used in a higher-level language that cannot be.
Talk about a performance problem
From a language and optimization perspective, you always try and use a derivative of the main DML/DDL language of the database, so that you can use the same optimizer for making the statements run faster and perform well.
Anyone can write internal hooks to have a code interpretation engine in a SQL database. Oracle's been doing it for years, and so has Sybase. No one I know uses it because it doesn't provide the real advantages of stored subprograms in a database, which is to store frequently-used and prototyped query statements and aggregations in such a way so that they can be optimally retrieved versus just executed. When you add additional languages, you lose that. Oracle's Java Stored Procedures are nothing more than Java code that calls a different JDBC driver. I don't even want to think of what ADO.NET is going to do in SQL Server 9.
While this seems like a good idea, remember that it's been out for a few years in two other products, and is coming out for another. It's not as big a deal as real SQL stored procedures, because it's not as optimal as they are due to their loose coupling (which describes it perfectly IMHO), and can't share in the same optimization techniques as user SQL queries.
In other words, this isn't something to be too happy about, since it's something that people already have and don't use.
Actually, this is very useful. If you want to do say 6000 inserts using a comma delimited string or something along those lines, to open a connection and call a specific stored procedure is EXTREMELY slow compared to parsing the string internal to the stored procedure (recent test I did when designing some software showed an insert called 6000x took 16 seconds compared to 1.5 seconds parsing the string in the db). Now when you use a language like java or perl to do that internal to the db, it will drop that time even more as SQL design wise has string manipulation features but isn't meant to be doing it. I would much rather have a Java parser that I call inside my sp and have it take half a second versus 1.5 seconds to have PL/SQL parse my strings. If you actually did any development involving database interaction, this would be pretty obvious.
Looks like it might be a while. Better just get PostgreSQL in the meantime.
if they put hooks into a generic MySQL facility which allows *any* programming language to serve as a SP language in the server. Why can't I use Python? Why can't I use xxx? It's widely rumored that Microsoft is doing this same thing for the next version of SQL Server, so this really isn't such a radical idea. The trick is to devise an abstraction within MySQL that represents all stored procedure capabilities, and then interface each target language to that layer.
I agree that having a Transact-SQL equivalent will be key to consideration by serious database users, but it's just a starting point.
Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
PERL is not a good language, and probably an especially bad choice for a stored procedure langauge.
The syntax is a mess, and like many basic-esque languages it's very easy to get into namespace trouble. There are gotchas with strings and escape sequences. Memory is managed with a reference counting garbage collector, which means circular dependencies will create memory leaks; this isn't as serious with kludge maintenance and CGI scripts, but on a database it will be of signal concern. What passes for a language API is what I would call deliberately obscure (lots of one and two letter functions, a million operators, &c &c). On the whole, it's a complete horror show, and just as with Win32, I'm continually amazed at how many things get written against it.
I say stop the cycle of abuse. There are over a dozen free languages that would have been a 100% better choice.
We're on the road to Tycho.
I've looked through the Slash 2 source code and poked around it some and plan to write some plugins. They didn't do a bad job at all. Sure, Python would probably be a better choice, but Slash is better than 85% of Perl code out there.
You don't know the first damn thing about database programming, do you? The stored procedure code isn't re-parsed every time it's run. The execution plan for the query is cached and *that* is run. The performance hit would only be seen the first time the SP was run, when the recompile occurs. Having multiple SP languages would be a very good thing.
No, not really, it is that kind of attitude that got MySQL into the position it's in today, everyone acknowledges it's fast, but nobody has any respect for it as a real database.
No no no, damnit. We need to get past these shitty Procedural SQL hacks. T/SQL and PL/SQL are crap, Why do you think Oracle is integrating Java and Microsoft is integrating ActiveX into the database engine? Because trying to do high-level programming in SQL is complete shit. Why would MySQL want to integrate a legacy language like PL/SQL?
I am gone to Linux World Expo, when I get back the failover should be in place. I have been testing the new replication stuff and it seems to be working fine for me (this is for Slashdot).
You can't grep a dead tree.
A lot of you people are forgetting two other critical reasons why stored procedures are good.
1. Most database pre-parse the stored procedures and keep the cached parsed information in memory. Really complex SQL queries can take a significant amount of time to parse, and cutting down on that overhead can be a huge win for some applications (it was for one of our queries!).
2. Stored procedures can encapsulte logic that requires multiple SQL queries into one call. This saves the network overhead of making multiple trips to the database, which can potentially be huge (and even be REALLY huge if you open up a new connection for each SQL query and then shut the connection immediately).
I don't know if the Perl procedures remain parsed, but at the very least they should be able to accomplish #2. Personally though, I'm going to wait till mySQL supports some sort of Transact SQL like stored procedures. I don't see a justifiable reason for the overhead involved in running Perl on my database. That just strikes me as a bad idea (same goes for java).
Well, one can dream, can't they? :)
Certainly, there are limitations, but to say there are very few cases ignores situations where programmers are migrating from thick to thin clients, using the same query between various languages and is unsure or not satisfied with client-side performance.
Just a very quick example. Let's say you wrote a database application using, oh, I dunno, Sybase and Powerbuider about 4 years ago. Now the client wants everything web-based. Guess what ? Your stored procedures work just fine in the JDBC and the PERL DBI. Problem is, all your code is in client-side/inline sql.
healyourchurchwebsite.com - WWJB?
Right, which is more then a little tricky since MySQL lacks two phase commit support. Its still going to require a human to do the work. But it will be possible at least. We have backups but no way to switch to those on the fly.
I added the static page option about half a year ago so that folks can at least see the front page when we loose the DB.
You can't grep a dead tree.
PERL????
Jesus, PERL????
You know, the strength of query languages is that you don't have to use (and in face, are usually punished for using) loops and cursors to make massive changes. Perl is the most loop oriented language on earth. And even if, underneath it all, the optimizer is turning your code into a loop anyway, it's goddamn doing it more efficiently than Perl ever would. This addition is NOT going to increase the likelihood of people migrating from sybase or other TSQL based databases to MySql...it's going to increase the number of hardliners who feel that MySQL is a pathetic ghost of "real" servers, and as such decrease the cadence of better open source solutions like PostGreSQL. MySQL and Perl...it's fast becoming a database for control freaks who don't believe in doing anything automatically, or allowing the machine to do our optimizations for us -- and that's what computers are all about, goddamnit!
It is nice that there's finally a way to perform object operations on a server without performing the logic in scripted code, and it's nice that MySQL is trying to make a grab for usefulness beyond its INSERT, SELECT, DELETE simplicity. But Perl is not a standard language in the DB world...it's asking for DBAs and programmers used to TSQL and looking for a cheaper, freer alternative to gain new custom knowledge that is complex and no better then the knowledge they already have! All those linux sysadmins to have a little database are going to be overjoyed...but for the rest of us, this is totally useless, just like the rest of MySQL's features.
Hey freaks: now you're ju
and it's a worthy goal. Unfortunately, there's two major problems with them:
1. Too many people use them for procedural programming anyway. There's just things you can't do otherwise, so the capability has to be there. But the capability is often abused.
2. They're too proprietary. I'm not up on ANSI SQL standards enough to know by how much each one deviates and whether the ANSI standard provides a complete enough standard for SP operations, but it occurs to me that MySQL could stand to gain a lot by exactly toeing the ANSI standards line. Just a thought I guess.
Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
Which is a shame considering cursors are high performance basic components in Oracle and Postgres.
Stored proceedures generally need things like variables, control statements, loop capability, stuff like that. SQL doesn't have those.
You'll notice, however, that most other DBs implement sql-like extentions that make sense in their own context; Oracle has 'Procedural Language SQL', SQL Server has 'Transact-SQL' and so on.
I haven't looked at it at all, but I get the impression is that what these guys have done is given you the ability to point to PERL scripts and say 'run that when I tell you to' which is NOT stored procedure capability, but close.
Vintage computer games and RPG books available. Email me if you're interested.
- UPDATE 'foo', map {
... } grep { ... } sort SELECT 'bar', ...
This is the heart of the power of Perl, and if the interface is built right, it could be a huge boon to database work.Of course, done wrong it could be slow, difficult to maintain and immediately obsolete.
If anything, then Java.
Oracle even moves PL/SQL (which isn't bad either) to Java. I'm sure Java will be the de facto SP language in the future for Oracle and DB2 (which have more than 60% of the market together). Just drop a JVM in the database core, and write a special JDBC driver for this.
No need to implement and maintain a fully new language.
Postgres home page
Remember that what's inside of you doesn't matter because nobody can see it.
Most people are using SQL engines just to store basic records, that sometimes even don't need any sort of indexation.
SQL engines are slow and unreliable. Almost everytime I see a web site down (even Freshmeat) it's due to a database crash. SQL is a brain damaged query language. SQL tables have an horrible obsolete Cobol-like structure (every record must have a fixed len to be handled efficiently, types are fixed, etc) .
Sure, they can be useful for something.
But for 99% of the projects they are used for, they could be easily replaced with a simple indexing library like CDB, GDBM or BerkeleyDB (BDB itself is very powerful, it has a lot of nifty features, plus it's rock solid and damn fast) .
Or even flat files. I've seen so many people using complex SQL tables just to store 50 poor records. Just crazy. Do people know that filesystems can store data, too ? Does Squid need Oracle to store the cache ?
I never used SQL (although I coded large search engines and other stuff that stores and index a lot of data) . And I don't want to. BerkeleyDB achieve the same thing on a 386 than *SQL on a Thunderbird.
{{.sig}}
Basically, it says that MySQL is faster and more stable, and that PostgreSQL has transactions. Which is more important? How about a database that doesn't crash when you put a tiny bit of load onto it. I'll stick to MySQL, thank you, and the addition of Perl as a language for stored procedures will make it even better and more useful.
Even Slashdot wants to hide some things
I certainly wouldn't use postgresql on windows (although I might if I bought it from great bridge). If you want a windows DB that open source, proven, stable, mature, reliable, fast, supports stored procedures, triggers, and has fantastic GUI tools may I recomend interbase. It does not have loadable stored procedures but does support domains and column level localization. Also consider SAPdb which is a very robust server from SAP the giant ERP company. They open sourced it a while ago.
War is necrophilia.
Ought to work.. anybody tried using it?
All I want to see is just *one* benchmark from the MySQL folks that isn't blatant dishonesty or incompetence.