Subject | RE: [firebird-support] Index question |
---|---|
Author | Thomas Steinmaurer |
Post date | 2003-11-26T22:23:57Z |
Christian,
result set out of a huge table, specified by a WHERE
clause. Using indices when the engine has to visit all
records in a table (for example if you want all records
back, cause you haven't specified a WHERE clause) is
usually a bad thing, because a FULL TABLE scan is
"cheaper" without using an index.
Thomas
> please take a look at the following table:Indices are your best friend if you want to get a small
>
> CREATE TABLE T_KUNDEN (
> ID INTEGER NOT NULL,
> KID INTEGER NOT NULL,
> NACHNAME VARCHAR(80) COLLATE DE_DE,
> FIRMA VARCHAR(80) COLLATE DE_DE,
> [...]
> );
>
> ... and the following indices:
>
> CREATE INDEX T_KUNDEN_FIRMA ON T_KUNDEN (FIRMA);
> CREATE INDEX T_KUNDEN_NACHNAME ON T_KUNDEN (NACHNAME);
>
> ... and the following select statement:
>
> SELECT * FROM T_KUNDEN
> ORDER BY FIRMA ASC, NACHNAME ASC
>
> Why does Firebird ignore the indices and uses the following plan?
>
> Plan
> PLAN SORT ((T_KUNDEN NATURAL))
> Adapted Plan
> PLAN SORT ((T_KUNDEN NATURAL))
result set out of a huge table, specified by a WHERE
clause. Using indices when the engine has to visit all
records in a table (for example if you want all records
back, cause you haven't specified a WHERE clause) is
usually a bad thing, because a FULL TABLE scan is
"cheaper" without using an index.
Thomas