ORDER BY on index can cause suboptimal index choices
----------------------------------------------------

                 Key: CORE-5845
                 URL: http://tracker.firebirdsql.org/browse/CORE-5845
             Project: Firebird Core
          Issue Type: Bug
          Components: Engine
    Affects Versions: 3.0.3, 3.0.4
            Reporter: Karol Bieniaszewski


CREATE TABLE TEST
(
ID1 INTEGER,
ID2 INTEGER,
ID3 INTEGER,
X NUMERIC(18,2),
CONSTRAINT PK_TEST PRIMARY KEY(ID1, ID2, ID3)
);


CREATE INDEX IXA_TEST__X ON TEST(X);
CREATE INDEX IXA_TEST__ID1_X ON TEST(ID1, X);


--------------------------------------------------------------------------------

SELECT * FROM TEST T WHERE T.ID1=1 AND T.X>0 

PLAN (T INDEX (IXA_TEST__ID1_X))

index IXA_TEST__ID1_X is used
--------------------------------------------------------------------------------


SELECT * FROM TEST T WHERE T.ID1=1 AND T.X>0  ORDER BY T.ID1, T.ID2, T.ID3

PLAN (T ORDER PK_TEST INDEX (IXA_TEST__X))

index IXA_TEST__X - suboptimal
--------------------------------------------------------------------------------

as you can see adding ORDER BY which consume some index (PK_TEST) 
cause suboptimal choice of index (IXA_TEST__X)

--------------------------------------------------------------------------------

if query is changed to order by not by index
SELECT * FROM TEST T WHERE T.ID1=1 AND T.X>0 ORDER BY T.ID1+0, T.ID2, T.ID3

PLAN SORT (T INDEX (IXA_TEST__ID1_X))


It can be releated to CORE-5795 but this can be different case


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://tracker.firebirdsql.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to