Subject | Re: SQL Query performance |
---|---|
Author | Svein Erling Tysvær |
Post date | 2005-07-11T07:46:06Z |
--- In firebird-support@yahoogroups.com, Robert martin wrote:
First, try to eliminate parts of your query that may include indexed
fields that you do not want to be part of any plan:
SELECT a,b,c
FROM Table1 t1
JOIN Table2 t2 t2 ON t2.pk = t1.FK
WHERE t1.PK = 4
AND (2=0 or (<the rest of the where clause))
Secondly, prevent the query from using two indexes on t1:
SELECT a,b,c
FROM Table1 t1
JOIN Table2 t2 t2 ON t2.pk = t1.FK+0
WHERE t1.PK = 4
...
If neither of these two suggestions help (even when taken together),
then I'm stumped.
HTH,
Set
> Hi AllOK Rob, I want you to try two things to tame your query!
>
> I have a Query that is basically
>
> SELECT a,b,c
> FROM Table1 t1
> JOIN Table2 t2 t2 ON t2.pk = t1.FK
> WHERE t1.PK = 4
> AND t2.CancelFlag <> 'T'
>
> The final and clause (t2.CancelFlag <> 'T' ) is really slowing the
> query down. It takes 1.3s with and is near instantaneous without.
> The CancelFlag field is a Char(1) field that is NOT indexed (because
> it would have low selectivity). Is there anything I can do to speed
> up this query?
>
> In the data I am testing the table sizes are...
> t1 = 3100
> t2 = 72000
First, try to eliminate parts of your query that may include indexed
fields that you do not want to be part of any plan:
SELECT a,b,c
FROM Table1 t1
JOIN Table2 t2 t2 ON t2.pk = t1.FK
WHERE t1.PK = 4
AND (2=0 or (<the rest of the where clause))
Secondly, prevent the query from using two indexes on t1:
SELECT a,b,c
FROM Table1 t1
JOIN Table2 t2 t2 ON t2.pk = t1.FK+0
WHERE t1.PK = 4
...
If neither of these two suggestions help (even when taken together),
then I'm stumped.
HTH,
Set