On Fri, 30 Aug 2013 16:22:04 +0000
Doug Nebeker <ad...@poweradmin.com> wrote:

> CREATE TABLE DevProps
> (
> CompID INTEGER NOT NULL,
> PropID INTEGER NOT NULL
> );
> 
> CREATE UNIQUE INDEX Ind_DevProps_CompIDPropID on DevProps (CompID,
> PropID);
...
> SELECT CompID FROM DevProps WHERE PropID=33
> 
> it looks like it will be doing a table scan.  Why is that?

Because the first column of your index is not PropID.  Your index is
ordered by CompIDl.  

PropID 33 might belong to any CompID.  SQLite has to look at every pair
to find them all.  It might as well scan the table.  

I would recomend adding ", primary key (CompID, PropID)" to the table
for semantic reasons, and creating an index with just PropID for
performance if you want to avoid the table scan.  

--jkl
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to