Subject | why table does a natural plan? |
---|---|
Author | emb_blaster |
Post date | 2009-02-17T18:39:01Z |
Hi all,
I understand that sometimes, an indexed search can be slowest than
natural. But I still don´t understand why this in every case.
for example:
I had TABLE_A with columns:
PK_CODE - primary key
FK_CODE1- fk
FK_CODE2- another fk
... others columns
so query:
Select * from TABLE_A;
or query:
Select PK_CODE, FK_CODE1- fk from TABLE_A;
result this Plan
PLAN (TABLE_A NATURAL)
Prepare time = 0ms
Execute time = 15ms
Avg fetch time = 0,83 ms
First Question here... a why Select doesn´t use a index? it is because
there´s no where and/or join clause, or because optimizier decided
that natural is fastest, or another thing?
.assuming PK_CODE is > 0
then Query:
Select PK_CODE, FK_CODE1- fk from TABLE_A
where PK_CODE >0;
result Plan:
PLAN (TABLE_A INDEX (RDB$PRIMARY29))
Prepare time = 0ms
Execute time = 16ms
Avg fetch time = 0,89 ms
there are second question is... why?
Can I say that it is because the indexed search in third query will
result in all records in the table (like first and second), so, it
cannot be fastest than a natural that read all records in pages?
thanks
I understand that sometimes, an indexed search can be slowest than
natural. But I still don´t understand why this in every case.
for example:
I had TABLE_A with columns:
PK_CODE - primary key
FK_CODE1- fk
FK_CODE2- another fk
... others columns
so query:
Select * from TABLE_A;
or query:
Select PK_CODE, FK_CODE1- fk from TABLE_A;
result this Plan
PLAN (TABLE_A NATURAL)
Prepare time = 0ms
Execute time = 15ms
Avg fetch time = 0,83 ms
First Question here... a why Select doesn´t use a index? it is because
there´s no where and/or join clause, or because optimizier decided
that natural is fastest, or another thing?
.assuming PK_CODE is > 0
then Query:
Select PK_CODE, FK_CODE1- fk from TABLE_A
where PK_CODE >0;
result Plan:
PLAN (TABLE_A INDEX (RDB$PRIMARY29))
Prepare time = 0ms
Execute time = 16ms
Avg fetch time = 0,89 ms
there are second question is... why?
Can I say that it is because the indexed search in third query will
result in all records in the table (like first and second), so, it
cannot be fastest than a natural that read all records in pages?
thanks