sql - random slowness in a simple SQLite query -
I have a code to update the SQLite database table (~ 40 million lines) (part of the code that we get regularly on a data file based on Perl using DBL on Linux, if this is the case) Frequently queries a very simple selection on the database. Some of them run under a transaction like a loop below. The selected query is usually & lt; 0.01 seconds, but a percentage of time will take 2 seconds or more Why any thoughts? This overrides "slow" runtime from time to time and therefore there is a big problem for me.
while (& lt; UPDATE_FILE & gt;)) {my ($ val4, $ val5) = get_values_from_line ($ _); My $ CMD = "SELECT col1, col2, col3 ... coln by table" "WHERE col4 = $ val4 and col5 = $ val5" "order calls by 2 days, call 3" "; execute $ cmd; On the basis, do not insert or modify the table, or do anything}
So whatever is different for each walk, where is the description of where the section I do not understand What's going on to know what's going on.
Things I've checked:
There's one The standard index is the column used in the WHERE section.
When the same code is resumed twice, it is not always the same question which is slow; such as the specific value of $ val4 and $ val5
There is no connection between the number of rows given by the selection and the speed of the query (the number of rows is never too big; <10).
What was done in the database and the query speed was finalized No clear relationship could not see, do not particularly slow queries follow essentially amendment / insertion between. (Which I think is not happening so far, because the loop is in a transaction?).
$ val4 and $ val5 can be redundant but it does not make any difference.
Slow queries are usually non-narrow if you run a special slow query to run again, it will be faster.
By using this database I am not doing anything whenever I try to update it.
Update:
Expanction QUERY revealed that SQLite was for some reason to select another reason, which is for this query Is inappropriate for When I add the query "INDEXED BY correct_index" and press the query to run using the correct index, it is always faster I will try to run the analytics after checking whether the query helps the optimizer.
Therefore, who resolves my immediate problem, but still amazes me about what is happening to me.
Update # 2:
Some questions are still randomly slow! It is only that with the new index, most questions are & lt; At 0.11 sec, sometimes with one 0.001 sec, it is satisfying for this special application, but can disturb the road.