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

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

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

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

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

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

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