不选择任何表列的查询 - 我理解正确吗?
我刚刚读了这篇文章:
http://use -the-index-luke.com/sql/clustering/index-only-scan-covering-index
底部是这样的语句:
不选择任何表列的查询通常作为仅索引扫描执行。
你能想出一个有意义的例子吗?
问题是,没有评论部分,所以我只是想验证一下,这是一个例子,对吗?
SELECT 1 FROM `table_name` WHERE `indexed_column` = ?
这是为了检查指定的行是否存在。
那么问题是:
- 它还有更多实际用途吗?
作为旁注,我在某处读到,如果封装在
EXISTS
中,上述查询可能会性能更高,我不知道如何检查它是否正确:SELECT EXISTS(SELECT 1 FROM `table_name` WHERE `indexed_column` = ? LIMIT 1)
是吗?
I just read this article:
http://use-the-index-luke.com/sql/clustering/index-only-scan-covering-index
And at the bottom is this statement:
Queries that do not select any table columns are often executed as index-only scan.
Can you think of a meaningful example?
Problem is, there is no comments section, so I just want to verify, this is one example, correct?
SELECT 1 FROM `table_name` WHERE `indexed_column` = ?
This is to check whether a specified row exists.
So the questions:
- Are there any more practical uses for that?
As a side note, I read somewhere that the above query might be more performant if encapsulated in
EXISTS
, I'm not sure how to check if it's true:SELECT EXISTS(SELECT 1 FROM `table_name` WHERE `indexed_column` = ? LIMIT 1)
Is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,规范的示例可能是
select count(*) from mytable
来获取行数。这不会从表中选择任何数据,并且很可能由主键索引(如果可用)来满足。
Well, possibly the canonical example would be
select count(*) from mytable
to get a row count.That selects no data from the table and would most likely be satisfied by the primary key index, if available.