views:

53

answers:

3

This is kind of a weird question but...
If I run this query in MySQL:

SELECT something FROM table WHERE id IN ();

which is obviously invalid, do I get some kind of time penalty (exception throwing, logging, something), compared to throwing a valid query?

The reason I'm asking is because I just found out an app I'm maintaining (not written by me) was throwing that particular query dozens of times per second to the DB, and I'm wondering whether fixing that might help with some weird performance problems we have on that same server.

My reasoning being based on "exceptions" being "slow" in a regular language, although I perfectly understand that there is absolutely no parallel here and that hasn't got anything to do with anything. Buy maybe there's some logging involved, or something that makes it slower?

Any ideas?

UPDATE: I should've specified this. I did fix this as soon as I found it. But we're having some weird performance problems in the server, and I wanted to see whether I could expect this to help considerably. Saving 15 regular queries per second to a server with this load is definitely not a big help (although i'm still doing it anyway). However, if an invalid query has to do something that takes time, then maybe....

Thanks! Daniel

A: 

It shouldn't be especially slower than a valid query, since the server has to parse the query and return a result to the client (data set or failure status) either way.

Of course, if the application doesn't need to issue the query in the first place (i.e. it's not simply a coding error where there should be a condition, but it got left out) then you certainly should be able to save a little work by not issuing it at all.

Andrew Medico
Yes, yes, I've fixed this, of course, I was just curious whether this could've been a part of our performance problems in that server...
Daniel Magliola
+1  A: 

Tried this just for fun and watched execution times with valid and invalid value. No Noticeable execution time difference. I would still argue for fixing based on wasted trips to database.

Roadie57
+1  A: 

A syntactically bad query won't need to access the database at all, so it should be much faster than one which needs to do work (but didn't return anything anyway).

Having said that, the optimiser can sometimes spot stupid stuff, so if you said WHERE 1=0 then it would throw back an empty set without actually touching the tables.

MarkR
Right, but is there more logging for a bad query than for a good one? (Enough that it might compensate)
Daniel Magliola
No, bad queries don't get logged. An error response is sent back, that's all. An error response isn't particularly different from an ok response (it may include an error message, but I can't see that making much difference).
MarkR