❝
If there is any data in a table, use limit 1 or count. If there is any data in a table, use limit 1 or count. If there is any data in a table, use limit 1 or count. So my friend asked me earlier if I could give an actual assessment ah, arrangement.
❞
This article focuses only on the following two SQL tests.
Two ways to write SQL
count()
SELECT count(*) FROM table
Copy the code
limit 1
SELECT 1 FROM table LIMIT 1
Copy the code
Evaluate the premise
Engine: INNODB
Table structure
Take a look at the following table structure, not too complex Settings.
explain
Smart everyone will first explain, then show you.
limit 1
count
Yes, as you can see, there is no difference. Let’s start with the actual numbers.
assessment
First test
So let’s insert 1000 pieces of data.
count
limit 1
Second test
count
limit 1
After the second round of testing it feels like the time is up. Continue to test.
Third test
Let’s go on to the third round and insert 100,000.
This execution is a little bit stuck, let’s wait a little while and have a cup of tea (6 minutes).
OK, the data is in place. Let’s test it again.
count
limit 1
Limit 1 has the upper hand in this round.
Fourth round of evaluation
Ok, let’s go ahead and do the fourth test and insert another 100,000, after all, 6 minutes at a time.
count
limit 1
Now it’s more and more limit 1. The test continues.
Round 5 evaluation
Continue to insert 100,000 pieces of data.
count
limit 1
Round 6 test
Insert another 200,000 pieces of data.
count
limit 1
We’re here. We can’t be lazy. Keep testing.
Round 7 test
Insert another 200,000 pieces of data.
count
limit 1
It’s getting better. Go ahead, then.
Round 8 test
Insert another 200,000 pieces of data.
count
limit 1
Round 9
Last round, insert another 100,000.
count
limit 1
The last
In fact, the results have been very obvious, xiaobian then summarized all the evaluation results to the table, irrefutable evidence.
conclusion
Good theory is of course important, theory can be learned from books, experience may need to be realized by ourselves to obtain, I hope this article can bring you some help.
This article is formatted using MDNICE