[DB-SIG] Help on this query

Andy Todd andy47@halfcooked.com
Wed, 05 Jun 2002 14:36:26 +1000


Chris Cogdon wrote:
> On Tuesday 04 June 2002 20:53, Andy Todd wrote:
> 
> 
>>You are absolutely right, I am an idiot. Mind you, thats some pretty
>>scary SQL you have there and, as you say, it won't work in every
>>database. I've been sitting here scratching my head trying to come up
>>with some ANSI standard SQL that will do the job and failing terribly.
> 
> 
> Of course, there's lots of stuff you can do in python. However, the fewer 
> queries you make to the server, and the less information that has to come 
> back for processing within python, the faster things will go.
> 
> 

Again true, but beware premature optimisation. For all we know two 
simple queries and a little bit of Python code are just as efficient as 
the pure SQL you posted.

In fact, in Oracle that would end up in two queries at the server anyway 
and would probably result in more process cycles to complete (as the 
intermediate result sets are cached). Contrast that with the overhead of 
storing two numbers at the client end. The cost of parsing not 
withstanding, of course.

Anyway, its a purely theoretical argument, I just try and follow the 
tenets of the Pragmatic Programmers (and Uncle Tim) and keep it simple.

Ninety nine times out of a hundred the extra cost of having multiple 
simple SQL statements versus one complex statement are worth it in the 
time saved developing, debugging and testing. If the simple approach 
causes a hot spot in your system then by all means optimise, but we 
shouldn't fuss about it until it *is* a problem.

Besides, 99.9997% of database performance problems can be removed by 
adding an index <0.5 wink>

Regards,
Andy
-- 
----------------------------------------------------------------------
 From the desk of Andrew J Todd esq - http://www.halfcooked.com