sqlite - Does a multi-column index work for single column selects too? -


I have found (for example) an index:

  some index order orders Do (Customer, Date);  

Does this index trigger only those questions where the customer and date are used or is it a quick question for a single column like this? Does it?

  SELECT * to order WHERE Client & gt; 33;  

I am using SQLite.


If the answer is yes, why is it possible to create more than one index from a table?


Another question: When you use both columns in a query, how fast is a composite index compared to two separate indexes?

marc_s has the correct answer to your first question. The first key in the Multi Index index can work just like a single index, but the keys after it can not be.

How fast the accumulated index relies on your data and how you make your index and query, but it is usually important that indexes essentially allows Scilit to perform a binary search on fields.

If you run the query, then use the example given to you:

  SELECT * commands where the customer & gt; 33 & amp; nbsp; Amp; Date & gt; 99]  

Siqulite must first use binary search on the entire table using all the results where the customer> 33. Then it will do a binary search only on the results that are looking for date 99 .

If you have asked the same question on the customer and the date with two different indexes, then SQLite will have to search the whole table twice for binary, first for the customer and then for the date.

The faster you can see the increase in speed, it depends on how you make your index in relation to your query. Ideally, the first field in your index and your query should be the closest to the possible matches, because that would greatly increase the speed of the work for a second, greatly reducing the amount of work.

For more information see:


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -