Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Ev8-0007kd-Oa for pgsql-general@arkaria.postgresql.org; Wed, 03 Feb 2021 09:57:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Ev7-00038s-NF for pgsql-general@arkaria.postgresql.org; Wed, 03 Feb 2021 09:57:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Erx-0006kE-HB for pgsql-general@lists.postgresql.org; Wed, 03 Feb 2021 09:54:41 +0000 Received: from mout.gmx.net ([212.227.17.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Eru-00025e-RS for pgsql-general@lists.postgresql.org; Wed, 03 Feb 2021 09:54:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1612346076; bh=Ayl3jM4ISYzcdvI+CF7J8uNr9DJnlEMC3tWlU1gjsRw=; h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To; b=HV6Q0qrXMb7Au5i22b/8FWztDpRifblslYyLDrUu53LSaCdXBzF8aZXJh72RVszbn wSZJAGX+t2nAs9LVgfnxYYPHWHZYEqE7WJeSG7Qn40+GRwWgu3siEd0HuG/opm9Pup Qw9gDBtBhbVKcUbma0xxcjHgoqcjGJtNUbiITrnM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from hermes ([77.11.250.193]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mlf0U-1lompa0tJi-00ilA9 for ; Wed, 03 Feb 2021 10:54:36 +0100 Received: from ncq by hermes with local (Exim 4.94) (envelope-from ) id 1l7Erq-0002RJ-IU for pgsql-general@lists.postgresql.org; Wed, 03 Feb 2021 10:54:34 +0100 Date: Wed, 3 Feb 2021 10:54:34 +0100 From: Karsten Hilbert To: pgsql-general@lists.postgresql.org Subject: Re: count(*) vs count(id) Message-ID: References: <3502043.1612226098@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Ma_X_il-Followup-to: d Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net X-Pri_X_ority: 2 (High) Sender: X-Provags-ID: V03:K1:NOLCK0Rq+J8fSKWsXm923qWO8dCbDo9qti9w4rLDmF1AeYhMgd1 v4ZV8Fjvf0xGwbRY6hM/uHy+Sw67d9b8aPY0AxF6O9e26RABKD8SFMV0aWF+DsaYRyK6s7S F3pOmJ5qGffRVATI5LFzqkzTxxw+5gytCB+XayDKiM8j6C8Ft9bfxH6QRyRaFFOIot6ZozR ATKmwiP7uU/nqjG74+Pqg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:warSXlTYVfY=:wWPGGWkj7WqsZZ/IM7mbOM ju6MZbtOtNmY0UyOmo/lOPyekVNCFcAG220NnJPg7OJCdik0fhS9kbgZmHhs0SJcSMTMyFaP7 lg/6fec8YhiWxvqsFKXtAi+VVvC4cH93ynXQQlN9P/Z7aR4M6AR9HdaCdndto4To34sJ5167r DmzTRyY1B7fYABJat2mQrLctDAz+cwLiaW9EDosz+edpR0031xikE7fvJZf2n9+OzvIVoWJPl r64iacprZelyS8U0mwmvoy7KAAjsXYRBNEPq1ceaPxZN+3SfoJB2n/U3wughT6o9mRt2P0s0h OycSVp5vomwKqafgimUfmUosLDj6L8Toc78Rd4FNoGT7e6B05InQmZoFhqC5YlawKnPQK0PX8 HP6VD6U8r/k1XK/d51nR8KY0/wAvlnRzm7b5RpxH7OjDfpQA+iGX3B0f88Ll6mm5cwGKH6lps OXdDVJdOiN1A3f51XsF3xUEGh9u0ROPeWNLkz7wsHeywjSOmCdAbNmNzY5E7CFgsGqF3/ecxR VbP1JlcgIBdOs8s4c1ovSrjQEnlNNAyiQVFhUqvd0Ym/iirG0Cs9AClWTERRaJ+OC8cmeBI0p dQyNbVYlZsLxBInx9O4tNVWiO5IUVBJsv5gpEukHwIIip6nTn/sOTHSnF2nrl0xliK03igbzd 6qMr5/WcILdMUg2pt7OQUc9KDe7FPyPbsPgGJz9ZU14F34Atw/TbvgPW7K2O0Xr1vcszt/CVk xEw3JoAsv66v+9sKHrHsH+/7cBl0jEqYw7HdoimTDsPhZnVrhPPzqbniSlTeVoFxH3Ab1KF+d kttyivkEXgcDTtiAFQOndT+cE9KqSr0Dyoyt9XTmDo+MK8A/ffOXvxyME+Dc8TqLnxL6eEsuS hWRqpBrk0UmFV8D4gHIw== Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Am Wed, Feb 03, 2021 at 01:43:14AM -0500 schrieb Cherio: > 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. Would you mind throwing in a test for select count(1) ... ? Karsten =2D- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B