Subject | does firebird always go fastest way? |
---|---|
Author | martinknappe |
Post date | 2006-05-17T09:32:01Z |
hello
i have a very rudimentary knowledge of sql as it's only one part of
the project im in right now and in order to find records in my
database i have my delphi application generate sometimes very awkward
queries and like for example
select * from (select * from (select * from (select * from (select *
from dicentries where id in (select id_dicentry from
dskrptlink_dicentries where id_dskrpt = (select id from dskrpts where
asdskrpt = 'ios'))) where id in (select id_dicentry from
dskrptlink_dicentries where id_dskrpt = (select id from dskrpts where
asdskrpt = 'iop'))) where id in (select id_dicentry from
dskrptlink_dicentries where id_dskrpt = (select id from dskrpts where
asdskrpt = 'ois'))) where id < 2067 order by id descending rows 20)
order by id ascending
(for some clarity: dskrptlink_dicentries.id_dicentry = foreign key on
dicentries.id; dskrptlink_dicentries.id_dskrpt = foreign key on
dskrpts.id => dskrptlink_dicentries is table establishing a
many-to-many link between tables dicentries and dskrpts...so this
query would ask for the last 20 of all those records in dicentries
that are linked via dskrptlink_dicentries to ALL three records in
dskrpts where dskrpts.asdskrpt = 'ois', asdskrpt = 'iop', asdskrpt =
'ios' and then order them ascendingly)
i'm pretty sure if i had better knowledge of sql there would be an
easier way to express the same thing but my question is: is it worth
it? will it make my searches faster or can i assume that firebird
always looks for the fastest way possible?
thanx,
martin
i have a very rudimentary knowledge of sql as it's only one part of
the project im in right now and in order to find records in my
database i have my delphi application generate sometimes very awkward
queries and like for example
select * from (select * from (select * from (select * from (select *
from dicentries where id in (select id_dicentry from
dskrptlink_dicentries where id_dskrpt = (select id from dskrpts where
asdskrpt = 'ios'))) where id in (select id_dicentry from
dskrptlink_dicentries where id_dskrpt = (select id from dskrpts where
asdskrpt = 'iop'))) where id in (select id_dicentry from
dskrptlink_dicentries where id_dskrpt = (select id from dskrpts where
asdskrpt = 'ois'))) where id < 2067 order by id descending rows 20)
order by id ascending
(for some clarity: dskrptlink_dicentries.id_dicentry = foreign key on
dicentries.id; dskrptlink_dicentries.id_dskrpt = foreign key on
dskrpts.id => dskrptlink_dicentries is table establishing a
many-to-many link between tables dicentries and dskrpts...so this
query would ask for the last 20 of all those records in dicentries
that are linked via dskrptlink_dicentries to ALL three records in
dskrpts where dskrpts.asdskrpt = 'ois', asdskrpt = 'iop', asdskrpt =
'ios' and then order them ascendingly)
i'm pretty sure if i had better knowledge of sql there would be an
easier way to express the same thing but my question is: is it worth
it? will it make my searches faster or can i assume that firebird
always looks for the fastest way possible?
thanx,
martin