开发者

Is there some kind of "strict performance mode" for MySQL?

开发者 https://www.devze.com 2022-12-22 06:00 出处:网络
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 trac开发者

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 trac开发者_运维百科e, 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?


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号