Re: count(*) vs count(id)

From: Cherio <cherio(at)gmail(dot)com>
To: Hellmuth Vargas <hivs77(at)gmail(dot)com>
Cc: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Rob Sargent <robjsargent(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: count(*) vs count(id)
Date: 2021-02-03 06:43:14
Message-ID: CAKHqFkKWVam7LyVM7bxDMXxsr4fZVbNuTG=rfHx07jpF5f6MMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)com> wrote:

>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sebastian Dressler 2021-02-03 09:12:41 Re: Foreign table performance issue / PostgreSQK vs. ORACLE
Previous Message Adrian Klaver 2021-02-02 22:54:51 Re: permission denied to create and drop user