The order of fields in the multicolumn index matters.

Taken in the order of fields in the index, the first inequality relation 
terminates the part of the index that is usable.

For a constraint "plate EQUALS and date BETWEEN" you need an index on 
(plate,date). Your index is only usable for "date EQUALS and plate BETWEEN"

-----Urspr?ngliche Nachricht-----
Von: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von Michele 
Pradella
Gesendet: Freitag, 19. Februar 2016 09:07
An: sqlite-users at mailinglists.sqlite.org
Betreff: [sqlite] Multiple Column index

Hi all, I have a question about using index with multiple column.
Take this test case
CREATE TABLE test (DateTime BIGINT,CarPlate VARCHAR(255)); CREATE INDEX indexA 
ON test(DateTime); CREATE INDEX indexB ON test(CarPlate); CREATE INDEX indexAB 
ON test(DateTime,CarPlate);

now if you do
[1] -> EXLPAIN QUERY PLAN SELECT * FROM test WHERE (DateTime=0) AND
(CarPlate='AA000BB')

you obtain:
0|0|0|SEARCH TABLE test USING COVERING INDEX indexAB (DateTime=? AND
CarPlate=?)
So it's good.

if you do
EXLPAIN QUERY PLAN SELECT * FROM test WHERE
(DateTime>1)AND(DateTime<100) AND (CarPlate = 'AA000BB');
0|0|0|SEARCH TABLE test USING INDEX indexB (CarPlate=?)
So is used only the indexB not the index for DateTime, and if you force it 
indexAB
0|0|0|SEARCH TABLE test USING COVERING INDEX indexAB (DateTime>? AND
DateTime<?)
so it used only for DateTime.

Do you think Is there a way to use indexAB (or using both index combining two 
select) to cover both condition (DateTime>X AND DateTime<Y  and CarPlate = 
'something' )? multicolumn index can be used only for [1] queries?
_______________________________________________
sqlite-users mailing list
sqlite-users at mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: hick at scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.


Reply via email to