Queries that do not select any table columns - do I understand this correctly?
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?
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.
精彩评论