Slashdot Mirror


MySQL Gets Functions in Java

Java Coward writes "Eric Herman and MySQL's Brian "Krow" Aker have released code to allow the DBMS MySQL to run Java natively inside of the database. The code allows users to write functions inside of the database that can be then used in SELECT/INSERT/UPDATE statements. So when will someone do Ruby?"

21 of 318 comments (clear)

  1. Now how about. by DAldredge · · Score: 5, Interesting

    Now how about a way to do online backups of the new table types with out having to buy a license to do it?

    1. Re:Now how about. by jamie · · Score: 5, Informative

      Replicate to a slave DB that isn't used for anything but backups. On the slave, you can do a 'mysqldump -x'. That'll block updating while it does the write, but you won't care. The only problem arises if your hardware is too slow to catch up replication before the next time you do the dump, in which case you're kind of screwed anyway. This works on both myisam and innodb tables.

  2. Hmmmm by cluge · · Score: 4, Insightful

    I wonder how this affects performance especially compared to regular user defined functions? (Available in later releases of MySQL). This is indeed an interesting twist. It certainly can help speed up development of large projects (java works well in a large/many programmer env.) Like a lot of other tools, it remains to be seen how people put this to use. Too often people learn one thing, and like the saying goes, when all you have is a hammer, every problem looks like a nail. Lets see where this goes shall we?

    --
    "Science is about ego as much as it is about discovery and truth " - I said it, so sue me.
  3. database language? by Anonymous Coward · · Score: 5, Funny

    So when will someone do Ruby?
    Warning, engaging humor mode *puts on asbestos suit just in case*

    After someone does perl and python ?

    (notice that both of those languages, as well as tcl, are already included in the other free database project: postgres)

  4. judf uses the Java Native Interface... by tcopeland · · Score: 4, Informative
    ....to start up the Java VM. From judf.cc:
    // Create the Java VM
    jint res = JNI_CreateJavaVM (&jvm, (void **) &env, &vm_args);
    Embedding a Ruby interpreter would reduce startup time, probably.
  5. Re:Keep this out. by gustgr · · Score: 4, Insightful

    I don't know why everybody wants to keep distance from Java. It is a very nice language implementing the very well the OOP paradigm.

    The 'lusers' may not use this new feature but Java programmers will and hopefully will enjoy it.

  6. That's great by j0hndoe · · Score: 5, Insightful

    I used Java stored procedures a lot back when I was working at a .com. For someone who's already using Java its a lot easier than learning each database vendors proprietary language. It's also good for keeping MySQL feature competitive with open source dbs, since Java stored prcedures have already been implemented for PostgreSQL

  7. Re:Keep this out. by j3110 · · Score: 4, Insightful

    Did you not think about that post? Sounds like you just dislike Java so much that hearing it in the same sentance as MySQL makes you cringe.

    1) Java isn't going to slow down any queries unless you use Java functions.
    2) What do you care that someone else isn't smart enough to write good software?
    3) MySQL as it stands has no other way to really embed functions easily, and it's actually more effecient to run code on the server and transfer data back afterwords.

    --
    Karma Clown
  8. Re:Keep this out. by Blackknight · · Score: 4, Informative

    I care because when you have 200 shared hosting accounts on one server all it takes is one idiot to load things down.

    Most of the time we detect who it is and suspend their account, but I still wouldn't want them running java code inside mysql.

  9. Oracle already does this... by XaXXon · · Score: 5, Informative

    The thing no one seems to have mentioned is that Oracle already does this and has for many years. I can't find any docs on it off-hand, but I know you can just drop a .jar file into Oracle and it will let you do similar stuff. This is nice because it lets you use a common language for doing your stored procedures instead of learning a different language for each database (e.g. Oracle uses PL/SQL).

    People who are saying "what's the use of this" or "This is just going to bog down the database" most likely have never worked in the industry. Stored procedures are a very common part of large systems and adding this functionality to MySQL will go a long ways in promoting MySQL use in bigger companies.

  10. Where is MySQL anyways? by Chitlenz · · Score: 5, Interesting

    As an Oracle DBA, at a small company, we're constantly looking for less expensive SOLID alternatives to our traditional Oracle/Solaris approach to the back end.

    When I say solid, I mean is able to handle very large files (excess of 50GB per datafile), has stored procedures and trigger infrastructure (a traditional MySQL weak point, and the main reason we've passed on it so far), an integrated backup system a la netbackup/RMAN, and prefereably a back end compiled scripting solution a la PL/SQL.

    This looks like a sorta kinda solution to the last (PL/SQL alternative), but I'm curious to know about the rest, and also how it performs. Ideally for us, we'd also like to see better clustering and large system support examples in the real world before we embarked onto this particular voyage with.. say a production ERP system.

    Are we talking about a good replacement for Access or for DB2 here?

    Enquiring minds want to know ...

    -chitlenz

    --
    Imagination is the silver lining of Intelligence.
    1. Re:Where is MySQL anyways? by BigGerman · · Score: 5, Interesting

      Postgresql seems to be the ticket.
      I have been doing Oracle work for 12 years and find Postgres easy to learn and quite powerful.
      Certainly ref integrity, triggers and PL/SQL like stored procedures are all there.
      I currently have 80GB PostgreSQL database as a backend for pretty busy websites and it holds well.
      THIS is not a solution, just a proof of concept. I looked at the code and it is not even thread-safe.

    2. Re:Where is MySQL anyways? by jdgreen7 · · Score: 5, Interesting

      We ended up moving all of our scattered Access Databases to MySQL about a year ago, and have never looked back. We still use Access as a front-end to get at the data, and everything has worked beautifully. Using Access gives us a consistent UI for each app, and it's quick and relatively painless to add new apps or features. And, using MySQL for the data is orders of magnitude faster that Access MDB files.

      As far as 'enterprise level' features, MySQL is still missing Stored Procedures, easy 2-way replication, and clustering (there are many projects out there that add these features, but none of them are included in the main branch AFAIK). They keep getting closer with each release, though.

      No, it's not ready to take on Oracle yet, but for mid-size shops (we regularly have 30-50 concurrent users all day from various remote locations), it's a great product. Slashdot runs it, and they seem to be able to handle quite a bit of a load. It's proven itself to me, but then again, I've never played with Oracle or DB2. It has a very active developer base, so things are changing all the time.

      PostgreSQL has more enterprise features, but it's not used as much as MySQL. It seems pretty solid, though. We toyed with a bit, but my boss decided to go with MySQL mainly because he had heard of it before.

  11. Re:Java in the DB - very, very bad idea by tcopeland · · Score: 4, Informative
    > Is mySQL process going to start the
    > whole new JVM on every hit?

    No. Look at judf.cc. There's a judf_init and a judf_deinit. judf_init starts up the VM and hangs on to it in here:
    static JavaVM *jvm = NULL;
    Seems to make sense - start the VM once, call it as many times as you want.
  12. Re:Java in the DB - very, very bad idea by laird · · Score: 5, Informative

    "The ability to write stored procedures in Java has been in Oracle for some time but I still cannot figure out why anyone would do that."

    Here are some reasons:

    1) Java runs _way_ faster than PL/SQL. This is because lots of people have been working in making Java run very efficiently compared to PL/SQL. I've seen people port from PL/SQL to Java stored procedures justified purely by increased system performance.

    2) It allows for consistent coding between database-resident and application server-resident code. This means that you don't need to train people in two very different languages to get work done.

    3) It allows for code portability between the database and application-server. This lets you tune performance. For example, if you have some code that does tons of database I/O, it may run far more efficiently inside the database rather than accessing the database across a network.

    I don't know how well the MySQL guys integrated Java yet, but in Oracle it's pretty wonderful compared to using their weird, slow, proprietary language.

  13. Re:Sounds like... by the+uNF+cola · · Score: 5, Insightful

    We all don't like learning the database language of a database. It's annoying that oracle, sybase, postgresql and mysql support different sets of ansi92 (or 98) sql, but they all have different gotchas..

    limiting the # of rows of output is different between oracle, sybase and postresql/mysql.

    None of them even have remotely the same stored proc language. Of course, everyone may embed a different language, but java seems to be a more common one.

    Now when you go from sybase to oracle, you don't have to worry so much about the stored procedure code, since it'd all be in java anyway.. riight?

    --

    --
    "I'm not bright. Big words confuse me. But Wanda loves me and that should be enough for you." - Cosmo

  14. simple. by flacco · · Score: 4, Funny
    So when will someone do Ruby?

    i will as soon as i can get her to drink this liter of vodka.

    --
    pr0n - keeping monitor glass spotless since 1981.
  15. Re:Java in the DB - very, very bad idea by randolfe · · Score: 5, Interesting

    The knees jerk so fast on /. whenever Java is mentioned, in any context, that I'm surprised someone doesn't have their eye put out.

    Of course there exist myriad reasons why one would prefer to standardize on a common language for DB SPs. Java, in this regard, is the most mature alternative at present. Even the notoriously skeptical Thomas Kyte and the pontificating Steven Feuerstein see the validity of Java in the database at the SP level.

    Of course, *we* can all keep fighting amongst ourselves about such things while Visual Basic and C(flat) become the only languages we have to chose from for everything we endeavor to do.

  16. PHP UDF by TheTomcat · · Score: 4, Informative

    There's similar functionality s/java/php/g, here:

    http://talks.php.net/show/phpquebec/27
    http://www.sklar.com/page/article/myphp

    S

  17. Oh come on, NOT stored procedures by Jhan · · Score: 4, Informative

    This is all about writing functions, like no_null in

    select no_null(oftennullfield)||" "||otherfield from...

    MySQL has always had an expansion framework for adding you own functions to the SQL, it's just that traditionally you had to have a compilable language to do that. Now, you can use Java methods as well. (Still not a bright idea IMHO, but...)

    --

    I choose to remain celibate, like my father and his father before him.

  18. Embedded Ruby is not thread-safe by jdoeii · · Score: 4, Informative

    So when will someone do Ruby?

    Not soon. Ruby cannot be embedded in a threaded application without using a giant mutex. Only one thread at a time can call Ruby interpreter.