当前位置:网站首页>About the difference between count (1), count (*), and count (column name)
About the difference between count (1), count (*), and count (column name)
2022-07-03 06:07:00 【vincentwc】
count(1) and count(*) There is no difference .
count( Column ) and count(*) It's actually as fast , If the index column is not empty ,count(*) Available to index , Just as fast at this time .
summary : But is the conclusion really like this . It's not . In fact, in the database count(*) and count( Column ) It is simply not equivalent ,count(*) It is aimed at the whole table , and count( Column ) It is for a certain column , If this column value is empty ,count( Column ) I won't count this line . So there is no comparability between the two , Performance comparison should first consider writing equivalence , These two statements are not equivalent at all . It will lose the significance of comparison !!!
If the query table has only one field , be COUNT(*) The fastest ;
If the query table has no primary key , be COUNT(1) Than COUNT(*) fast ;
If the query table has a primary key , be COUNT( Primary key ) Than COUNT(*) fast ,count( Primary key column )》count(1)》count(*);
COUNT(*) Return the total number of rows , contain NULL value ; COUNT( Name ) Return the total number of rows , Not included NULL value ; DISTINCT COUNT(*) Return the total number of rows , Remove duplicates without NULL value
边栏推荐
- JS implements the problem of closing the current child window and refreshing the parent window
- Kubernetes notes (10) kubernetes Monitoring & debugging
- 项目总结--01(接口的增删改查;多线程的使用)
- 1. 兩數之和
- 88. Merge two ordered arrays
- [teacher Zhao Yuqiang] MySQL flashback
- Simple solution of small up main lottery in station B
- 技术管理进阶——你了解成长的全貌吗?
- MySQL帶二進制的庫錶導出導入
- 深度学习,从一维特性输入到多维特征输入引发的思考
猜你喜欢
【系统设计】邻近服务
Life is a process of continuous learning
[teacher Zhao Yuqiang] MySQL flashback
[teacher Zhao Yuqiang] Alibaba cloud big data ACP certified Alibaba big data product system
Detailed explanation of contextclassloader
Core principles and source code analysis of disruptor
卷积神经网络CNN中的卷积操作详解
Phpstudy setting items can be accessed by other computers on the LAN
Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
Analysis of Clickhouse mergetree principle
随机推荐
When PHP uses env to obtain file parameters, it gets strings
[teacher Zhao Yuqiang] use the catalog database of Oracle
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
[written examination question analysis] | | get [sizeof and strlen] [pointer and array] graphic explanation + code analysis
Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
Alibaba cloud Alipay sandbox payment
Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)
70 shell script interview questions and answers
Simple solution of small up main lottery in station B
[teacher Zhao Yuqiang] kubernetes' probe
The most responsible command line beautification tutorial
Oauth2.0 - Introduction and use and explanation of authorization code mode
项目总结--04
Redhat7 system root user password cracking
Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
[minesweeping of two-dimensional array application] | [simple version] [detailed steps + code]
Code generator - single table query crud - generator
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
C 语言文件操作函数大全 (超详细)