SQL Speedups
Posted in 1996
I have two questions on SQL access and tuning I can't answer for myself, from books or from
the FAQ. Any help will be greatly appreciated...
I'm using ESQL/C and I-SE 5.0.
Q1: I need to select single data records "atomically" and stateless, and each SELECT has to
return the smallest matching record. Currently this is implemented as follows:
declare foo_cur cursor for select .... order by col1, col2;
open foo_cur;
fetcht foo_cur into $a, $b, $c;
close foo_cur;
In short: I just care for the first (smallest) record that the SELECT returns. Is there a
faster way to implement this without adding state to the program?
Q2: some of those SELECTs have huge and complicated WHERE clauses. Here's a sample:
select * from table where
(col1 = val1 and col2 = val2 and col3 = val3 and col4 = val4 and col5 >= val5) or
(col1 = val1 and col2 = val2 and col3 = val3 and col4 >= val4) or
(col1 = val1 and col2 = val2 and col3 >= val3) or
(col1 = val1 and col2 >= val2) or
(col1 >= val1)
order by col1, col2, col3, col4, col5;
The largest of those clauses does this for eight columns...
There is a composite index on col1..col5, but nevertheless the optimizer decides to sort
via a temporary table. Again: is there a better/faster way to do this?
Thank you in advance,
Gereon
--
Gereon Steffens // eMail: gereon.steffens@materna.de
Dr. Materna GmbH //
Dortmund, Germany // ``If at first you don't succeed, redefine success''