当前位置:网站首页>MySQL -count: the difference between count (1), count (*), and count (column name)
MySQL -count: the difference between count (1), count (*), and count (column name)
2022-07-26 21:20:00 【The clouds are idle】
Come to the conclusion first
On the effect of execution :
- count(*) It includes all the columns , Equivalent to the number of lines , When it comes to statistical results , Will not be ignored as NULL Value .
- count(1) use 1 Represents the line of code , When it comes to statistical results , Will not be ignored as NULL Value .
- count( Name ) Only include the column of the list , When it comes to statistical results , Will ignore null column values ( Null here does not mean an empty string or 0, It means null) Count of , That is, the value of a field is NULL when , No statistics .
In terms of execution efficiency :
- The column name is primary key ,count( Name ) than count(1) fast
- Column name is not primary key ,count(1) than count( Name ) fast
- If the table has multiple columns and no primary key , be count(1) Is superior to the execution efficiency count(*)
- If there is a primary key , be select count( Primary key ) The efficiency of execution is optimal
- If the table has only one field , be select count(*) The optimal .
make a concrete analysis
1. count(1) and count(*)
In terms of execution plan ,count(1) and count(*) The effect is the same .
When the table has more data , After analyzing the table , Use count(1) It's better than using count(*) It takes a lot of time !
When the amount of data is 1W Within ,count(1) than count(*) We need less time , But not much .
If count(1) When it's a clustered index , That must be count(1) fast , But the difference is very small .
because count(), It will automatically optimize the field assigned to . So there's no need to count(1), Use count(),sql It will help you optimize
therefore : When there is a clustered index count(1) and count(*) Basically no difference !
2. count(1) and count( Field )
The main difference between the two is :
count(1) Will count all the records in the table , The containing field is null The record of .
count( Field ) Count the number of times the field appears in the table , The ignored field is null The situation of . That is to say, do not count the fields as null The record of .
边栏推荐
- TableWidget
- 【Oracle实训】-部署号称零停机迁移的OGG
- 基于Hough变换的直线检测(Matlab)
- [MySQL series] - how much do you know about the index
- 【MySQL系列】-索引知多少
- Go+mysql+redis+vue3 simple chat room, bullet 5: synchronize messages to MySQL using message queues and scheduled tasks
- 如何借助自动化工具落地DevOps|含低代码与DevOps应用实践
- 测试用例千万不能随便,记录由一个测试用例异常引起的思考
- Redis hash和string的区别
- [virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure
猜你喜欢

拦截器、、

DeepFake捏脸真假难辨,汤姆·克鲁斯比本人还像本人!

ECCV 2022 | 同时完成四项跟踪任务!Unicorn: 迈向目标跟踪的大统一

Redis hash和string的区别

09_ UE4 advanced_ Enter the next level and reserve the blood volume

Line detection based on Hough transform (matlab)

How to block the legendary GEE engine version? Close player account tutorial through script + engine

GOM and GEE lander list file encryption tutorial

【HCIE安全】双机热备-主备备份

Niuke brush questions - MySQL series
随机推荐
2022-7-26 the seventh group of abstractions and interfaces
播报语音 h5 SpeechSynthesisUtterance
拦截器、、
Mysql -count :count(1)、count(*)、count(列名)的区别
idea中debug时如何进入指定的用户方法体中?
How to enter the specified user method body when debugging in idea?
Redis interview questions
JDBC的连接
Modify excel default code
Transaction rollback and record exception information at the same time
详解西部数据SMR叠瓦式硬盘的190二级编译器(译码表)模块
Leetcode linked list class
Devsecops, speed and security
【HarmonyOS议题资料下载】HDD杭州站·线下沙龙专注应用创新 展现鸿蒙生态魅力
Web3.0 时代,基于P2PDB实现一款Dapp的技术理论
GOM登录器配置免费版生成图文教程
LiveDatade的基本使用
GOM跟GEE登陆器列表文件加密教程
【问题篇】浏览器get请求带token
CONDA reports an error: json.decoder.jsondecodeerror: