Stories
Slash Boxes
Comments

News for nerds, stuff that matters

MySQL Gets Perl Stored Procedures

Posted by CmdrTaco on Fri Aug 24, 2001 11:52 AM
from the well-isn't-that-special dept.
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.
This discussion has been archived. No new comments can be posted.
Display Options Threshold:
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • Better stored proc languages... (Score:3, Interesting)

    by Hagabard (461385) on Friday August 24 2001, @11:57AM (#2213941)
    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.

  • That's great. (Score:1, Offtopic)

    by briggsb (217215) on Friday August 24 2001, @11:58AM (#2213943)
    I've been waiting for that. Good job Krow.

    Now if we could only get high school students [bbspot.com] to understand Perl and MySQL we'd be all set.

    • 1 reply beneath your current threshold.
  • Rock on! (Score:1)

    by xZAQx (472674) <zrizerNO@SPAMsbcglobal.net> on Friday August 24 2001, @11:58AM (#2213945) Homepage
    Bring on the GUI apps. Guess now I've got yet another reason to learn Perl
  • Java (Score:1)

    by sean@thingsihate.org (121677) on Friday August 24 2001, @12:00PM (#2213958) Homepage
    But what about the java? The java support on Oracle is pretty damn nice, and damn it, I don't think it's "crazy" to expect the same kind Oracle-quality from mysql...

    TEH SEANS@!!@!@
    • Re:Java by pinkelefant (Score:1) Friday August 24 2001, @12:57PM
      • Re:Java by The_Messenger (Score:1) Friday August 24 2001, @01:51PM
    • Re:WTF? by dameatrius (Score:3) Friday August 24 2001, @12:32PM
      • 1 reply beneath your current threshold.
    • 3 replies beneath your current threshold.
  • Not a DB guru (Score:2)

    by Sir_Real (179104) on Friday August 24 2001, @12:01PM (#2213968)
    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
  • by BillyGoatThree (324006) on Friday August 24 2001, @12:03PM (#2213986)
    ...but you have to wonder about a product that is made *easier* by adding *Perl*.
  • by Si (9816) on Friday August 24 2001, @12:05PM (#2213998) Homepage
    whether to write application logic as Perl in MySQL, or as SQL in Perl..

  • Subselects? (Score:3, Funny)

    by hetfield (129762) <hetfield@hetfield.net> on Friday August 24 2001, @12:17PM (#2214071) Homepage
    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?
  • But wait... (Score:2)

    by don_carnage (145494) on Friday August 24 2001, @12:18PM (#2214082) Homepage
    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!
  • by The_Messenger (110966) on Friday August 24 2001, @12:19PM (#2214099) Homepage Journal
    Wow, now they only have to implement constraints, foreign keys, and transactions, and they'll almost be on the level of Postgresql.

    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 [slashdot.org], who uses MySQL?

    DB2 rocks on GNU/Linux, by the way, and it's free as in beer. You should check it out.

  • 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
  • Is it offical (Score:1)

    by fava (513118) on Friday August 24 2001, @12:26PM (#2214131)
    From mysql.com's todo page (http://www.mysql.com/development/todo.html) under the heading of "Things that have to be done sometime":
    Stored procedures. This is currently not regarded to be very important as stored procedures are not very standardized yet. Another problem is that true stored procedures make it much harder for the optimizer and in many cases the result is slower than before We will, on the other hand, add a simple (atomic) update language that can be used to write loops and such in the MySQL server.
    What are the chances that this patch might make it into an offical release of mySQL, I know that that they are reluctant to add features that are not created by themselves.

    Yes I also know that I can/should recompile from source but most people will simply install the binaries.

  • 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.
  • Cool! (Score:1)

    by Anomolous Cow Herd (457746) on Friday August 24 2001, @12:33PM (#2214182) Journal
    Now I can edit GIFs and add GUIs to my database functions! This is great, now if only I can convince my boss that we need this. Oh, and also convince him to upgrade from the dual Xeon to the 8-way machine to handle all the overhead.


    Sheesh, could they have made a more braindead move?

  • by dave-fu (86011) on Friday August 24 2001, @12:38PM (#2214208) Homepage Journal
    I'll probably get modded down for daring to ask this, but am I missing something here? Why stored procs in Perl and not in, say... SQL?
    Or is being server-agnostic a Bad Thing now?
  • Mysql todo list (Score:3)

    by Jeffrey Baker (6191) on Friday August 24 2001, @12:38PM (#2214212)
    Great! MySQL crosses off another thing on their list of things they need to do to catch up with PostgreSQL:
    • New logo (check)
    • Stored procedures in Perl (check)
    • Stored procedures in C, C++, Python, TCL
    • Langauge similar to PL/pgSQL
    • User-defined datatypes
    • Transactions
    • Subqueries
    • Constraints
    • Stop being a bunch of whining Euro sue-boys

    Looks like it might be a while. Better just get PostgreSQL [postgresql.org] in the meantime.

  • and why? (Score:1)

    by orcldba (195785) on Friday August 24 2001, @12:50PM (#2214299)
    The biggest advantage of stored procedure is that it is compiled and can be executed immediately after load into memory and binding variables to it. You also can nicely pin stored procedures into a memory so it will not get booted out and it will perform pretty well.
    Correct me if I am wrong, but perl is interpreted language. So what is the point? It will take exactly the same time to execute the thing as I would have the proc outside of the database...
    Just my 2C (canadian)
  • by gol64738 (225528) on Friday August 24 2001, @01:04PM (#2214384)
    more people are beginning to realize that between python and php, perl is useless. not to mention the fact that the code syntax was stupid to begin with.

    sorry perl, you had your day, but you are now outclassed.
  • makefile (Score:1)

    by kootch (81702) on Friday August 24 2001, @01:08PM (#2214416) Homepage
    so uh, anyone mind writing a makefile for this?

    i love brian's comment in the "install" file tho. yea...you just need to re-configure perl, and if it's done wrong it will core on you...
  • I was rereading an old story from when Slashdot moved to Exodus, and Malda has this to say:
    Fault tolerance was a big issue. We've started by load balancing anything that could easily be balanced, but balancing MySQL is harder. We're funding development efforts with the MySQL team to add database replication and rollback capabilities to MySQL (these improvements will of course be rolled into the normal MySQL release as well).

    I'm curious, Taco, what happened with this? It was before VA Itsux bought Bendover, so maybe the funding got nixed then? Or did they spend all of the money on designing the new logo? [mysql.com]
  • by DaveWood (101146) on Friday August 24 2001, @01:21PM (#2214508) Homepage
    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.
  • One other reason (Score:2, Insightful)

    by Dalroth (85450) on Friday August 24 2001, @01:48PM (#2214668) Homepage Journal
    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).
  • by 01010101 (159722) on Friday August 24 2001, @01:59PM (#2214754)
    Relational databases are slow and unscalable.
    Can I add another box and double my query or
    insert capability? No.

    But, I can add another app server and theoretically double my ability to execute code. People who design enterprise applications to use stored procedures are giving up their ability to scale. The exception to this rule is when stored procedures perform aggregations, and time series analysis. However, I will go so far as to say that using a relational database to perform ad-hoc analysis is a stupid thing to do and a billion dollar industry has grown up around solving this problem in a better way (OLAP).

    ALL enterprise applications I've seen that use stored procedures were failures because they could not scale. They had to be rewritten and redesigned from scratch.

    As other posters have said, this is not much to be happy about.
  • PostgreSQL (Score:1)

    by howardjp (5458) on Friday August 24 2001, @02:18PM (#2214879) Homepage
    PostgreSQL has had Perl, Tcl/Tk, C, and hooks for other languages for some time now.
  • by Craig Maloney (1104) on Friday August 24 2001, @02:50PM (#2215073) Homepage Journal
    I wonder if Oracle will allow Perl Stored Procedures. I despised PL/SQL when I had to use it, since I could do everything PL/SQL did in Perl (minus triggers).

    Well, one can dream, can't they? :)

  • 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.
  • by ajs (35943) <ajs@aj[ ]om ['s.c' in gap]> on Friday August 24 2001, @04:21PM (#2215470) Homepage
    Wow, can you imagine doing
    • 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.
  • by l00sr (266426) on Friday August 24 2001, @04:47PM (#2215603)
    I'm sorry, but all this talk of MySQL's lack of subselects has got me all worked up. Could someone explain to the rest of us why the suckers are so hard to implement? It always seemed to me like it would be intuitively simple -- just execute the subselect, dump the result set into a temporary table, replace the subselect text in the main statement with the name of the temporary table, execute the main statement, delete the temporary table, etc. Is there any reason why it can't be this simple?
  • SQL sucks (Score:2)

    by chrysalis (50680) on Friday August 24 2001, @04:54PM (#2215634) Homepage
    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.
    • Re:SQL sucks by Tablizer (Score:1) Saturday August 25 2001, @04:47PM
  • Perl is a Scripting language ( read interpreted) Stored procedures, by default are SQL statements which are compiled by the server and used as db objects... so, doesn't this defeat the purpose of having a (speedy, compiled) SQL statement?
  • by nograz (267831) on Saturday August 25 2001, @06:09AM (#2216090)
    I enjoy seeing MySQL becoming a mature database, but I do not exactly know what this hype is all about!? PostgreSQL supports server-side programming for a long time now (the same way it supported transactions long before!). At the moment it supports three different (and working) implementations:

    - PL/pgSQL (this is the counterpart to ORACLE PL/SQL)
    - PL/Tcl (TCL Procedural Language)
    - PL/Perl (yes, this is server-side perl implementation!)

    Here the pointer to the corresponding manual entry [postgresql.org]
  • by bad-badtz-maru (119524) on Saturday August 25 2001, @01:11PM (#2216402) Homepage

    How can we comment on how good or bad this is when (per the development web site) there is no benchmark as to how expensive this functionality is? If it makes queries execute at a tenth of the "normal" speed and also adds 15 megs onto each mysql instance, then that would certainly factor significantly into the "usefulness" equation.

    maru
    www.mp3.com/pixal
  • I don't know if this will work with the subject of this story, but if the Inline module is supported it will let you also use Python, Java, C, C++, Tcl, Assembler, Guile, and whatever somebody else feels like glueing in.

    Ought to work.. anybody tried using it [cpan.org]?

  • by bartwol (117819) on Friday August 24 2001, @12:11PM (#2214035)
    ...you too are among us, the trash.



    <bart

    [ Parent ]
  • Re:Lame (Score:1)

    by Drazi100 (458128) on Friday August 24 2001, @12:38PM (#2214206)
    you may be right about MySQl being that. I like MS SQL. Its the only product they have made that is any good. too bad it only functions on that buggy OS which makes linux look like King.("buggy OSS" project as you like to call it)
    BTW as a SQL SERVER dba, I usually reach for my pistol when anyone asks me to use ASP( another buggy MS crap) on it.
    [ Parent ]
  • Actually (Score:2)

    by Micah (278) on Friday August 24 2001, @01:27PM (#2214545) Homepage Journal
    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.
    [ Parent ]
    • Re:Actually by smallpaul (Score:1) Friday August 24 2001, @02:56PM
  • Re:Perl Yuck! (Score:1)

    by trilucid (515316) <pparadis@havensystems.net> on Friday August 24 2001, @01:39PM (#2214621) Homepage Journal

    Now, I know I'm responding to an AC post, which is admittedly not terribly bright since it's obviously a troll anyhow, but I feel I need to pop my 2 cents in here...

    Back at my old "full time" job, we used MS SQL databases in production at a Windows NT-based NOC. Incidentally, this was for the BOA telephone banking system itself (yep, I was a coder on that team, it's mostly written in VB6). Anyhow, I used mySQL for personal purposes, and eventually got around to (of course) reproducing some of the system logic in C/Perl and mySQL. Guess what? On limited stress tests, my system held up fine. Of course, I wasn't about to try to evangelize my job away, but the point remains valid that it could have worked in production.

    Fast forward to the present, where I run a small web hosting and web application design company (see sig fo mo). All our clients use mySQL and Perl for their solutions, most of which are quite robust and flexible. Not to mention fast; we run a pure Linux shop for that stuff and haven't had any competition anxiety with Windows shops.

    The progess with things like stored procedures in mySQL and such may have been a bit slow, but it's getting there. Hey, last I checked /. ran on mySQL, not to mention the ever-popular time waster HotOrNot.com. Just my perspective, of course...

    [ Parent ]
  • Re:Why MySQL ? (Score:1)

    by Betcour (50623) on Saturday August 25 2001, @03:50AM (#2215924)
    Why ? Because up to a few months ago things like BLOB had to be handled in a screwed up ways, because some types are missing, because indexes on 64 bit values seems to not work, etc...

    postgreSQL is much more feature rich but not perfect, and the documentation is seriously not in sync with latest release (forcing you to dig thru mailling list archives to find how to use this or this feature)
    [ Parent ]
  • 18 replies beneath your current threshold.