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 1mzUK0-0005CZ-GL for pgsql-performance@arkaria.postgresql.org; Tue, 21 Dec 2021 01:52:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mzUJz-0006pi-Dd for pgsql-performance@arkaria.postgresql.org; Tue, 21 Dec 2021 01:52:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzUJz-0006pZ-4c for pgsql-performance@lists.postgresql.org; Tue, 21 Dec 2021 01:52:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mzUJs-0008Vj-Ff for pgsql-performance@lists.postgresql.org; Tue, 21 Dec 2021 01:52:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1BL1pxEE2688020; Mon, 20 Dec 2021 20:51:59 -0500 From: Tom Lane To: Lars Bergeson cc: pgsql-performance@lists.postgresql.org Subject: Re: Query is slower with a large proportion of NULLs in several columns In-reply-to: References: Comments: In-reply-to Lars Bergeson message dated "Mon, 20 Dec 2021 17:23:54 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2688018.1640051519.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 20 Dec 2021 20:51:59 -0500 Message-ID: <2688019.1640051519@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Lars Bergeson writes: > What is it about null values in the table that slows down the full table > scan? If a row has any nulls, then it contains a "nulls bitmap" [1] that says which columns are null, and that bitmap has to be consulted while walking through the row contents. So the most obvious theory here is that that adds overhead that's significant in your case. But there are some holes in that theory, mainly that the I/O timings you are showing don't seem very consistent: no nulls: > I/O Timings: read=3D1884365.335 > Execution Time: 11135.368 ms with nulls: > I/O Timings: read=3D17141420.771 > Execution Time: 25407.318 ms Regardless of CPU time required, it should not take 10X less I/O time to read a physically larger table. So there's something fairly bogus going on there. One thing you might try is disabling parallelism (set max_parallel_workers_per_gather =3D 0) to see if that's confusing the numbers somehow. regards, tom lane [1] https://www.postgresql.org/docs/current/storage-page-layout.html#STORA= GE-TUPLE-LAYOUT