Usage relations and differences of count (1), count (*) and count (a field) in MySQL

usage relations differences count count

One . From the execution results

count(*): All rows are counted , Include NULL That's ok
count(1): All rows are counted , Include NULL That's ok
count(column): Yes column Central African Null Make statistics

Two . In terms of execution efficiency

There will be some differences between them according to different situations ,MySQL Would be right count(*) Make optimization .

(1) If the column is the primary key ,count( Name ) Efficiency is better than count(1)
(2) If the column is not a primary key ,count(1) Efficiency is better than count( Name )
(3) If there is a primary key in the table ,count( Primary key column name ) The efficiency is the best
(4) If there is only one column in the table , be count(*) The efficiency is the best
(5) If the table has multiple columns , And there is no primary key , be count(1) Efficiency is better than count(*)

3、 ... and . count(1) principle

count(1), In fact, it is to calculate the number of qualified lines .1 It doesn't mean the first field , It's a fixed value .

In fact, it can be thought that there is such a field in the table : This field is a fixed value 1,count(1), That's how many in all 1.

Four . count(*) principle

count(*), During execution, the asterisk will be translated into the specific name of the field , The effect is the same .

But there is one more translation action , Slightly less efficient than the fixed value approach .

本文为[Old fellow iron has dried up the code.]所创,转载请带上原文链接,感谢

  1. Java虚拟机|JVM【适合初学者入门】
  2. [Azure Cloud Service] Azure Cloud Service ajoute des champs personnalisés pour le rôle Web (hôte IIS) (ajoute le champ user agent dans l'en - tête de demande http au Journal de sortie IIS)
  3. Spring Cloud 2021.0.0-M2 發布
  4. Java虛擬機|JVM【適合初學者入門】
  5. Spring Cloud 2021.0.0-m2 Release
  6. Machine virtuelle Java | JVM [convient aux débutants]
  7. 10412 Xiaopeng cars announced sales results in September
  8. Apprendre le mécanisme des événements Java
  9. Java script RPC (07) - timeout timeout Processing from zero
  10. Introduction à la page Web de rabbitmq (3)
  11. MySQL read - Write Separation Cluster Construction and Integration with mycat
  12. Analyse du principe du conteneur du CIO printanier
  13. Java面向对象基础
  14. Java communique avec les capteurs industriels via socket et DTu, RTU
  15. Xiaopeng automobile delivered 10412 units in September, with a monthly sales volume of more than 10000 for the first time
  16. Java Object Oriented Foundation
  17. Introduction au développement Android PDF, un tour pour vous apprendre à comprendre netty
  18. Hadoop Foundation - 01 - concepts de base
  19. Hadoop Foundation - 02 - Basic Structure
  20. Hadoop Foundation - 03 - hdfs (Hadoop Distributed File System) Basic Concepts
  21. Hadoop Foundation - 04 - hdfs API Programming
  22. Hadoop Foundation - 05 - hdfs Project (word Frequency Statistics)
  23. Hadoop Foundation - 06 - hdfs Data Read and write
  24. The "monthly test" report card of the new car built under the lack of core: Xiaopeng and Weilai took the lead in "breaking 10000", and the ideal plummeted by 25%
  25. Introduction to making arch linux software package
  26. Hard core observation 407 HTTPS everywhere browser extension is about to retire
  27. How to use busybox on Linux
  28. In 2021, the talent incentive plan of Linux foundation open source software School Park was officially launched
  29. It's not windows or Linux. Shrink is the "God operating system"
  30. Install anydesk on Ubuntu Linux
  31. 2021, can we recommend using Linux to play games?
  32. not exist:org.springframework.kafka.listener.AbstractMessageListenerContaingetContainerProperties()
  33. Are you sure HTTPS is asymmetric encryption for content encryption? See the answers and reasons
  34. MySQL online slow log query
  35. Java JDK server installation
  36. 手把手教你使用Java开发在线生成pdf文档
  37. Questions d'entrevue dans la base de données MySQL (dernière version 2021)
  38. Java零基础小白入门必做题汇总(建议收藏)第一篇
  39. Day15 Java Foundation
  40. Day16 Java Foundation
  41. Day17 Java Foundation
  42. Day18 Java Foundation
  43. Linux installe JDK 1.8 et configure les variables d'environnement
  44. Tutoriel d'utilisation Maven super détaillé
  45. Spring boot reads project parameter configuration
  46. Docker installing rocketmq
  47. Java Zero Basic small white Beginner must make a summary of issues (recommended Collection) Chapitre 1
  48. Manuel pour vous apprendre à utiliser le développement Java pour générer des documents PDF en ligne
  49. 40 + comment les femmes s'habillent - elles pour montrer leur jeunesse?Un manteau et une jupe vous donnent un look haut de gamme tout au long de l'automne et de l'hiver
  50. Tutoriel d'installation Ubuntu 16.04 / Hadoop 3.1.3Configuration autonome / pseudo - distribuée
  51. L'apprentissage le plus détaillé de springboot à l'échelle du réseau - day01
  52. L'apprentissage le plus détaillé de springboot sur le Web - day02
  53. L'apprentissage le plus détaillé de springboot sur le Web - day03
  54. L'apprentissage le plus détaillé de springboot sur le Web - day04
  55. Tutoriel d'utilisation Maven super détaillé
  56. L'apprentissage le plus détaillé de springboot sur le Web - day05
  57. L'apprentissage le plus détaillé de springboot sur le Web - day06
  58. L'apprentissage le plus détaillé de springboot sur le Web - day07
  59. Introduction to JavaScript - write a photo album for your girlfriend
  60. [Hadoop 3. X] HDFS storage type and storage strategy (V) overview