postgresql - Why do SQL statements take so long when "limited"? -


Consider the following pgSQL statement:

  select some fields from some_the_table where Some_field like 'text%' LIMIT 10;  

Also think, there are several million records in some documents, and some fields have B-tree indexes.

How long does it take to execute the query?) What do I mean, why do not loop this through creating a result set, and once the 10 turns out, return the results? It appears that the execution time is the same, even if you are not 'LIMIT 10' or not.

Is this true or am I forgetting something? Is there anything that I can do to return it to the first 10 results and 'screw' the rest?

UPDATE: If you drop separately, the results are returned almost immediately, although I know that many of the few Tables record are already quite specific, and certainly when I have no separate announcement When I run the query, the first 10 results are really unique. I have also terminated where (destroying it as a factor), my basic question still remains, why can not it be eliminated after 10 matches?

You have a different meaning, to find 10 different rows, all the rows It is necessary to scan which ranges from 10 << em> different some_fillds are found.

Depending on your indices, the query optimizer can decide that scanning all the rows is the best way to do this.

10 different rows can represent an infinity of 10, one million, non-specific rows.


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%? -