Comments on: COUNT(*) vs COUNT(col) in MySQL https://www.percona.com/blog/count-vs-countcol-in-mysql/ Tue, 14 Feb 2023 12:05:51 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Denis Subbota https://www.percona.com/blog/count-vs-countcol-in-mysql/#comment-10973919 Fri, 10 Feb 2023 10:17:19 +0000 https://www.percona.com/blog/?p=84510#comment-10973919 Hello, Zonglei Dong. Good catch, thank you.

]]>
By: Zonglei Dong https://www.percona.com/blog/count-vs-countcol-in-mysql/#comment-10973917 Wed, 08 Feb 2023 14:22:55 +0000 https://www.percona.com/blog/?p=84510#comment-10973917

It is worth to note in this case, MySQL Optimizer does not do a good job of optimizing the query. One could notice (val_with_nulls) column is not null, so COUNT(val_with_nulls) is the same as COUNT(*), and so the query could be run as an index-covered query. It does not, and both queries have to perform row reads in this case.

I think it should be “COUNT(val_no_null)“, not COUNT(val_with_nulls)

]]>