sagarswathi / h2database

Automatically exported from code.google.com/p/h2database
0 stars 1 forks source link

Optimiser not using clustered index #409

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, 

 I would expect the following to use the index PUBLIC.ID_DATA however it only uses the default primary key index PUBLIC.PRIMARY_KEY_27

create table test( 
ID BIGINT PRIMARY KEY AUTO_INCREMENT,
DATA VARCHAR(100)
);

CREATE INDEX ID_DATA ON TEST(ID,DATA);

EXPLAIN PLAN SELECT * FROM TEST WHERE (id>3 AND data = 'SOMETHING')

*****

PLAN 
SELECT
    TEST.ID,
    TEST.DATA
FROM PUBLIC.TEST
    /* PUBLIC.PRIMARY_KEY_27: ID > 3 */
WHERE (ID > 3)
    AND (DATA = 'SOMETHING')

Is this something I have done wrong or not supported?
The optimiser will use clustered indexes when NOT including the primary key.

I am using the h2-1.3.162.jar

This is very important to fix/workaround.

I am toying with the idea of making another column which is the same as ID and 
making clustered indexes on it, then querying on it...

Thanks

From, 

Phill

Original issue reported on code.google.com by phillip....@pbtgroup.com.au on 20 Jul 2012 at 4:27

GoogleCodeExporter commented 8 years ago
Duplicate of #389

Original comment by noelgrandin on 8 Feb 2013 at 2:10