Click here to Skip to main content
15,353,179 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Here is a simple mydql query statement: This sentence finds how many users liked a comment.
I want to clearly understand the meaning of the query.
Comments are one of the most data-rich items on the web. For a large website, the size will be huge. If there are 1 billion comments, does that query scan and verify all 1 billion data? If so, it looks very inefficient. It's like a police officer visiting a house to find a few suspects in a country with a billion people, isn't it? Rather, it seems efficient to add a count column and update the number every time the user clicks the like button. I wonder what processing is done internally when that query occurs.

What I have tried:

select * from like where comment_id="?";
Updated 9-May-22 22:10pm

1 solution

If there is an index on comment_id then no, it will not scan and "verify" all 1 billion data.

See the documentation MySQL :: MySQL 8.0 Reference Manual :: 8.8 Understanding the Query Execution Plan[^]
Maciej Los 10-May-22 7:54am
Chopin2001 10-May-22 16:24pm
I'm learning the database now. Thank you for good material

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900