Ale*_*lex 5 php sqlite performance pdo count
Two simple queries:
SELECT * FROM some_table WHERE some_column = 1
Returns array with all the records, with columns and values. About 100K in total. Takes ~40ms to complete.
SELECT COUNT(id) FROM some_table WHERE some_column = 1
Returns just the record count value, same count as the query above. Takes 1 second!!
EXPLAIN QUERY PLAN tells me the same thing for both queries: that it's searching the table using index...
Am I missing something here? Why is getting the count slower than getting the actual records?
I really don't want to use the 1st query, because I just need the count, and fetching 100K records will surely use all available memory :(
EXPLAIN QUERY PLAN output:
query #1:
selectid order from detail
0 0 0 SEARCH TABLE atts USING INDEX idxType (type=?)
Run Code Online (Sandbox Code Playgroud)
query #2:
selectid order from detail
0 0 0 SEARCH TABLE atts USING COVERING INDEX idxType (type=?)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |