Subject | Query optimization novice question |
---|---|
Author | Balanyi Zsolt |
Post date | 2007-03-20T16:16:13Z |
Hi!
I have the following two queries (FB SS 1.5.2 Win XP):
1)
SELECT TERMEKKOD, TERMEKNEV, SUM(MENNYISEG) AS MENNYISEG,
SUM(TELJESITETTMENNYISEG) AS TELJESITETTMENNYISEG, EGYSEGAR,
SUM(NETTOERTEK) AS NETTOERTEK, SUM(AFAERTEK) AS AFAERTEK,
SUM(BRUTTOERTEK) AS BRUTTOERTEK
FROM MEGRENDELESTETELEK WHERE (TIPUS=:T1 OR TIPUS=:T2)
AND MEGRENDELESID < 5000
GROUP BY TERMEKKOD, TERMEKNEV, EGYSEGAR
2)
SELECT TERMEKKOD, TERMEKNEV, SUM(MENNYISEG) AS MENNYISEG,
SUM(TELJESITETTMENNYISEG) AS TELJESITETTMENNYISEG, EGYSEGAR,
SUM(NETTOERTEK) AS NETTOERTEK, SUM(AFAERTEK) AS AFAERTEK,
SUM(BRUTTOERTEK) AS BRUTTOERTEK
FROM MEGRENDELESTETELEK WHERE (TIPUS=:T1 OR TIPUS=:T2)
AND MEGRENDELESID IN (SELECT MEGRENDELESID FROM MEGRENDELESEK WHERE
MEGRENDELESID < 5000)
GROUP BY TERMEKKOD, TERMEKNEV, EGYSEGAR
They differ only in the 5. line, but the line filters the same rows
(where MEGRENDELESID < 5000)
The funny thing is, that if I use query 1) then I get the plan:
PLAN SORT ((MEGRENDELESTETELEK INDEX (FK_MEGRENDELESTETELEK)))
where FK_MEGRENDELESTETELEK is a foreign key to table MEGRENDELESEK on
the PK field MEGRENDELESID
Execution time is around 1,8 sec
If I use query 2), the plan is:
PLAN (MEGRENDELESEK INDEX (PK_MEGRENDELESEK))
PLAN SORT ((MEGRENDELESTETELEK NATURAL))
where PK_MEGRENDELESEK is the primary key on the field MEGRENDELESID
Execution time is around 3,5 sec
Can anyone explain to me how to make plan of the query 2) to end like
plan of qurey 1)?
Best regards, Zsolt Balanyi
I have the following two queries (FB SS 1.5.2 Win XP):
1)
SELECT TERMEKKOD, TERMEKNEV, SUM(MENNYISEG) AS MENNYISEG,
SUM(TELJESITETTMENNYISEG) AS TELJESITETTMENNYISEG, EGYSEGAR,
SUM(NETTOERTEK) AS NETTOERTEK, SUM(AFAERTEK) AS AFAERTEK,
SUM(BRUTTOERTEK) AS BRUTTOERTEK
FROM MEGRENDELESTETELEK WHERE (TIPUS=:T1 OR TIPUS=:T2)
AND MEGRENDELESID < 5000
GROUP BY TERMEKKOD, TERMEKNEV, EGYSEGAR
2)
SELECT TERMEKKOD, TERMEKNEV, SUM(MENNYISEG) AS MENNYISEG,
SUM(TELJESITETTMENNYISEG) AS TELJESITETTMENNYISEG, EGYSEGAR,
SUM(NETTOERTEK) AS NETTOERTEK, SUM(AFAERTEK) AS AFAERTEK,
SUM(BRUTTOERTEK) AS BRUTTOERTEK
FROM MEGRENDELESTETELEK WHERE (TIPUS=:T1 OR TIPUS=:T2)
AND MEGRENDELESID IN (SELECT MEGRENDELESID FROM MEGRENDELESEK WHERE
MEGRENDELESID < 5000)
GROUP BY TERMEKKOD, TERMEKNEV, EGYSEGAR
They differ only in the 5. line, but the line filters the same rows
(where MEGRENDELESID < 5000)
The funny thing is, that if I use query 1) then I get the plan:
PLAN SORT ((MEGRENDELESTETELEK INDEX (FK_MEGRENDELESTETELEK)))
where FK_MEGRENDELESTETELEK is a foreign key to table MEGRENDELESEK on
the PK field MEGRENDELESID
Execution time is around 1,8 sec
If I use query 2), the plan is:
PLAN (MEGRENDELESEK INDEX (PK_MEGRENDELESEK))
PLAN SORT ((MEGRENDELESTETELEK NATURAL))
where PK_MEGRENDELESEK is the primary key on the field MEGRENDELESID
Execution time is around 3,5 sec
Can anyone explain to me how to make plan of the query 2) to end like
plan of qurey 1)?
Best regards, Zsolt Balanyi