MySQL Gets Functions in Java 318
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?"
Apparently somebody already did (Score:2, Informative)
MySQL Ruby Interface [google.com]
Google Cache here [216.239.57.104].
Google's your friend [google.com]
judf uses the Java Native Interface... (Score:5, Informative)
Re:Now how about. (Score:5, Informative)
Re:waaaaiiiit a minute... (Score:4, Informative)
> 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:Nifty!
Re:Keep this out. (Score:5, Informative)
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.
Oracle already does this... (Score:5, Informative)
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.
Re:Java in the DB - very, very bad idea (Score:5, Informative)
> 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:Seems to make sense - start the VM once, call it as many times as you want.
Re:Java in the DB - very, very bad idea (Score:5, Informative)
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.
Re:Oracle already does this... (Score:3, Informative)
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.
Re:Now how about. (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.
Re:Now how about. (Score:3, Informative)
It's trivial really. Announce to the database that you want to perform an online backup. This marks the database in a special mode that lets it know that data writes are going to be at the block level vs. row level.
Also data modifications are still written to the datafiles and also are always written to special files (simultaneously and at the sime time
During an online backup you backup all of the "archived" redo log files for the entire time it takes you to backup the data files. Once you backup the datafiles, and the archived redo log files, you can then take the database out of backup mode, and start doing row level modifications again.
When it's time to restore, the database sees that the restore datafiles are in an incosistent state but that's "ok", because it also knows you have competently saved all of the "missing" changes. The database rolls through the archived log files applying the changes that are neccessary until the database is in a consistent state.
PHP UDF (Score:5, Informative)
http://talks.php.net/show/phpquebec/27 [php.net]
http://www.sklar.com/page/article/myphp [sklar.com]
S
Oh come on, NOT stored procedures (Score:5, Informative)
This is all about writing functions, like no_null in
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...)
Re:That's great (Score:4, Informative)
Re:Now how about. (Score:1, Informative)
Re:Now how about. (Score:2, Informative)
PHP would have been a much better choice (Score:2, Informative)
Java in the database is so 98, that makes me wonder why all companies are trying to conquer the world with the same approach..
PHP would make just a more natural choice for stored procedures, and the approach in MySQL should be to allow stored procedures, triggers and referential integrity (this should be native like in PostgreSQL).
It's weak typed and has a pretty standard MySQL api. However, a metalanguage over PHP to minimize the API and to make it transparent would be nice.
Alexandru
PHP has this for over a year (Score:3, Informative)
Re:PHP would have been a much better choice (Score:3, Informative)
If that's their motivation, they're missing by far. Postgres is *way* closer to oracle.
Postgres does have a plPHP as you're describing. I wouldn't say that being a weakly typed language or having a standard API for talking to a particular type of database make for a good language.
But postgres allows you to make that decision for yourself. Stored functions and procedures may be written in any language and it's easy to plug them in.
Re:Hmmmm (Score:1, Informative)
The puprpose of SQL is not to worry about how to get but what to get.Injecting function calls inside your queries will make your and others life definitely harder especialy in the large projects you mentioned.
I am quite confident that the above will harm performance ass well.
Databe functions(!=injecting function calls inside queries) are definitely usefull. MS access is for SOHO/small companys use.
Chris
Re:Oracle already does this... (Score:3, Informative)
Re:Where is MySQL anyways? (Score:4, Informative)
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
Re:Keep this out. (Score:2, Informative)
However, Java has become more relevant in the past 3 to 4 years as a server-side language. J2EE is an excellent web application platform, and tremendous growth has occurred in that arena. Also, J2ME is also becoming more relevant with the growth in cellphones and PDAs that supports it.
-B
Re:Keep this out. (Score:2, Informative)
As they say in my home country, (to be pronounced with a crazy accent) "If you don't want a monkey, don't buy a monkey."
Re:Java in the DB - very, very bad idea (Score:3, Informative)
I agree that the strongest argument for running Java inside the database is because Java ia full featured programming language. Your example with string parsing sent shivers down my spine.
Embedded Ruby is not thread-safe (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.
Re:That's great (Score:3, Informative)
MySQL lacks several essential features which necessary to implement a proper client/server application -- stored procedures and transactions most of all. Stored procedures are essential for several reasons: security, performance, and efficiency. Stored procedures have better performance because they are pre-compiled; there's significantly less overhead to call an SP than there is to process an ad-hoc query. Stored procedures make programming more efficent because you can write a single, complex set of queries and re-use it across multiple clients.
Perhaps most importantly, stored procedures have several security advantages. If your database allows ad-hoc queries to run against it, it is vulnerable to an injection attack -- an attacker could potentially run any SQL query he wants against your database (EG: update Account set balance = 1000000 where AccountNumber = 123456). A stored procedure acts similarly to a setuid/setgid program in unix, in that it runs with it's owner's permission instead of the user's. This means that you can allow a user to modify a table in a single, very specific manner that they would otherwise not be allowed to touch. Good security is achieved by defense in depth, and stored procedures give you an additional layer of security.
If cost is a concern, then there are alternatives to Oracle: Postgres is signifiantly closer to being a real database than MySQL; and there are zero-cost licenses available from several of the commerial database vendors. Most notably, Sybase 11.0.3.3 for Linux [sybase.com] is available at no cost for any purpose. While a little dated compared to more recent releases, it is still far more mature than any open-source database. Open-source advocacy (zealotry) should never get in the way of making sound engineering decisions.
Re:Krow (Score:4, Informative)
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.