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?"

15 of 318 comments (clear)

  1. 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.
  2. 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.

  3. Re:waaaaiiiit a minute... by tcopeland · · Score: 3, Informative
    > you are storing java functions/objects
    > in the database?

    Nope, they're external to the DB.

    > program your own functions like
    > insert/modify/etc in java

    You can program functions in Java, and then call them from MySQL queries. From the README:
    To run the sample Java DBMS function
    mysql> SELECT judf("test/GreenBar", COLUMN1, COLUMN2) FROM foo;
    Nifty!
  4. 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.

  5. 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.

    1. Re:Oracle already does this... by KenSeymour · · Score: 3, Informative

      Yes Oracle has this. IIRC so does DB2.

      One place where I worked, they had a bunch of Java stored procedures doing things you could have done in PL/SQL.
      They later re-wrote them because the performance is so much worse.

      There are, however, things it might make sense to do in a Java Stored Procedure. Publishing a message using JMS from a trigger is an example.
      I am not sure if Oracle has created utility packages so you could do it from PL/SQL.
      But having a Java stored procedure in this case would allow you to use the same message class that is used by the subscribers to the message.

      I don't think this will bog down non-Java users of MySQL.

      Years ago, when I was using DB2, I noticed that they had external stored procedures that could be written in nearly any language. C, Java, COBOL, you name it.

      --
      "We can't solve problems by using the same kind of thinking we used when we created them." -- Albert Einstein
  6. 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.
  7. 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.

  8. Re:Now how about. by Cajal · · Score: 3, Informative

    There needs to be someway of doing online back ups of MySQL with out spending money.

    Why not just use PostgreSQL? It's had hot-backup of tables for years.

  9. 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

  10. 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.

  11. Re:That's great by krow · · Score: 3, Informative

    Stored Procedures are in 5.0.

    --
    You can't grep a dead tree.
  12. Re:Where is MySQL anyways? by jadavis · · Score: 3, Informative

    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.

    Yeah, postgres has always had a recognition problem. I like it because of the data integrity features, and the only feature I would really like is point-in-time-recovery (incremental backup, whatever you want to call it).

    It's strange how much recognition matters, even when postgres runs the .info registry, the .org registry, and I think the american chemical society has a database >1TB. I'm a postgres fan, so it's a little disappointing to see it rejected like that. I think it will help a lot when they get the windows port out.

    --
    Social scientists are inspired by theories; scientists are humbled by facts.
  13. 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.

  14. Re:Krow by krow · · Score: 3, Informative

    Auditing the code should be trivial for anyone (judf is actually quite small).

    I resigned because I had been working on Slash for 3 years and wanted to do something new. I rather like the people who run this site, and still follow the development of it and point out feature improvements from time to time. I no longer develop the code myself, except for a few sites that I happen to help with.

    Just to poke another hole in this, if I was fired would I still be an author on the site some 7 months later? I think not.

    --
    You can't grep a dead tree.