admin管理员组文章数量:1391974
I went through the following article on query planning in SQLite. However, I do not understand the following, stated in Sec. 1.2:
One technique for avoiding a full table scan is to do lookups by rowid (or by the equivalent INTEGER PRIMARY KEY). To lookup the price of peaches, one would query for the entry with a rowid of 4:
SELECT price FROM fruitsforsale WHERE rowid=4;
Since the information is stored in the table in rowid order, SQLite can find the correct row using a binary search.
Is that really true - is the information in the table sorted by the rowid (primary key) by default?
I went through the following article on query planning in SQLite. However, I do not understand the following, stated in Sec. 1.2:
One technique for avoiding a full table scan is to do lookups by rowid (or by the equivalent INTEGER PRIMARY KEY). To lookup the price of peaches, one would query for the entry with a rowid of 4:
SELECT price FROM fruitsforsale WHERE rowid=4;
Since the information is stored in the table in rowid order, SQLite can find the correct row using a binary search.
Is that really true - is the information in the table sorted by the rowid (primary key) by default?
Share Improve this question asked Mar 13 at 14:55 ImahnImahn 5562 gold badges7 silver badges26 bronze badges1 Answer
Reset to default 1Yes, this is true, see https://www.sqlite./lang_createtable.html#rowid:
The data for rowid tables is stored as a B-Tree structure containing one entry for each table row, using the rowid value as the key. This means that retrieving or sorting records by rowid is fast. Searching for a record with a specific rowid, or for all records with rowids within a specified range is around twice as fast as a similar search made by specifying any other PRIMARY KEY or indexed value.
本文标签: Understanding SQLite Query PlanningStack Overflow
版权声明:本文标题:Understanding SQLite Query Planning - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744694865a2620215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论