Subject | Simpel query question - speed |
---|---|
Author | mivi71dk |
Post date | 2009-11-26T08:41:49Z |
Hi
I have a table defined as:
CREATE TABLE POINT_KVIT
(
ID INTEGER NOT NULL,
BONNR INTEGER DEFAULT 0,
TEKST VARCHAR( 100) DEFAULT '' COLLATE NONE,
CONSTRAINT FK_POINT_KVIT PRIMARY KEY (ID)
);
CREATE ASC INDEX POINT_KVIT_IDX1 ON POINT_KVIT (BONNR);
This tables contains some 24 millions records.
The selectivity to index POINT_KVIT_IDX1 is 0,00000142520 or less
If I do a select like this:
Select
ID, BonNr, Tekst
from Point_Kvit
Where BonNr = 2236136
It fetches 31 records in hardly no time (0.062 secs) with this plan:
PLAN (POINT_KVIT INDEX (POINT_KVIT_IDX1))
If I on the other hand do a select like this:
Select
ID, BonNr, Tekst
from Point_Kvit
Where BonNr = 2236136
Order by ID
It fetches the same 31 records, but i now uses 2 seconds to do the same with this plan:
PLAN (POINT_KVIT ORDER RDB$PRIMARY240 INDEX (POINT_KVIT_IDX1))
My question is, why is there such a big difference in the to above Selects?
I need to have them ordered, so I get them in the same order they where inserted.
I have for now solved it by doing this select, which is as fast as the first one:
Select
ID, BonNr, Tekst,
BonNr || ID as P
from Point_Kvit
Where BonNr = 2236136
order by 4
Which also have the same PLAN as the first one.
Regards
Michael
I have a table defined as:
CREATE TABLE POINT_KVIT
(
ID INTEGER NOT NULL,
BONNR INTEGER DEFAULT 0,
TEKST VARCHAR( 100) DEFAULT '' COLLATE NONE,
CONSTRAINT FK_POINT_KVIT PRIMARY KEY (ID)
);
CREATE ASC INDEX POINT_KVIT_IDX1 ON POINT_KVIT (BONNR);
This tables contains some 24 millions records.
The selectivity to index POINT_KVIT_IDX1 is 0,00000142520 or less
If I do a select like this:
Select
ID, BonNr, Tekst
from Point_Kvit
Where BonNr = 2236136
It fetches 31 records in hardly no time (0.062 secs) with this plan:
PLAN (POINT_KVIT INDEX (POINT_KVIT_IDX1))
If I on the other hand do a select like this:
Select
ID, BonNr, Tekst
from Point_Kvit
Where BonNr = 2236136
Order by ID
It fetches the same 31 records, but i now uses 2 seconds to do the same with this plan:
PLAN (POINT_KVIT ORDER RDB$PRIMARY240 INDEX (POINT_KVIT_IDX1))
My question is, why is there such a big difference in the to above Selects?
I need to have them ordered, so I get them in the same order they where inserted.
I have for now solved it by doing this select, which is as fast as the first one:
Select
ID, BonNr, Tekst,
BonNr || ID as P
from Point_Kvit
Where BonNr = 2236136
order by 4
Which also have the same PLAN as the first one.
Regards
Michael