Re: count(*) vs count(id) - Mailing list pgsql-general

From Cherio
Subject Re: count(*) vs count(id)
Date
Msg-id CAKHqFkKWVam7LyVM7bxDMXxsr4fZVbNuTG=rfHx07jpF5f6MMA@mail.gmail.com
Whole thread Raw
In response to Re: count(*) vs count(id)  (Hellmuth Vargas <hivs77@gmail.com>)
Responses Re: count(*) vs count(id)
List pgsql-general
I just ran a few practical tests on large (~14mil rows) tables that have multiple indexes.

SELECT COUNT(id) forces PostgreSQL to use the primary key index.
SELECT COUNT(*) allows PostgreSQL to chose an index to use and it seems to be choosing one of smaller size which leads to less IO and hence returns the result faster.


On Tue, Feb 2, 2021 at 3:45 PM Hellmuth Vargas <hivs77@gmail.com> wrote:

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: permission denied to create and drop user
Next
From: Sebastian Dressler
Date:
Subject: Re: Foreign table performance issue / PostgreSQK vs. ORACLE