Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用临时B-TREE查询ORDERBY而不是索引的SQLite_Sqlite_Sorting_Indexing_Query Planner - Fatal编程技术网

使用临时B-TREE查询ORDERBY而不是索引的SQLite

使用临时B-TREE查询ORDERBY而不是索引的SQLite,sqlite,sorting,indexing,query-planner,Sqlite,Sorting,Indexing,Query Planner,我有一个非常简单的表,包括两列,message_id和server_timestamp,但是当我查看此查询的计划时: sqlite> explain query plan select message_id, server_timestamp from messages group by message_id order by server_timestamp; selectid|order|from|detail 0|0|0|SCAN TABLE messages USING COVER

我有一个非常简单的表,包括两列,message_id和server_timestamp,但是当我查看此查询的计划时:

sqlite> explain query plan select message_id, server_timestamp from messages group by message_id order by server_timestamp;
selectid|order|from|detail
0|0|0|SCAN TABLE messages USING COVERING INDEX index_messages_id_server_timestamp
0|0|0|USE TEMP B-TREE FOR ORDER BY
其中,index_messages_id_server_timestamp是上的索引(message_id,server_timestamp)


为什么此查询需要使用临时b树进行排序?

由于GROUP BY,表中的多行可能导致输出中的一行。这打破了
消息\u id
服务器\u时间戳
值之间的关系,因此无法再证明使用索引对它们进行排序是有效的。

这是一个奇妙的解释,解释了为什么索引由于对查询结果进行分组而“为空”。