Performance Comparison between count (*) and count (column) in mysql

Source: Internet
Author: User
This article will introduce in detail the difference between count (*) and count (column) in mysql. For more information, see

This article will introduce in detail the difference between count (*) and count (column) in mysql. For more information, see

Count (*) calculates the number of rows, including NULL

Count (column) calculates the number of rows that a specific column value has, excluding NULL values.

Count () also has a usage method. the usage of count (1) is the same as that of count.


About their performance

1. select count (*) FROM tablename is the optimal choice under any circumstances;
2. minimize select count (*) FROM tablename where col = 'value' queries;
3. prevent the appearance of select count (COL) FROM tablename WHERE COL2 = 'value.

If the table does not have a primary key, count (1) is faster than count.
If a primary key exists, count (primary key, joint primary key) is faster than count.
If the table has only one field, count (*) is the fastest.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.