Subject | Query not using/choosing plan correctly |
---|---|
Author | Michael Horne |
Post date | 2008-12-09T08:18:36Z |
Hello,
I have a table with indexes defined as such:
CREATE TABLE ORDERSM (
OM_ID integer NOT NULL,
OM_CUS_ID VARCHAR(6) CHARACTER SET NONE COLLATE NONE,
OM_INVNUM integer,
OM_COMPANY varchar(30));
ALTER TABLE ORDERSM ADD CONSTRAINT ORDERSMBYID PRIMARY KEY (OM_ID);
CREATE UNIQUE DESC INDEX ORDERSMBYCUSTNUM3 ON ORDERSM(OM_CUS_ID,OM_ID);
Running the following query which returns only 1 record reads the entire
file, just as if the plan was natural. But the plan reported
is : "PLAN (ORDERSM ORDER ORDERSMBYCUSTNUM3)"
SELECT *
FROM ORDERSM
where om_cus_id = 2000
order by om_cus_id desc, om_id desc
This seems like a bug to me?
Also, if I change the sort to "order by om_cus_id, om_id"
the plan reported then is "PLAN SORT ((ORDERSM NATURAL))"
which also seems strange to me. With a unique index and
a single variable why not use it to select the records and
then sort. - another bug???
Using - Firebird server v 2.1.1.17910 Firebird 2.1
Newly restored from backup DB.
Yes I have tried recomputing the indexes.
I look forward to some enlightenment.
Thanks
Michael Horne
I have a table with indexes defined as such:
CREATE TABLE ORDERSM (
OM_ID integer NOT NULL,
OM_CUS_ID VARCHAR(6) CHARACTER SET NONE COLLATE NONE,
OM_INVNUM integer,
OM_COMPANY varchar(30));
ALTER TABLE ORDERSM ADD CONSTRAINT ORDERSMBYID PRIMARY KEY (OM_ID);
CREATE UNIQUE DESC INDEX ORDERSMBYCUSTNUM3 ON ORDERSM(OM_CUS_ID,OM_ID);
Running the following query which returns only 1 record reads the entire
file, just as if the plan was natural. But the plan reported
is : "PLAN (ORDERSM ORDER ORDERSMBYCUSTNUM3)"
SELECT *
FROM ORDERSM
where om_cus_id = 2000
order by om_cus_id desc, om_id desc
This seems like a bug to me?
Also, if I change the sort to "order by om_cus_id, om_id"
the plan reported then is "PLAN SORT ((ORDERSM NATURAL))"
which also seems strange to me. With a unique index and
a single variable why not use it to select the records and
then sort. - another bug???
Using - Firebird server v 2.1.1.17910 Firebird 2.1
Newly restored from backup DB.
Yes I have tried recomputing the indexes.
I look forward to some enlightenment.
Thanks
Michael Horne