Re:How to assert that your SQL does not do full table scans
by mullr on Friday March 26, 2010 @11:12AM
(#1221187)
But for those cases where you are just pulling a row or two, this is a nice technique. It hints at something more interesting, I think.
Fundamentally it wants to be an assertion against the schema. It would be better to be able to ask the database about the worst-case complexity of a particular query, then write assertions against that. (I don't think this is the same as 'explain', it's more like 'explain as if' with some structure behind it)
Something like: assertEqual( O(log(n)), schema.worstCaseComplexityOf('SELECT text FROM response WHERE questionId = 27 AND participantId = 38'))
Even better would be a schema language that lets you build in these assertions directly. This is really something you should be thinking about while designing the schema, after all.
Re:How to assert that your SQL does not do full table scans
by msluyter on Friday March 26, 2010 @11:13AM
(#1221194)
Indeed. Also, a full table scan can take advantage of multi-block I/O, so you really can't rely on grand generalizations. For anyone interested in these topics in an Oracle context, I recommend Tom Kyte's books.
Sure, for simple cases where you're pulling a row or two from the heap, an index scan will be vastly cheaper, but just because they're sometimes better, doesn't make them always better.