Databases 5 min read

Is MySQL count(1) Really Faster Than count(*)?

This article examines whether MySQL's count(1) is faster than count(*), explains how InnoDB processes both expressions identically, compares them with count(column), and offers practical advice on avoiding costly full‑table counts.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Is MySQL count(1) Really Faster Than count(*)?

Many developers assume that count(1) is faster than count(*) in MySQL; this article investigates that belief and explains the real performance characteristics.

In the MyISAM engine the total row count is stored, so count(*) can return the value directly and is very fast. Since MySQL 5.5 the default engine switched to InnoDB, which uses MVCC and cannot cache a static row count; each transaction must compute the count, making count(*) and count(1) behave the same way.

The official MySQL documentation states that InnoDB handles SELECT COUNT(*) and SELECT COUNT(1) in exactly the same manner, so there is no performance difference between them.

According to the MySQL reference, COUNT(expr) returns the number of non‑NULL values of expr in the result set, while COUNT(*) counts all rows regardless of NULL values. Because the constant 1 in COUNT(1) is always true, it effectively counts every row just like COUNT(*) .

When counting a specific column, MySQL must read each row, check whether the column value is NULL, and then increment the counter, which adds extra I/O. Consequently, the performance ranking is: count(*) = count(1) > count(primary key) > count(column) .

Given that full‑table counts can be expensive, it is advisable to avoid them in design whenever possible. Common strategies include caching expected counts in Redis or maintaining a separate MySQL table that tracks row counts, while also handling consistency concerns.

In summary, count(*) and count(1) are essentially identical in InnoDB, and developers should focus on caching or alternative counting methods rather than seeking a nonexistent speed advantage.

PerformanceDatabaseInnoDBMySQLcount()
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.