On 28 May 2010, at 3:57pm, Michael Ash wrote:

> Per suggestions, I indexed year and media on the big table.  So I now
> have separate indexes for the key variable (releasenumber) and for
> year and for media.    Would  it make more sense to have a single
> index for all three, thus:
> 
> CREATE UNIQUE INDEX r ON release_cl (year,media,releasenumber);

Correct.  Each SELECT command uses zero or one index.  It's pointless to create 
individual indexes for each column in your table.  Look at the columns, ORDER 
BY and WHERE of your SELECT query and make up one index which is ideal for that 
query.  For the ideal index in SQLite, you make the index up of

first, the columns mentioned in the WHERE clause
then, the columns mentioned in the ORDER BY clause
finally any other columns you want retrieved.

For each purpose you have to choose your preferred cutoff: it's usually not 
worth doing the last section of the above, and sometimes not even worth doing 
the ORDER BY section.  The more indexes, and the longer they are, the longer 
each WRITE operation takes for that table.  You could end up with a table which 
might be fast to search but need a very long time for each INSERT.  Also, 
increasing the length of each index will increase the database filesize, and 
therefore cause operations which change the database file to take longer.

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

Reply via email to