View Single Post
  #12 (permalink)  
Old 12-04-09, 07:32
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Quote:
Originally Posted by olel View Post
we have to make sure that we are independend of the dbms used.
If you make it independent it will be slow on all DBMS (some DBMS have better optimizers than others, so it might be that one DBMS runs this statement fast, while others do not).
That's the price you pay for independency

An alternative DBMS independent solution is to maintain an aggregration table that is updated through triggers and stores the counts that you need.
In that case your application/Java code would be somewhat DBMS independent, but the triggers will not. You could also maintain the summary/aggregation table from within your application, but that would not ensure that an external access to the database would leave those tables in a consistent state.

If you really want to limit yourself to the MySQL features (which is more or less the least common denominator when it comes to SQL features and ANSI compliance) then probably your only option is to read the necessary information into memory, and do the processing (filtering, sorting, ...) there.

Most probably you'll need more than one SQL for that (which might or might not be faster depending on the DBMS).

In any case, you will be implementing some kind of DBMS abstraction layer, so you could just as well implement a layer that will generate different SQL statements for different DBMS. But you should still verify that my solution is indeed faster when using windowing functions!
Reply With Quote