views:

66

answers:

3

I'd like to setup one instance of MySQL to flat-out reject certain types of queries. For instance, any JOINs not using an index should just fail and die and show up on the application stack trace, instead of running slow and showing up on the slow_query_log with no easy way to tie it back to the actual test case that caused it.

Also, I'd like to disallow "*" (as in "SELECT * FROM ...") and have that throw essentially a syntax error. Anything which is questionable or dangerous from a MySQL performance perspective should just cause an error.

Is this possible? Other than hacking up MySQL internals... is there an easy way?

A: 

Impossible.

What you could do to make things work better, is createing views optimized by you and give the users only access to these views. Now you're sure the relevent SELECT's will use indexes.

But they can still destroy performance, just do a crazy JOIN on some views and performance is gone.

Frank Heikens
A: 

If you really want to control what users/programmers do via SQL, you have to put a layer between MySQL and your code that restricts access, like an ORM that only allows for certain tables to be accessed, and only certain queries. You can then also check to make sure the tables have indexes, etc.

You won't be able to know for sure if a query uses an index or not though. That's decided by the query optimizer layer in the database and the logic can get quite complex.

OverClocked
The problem with an ORM is that it sits in the application developer's domain, not the DBA's, so really nothing is solved. But I'll select this answer as technically correct since probably the only viable option is another "layer in between" in the form of Stored Procedures (along with revoke select from all tables!)
Alex R
Alex: true for most standard ORMs, but that's an implementation point. If you think about it, the ORM has two sides, one facing the apps -- offering an object view. One facing the DB. There's no reason why the two sides have to controlled/organized the same way. At my company, we have an ORM that, between these two sides, use an RPC in the middle. So the DB facing side is entirely in the DBA's domain, and the apps facing side is in the apps domain. There just need to be an agreement on the API to the apps, and the implementation of the API is DBA driven.
OverClocked
+1  A: 

As far as I'm aware there's nothing baked into MySQL that provides this functionality, but any answer of "Impossible", or similar, is incorrect. If you really want to do this then you could always download the source and add the functionality yourself, unfortunately this would certainly class as "hacking up the MySQL internals".

Rob