In SQL, the count aggregate command is used to calculate the total number of table records. This command gives us the feeling that it is faster than the general query. However, when your data table has many records, for example, if there are millions or tens of millions of records, it is not so fast for count. We need to master some skills to optimize this count. Some people say: selectcount (1)
In SQL, the count aggregate command is used to calculate the total number of table records. This command gives us the feeling that it is faster than the general query. However, when your data table has many records, for example, if there are millions or tens of millions of records, it is not so fast for count. We need to master some skills to optimize this count. Some people say: select count (1)
In SQL, the count aggregate command is used to calculate the total number of table records. This command gives us the feeling that it is faster than the general query. However, when your data table has many records, for example, if there are millions or tens of millions of records, it is not so fast for count. We need to master some skills to optimize this count.
Some people say:
Select count (1) from table
Select count (primarykey) from table
It's faster. You must never use it.
Select count (*) from table
But what I want to say is that count (*) is faster. Why? What does count (*) mean? In fact, the true meaning of this field is to find an index field with the smallest space occupied, and then count it. Do not think it is "Big" as soon as you see *. In the count command, it refers to "any".
For a large table, if your field has a bit type, such as a gender field, which indicates a field with a true/false relationship, we need to add an index for it, our count speed is dozens of times faster, really, haha
First, add the index IsSync to the bit type field to add the clustered index.
If the data table is too large, run