Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r4pNs-00APaN-TH for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Nov 2023 21:31:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r4pNr-004qYI-B3 for pgsql-bugs@arkaria.postgresql.org; Sun, 19 Nov 2023 21:31:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r4pNr-004qY9-2J for pgsql-bugs@lists.postgresql.org; Sun, 19 Nov 2023 21:31:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r4pNk-007Iz7-NO for pgsql-bugs@lists.postgresql.org; Sun, 19 Nov 2023 21:31:14 +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 3AJLUn5G1147964; Sun, 19 Nov 2023 16:30:49 -0500 From: Tom Lane To: Andres Freund cc: dmigowski@ikoffice.de, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18205: Performance regression with NOT NULL checks. In-reply-to: <20231119211203.o5qczelolmbczawt@awork3.anarazel.de> References: <18205-53c59cab45881d52@postgresql.org> <1130864.1700420885@sss.pgh.pa.us> <20231119211203.o5qczelolmbczawt@awork3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Sun, 19 Nov 2023 13:12:03 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1147962.1700429449.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 19 Nov 2023 16:30:49 -0500 Message-ID: <1147963.1700429449@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > On 2023-11-19 14:08:05 -0500, Tom Lane wrote: >> So that results in not having to deconstruct most of the tuple, >> whereas in the new code we do have to, thanks to b8d7f053c's >> decision to batch all the variable-value-extraction work. > Yea, I think we were aware at the time that this does have downsides - i= t's > just that the worst case behaviour of *not* batching are much bigger tha= n the > worst-case downside of batching. Agreed. Still ... > We actually did add fastpaths for a few similar cases: ExecJustInnerVar(= ) etc > will just use slot_getattr(). These can be used when the result is just = a > single variable. However, the goal there was more to avoid "interpreter > startup" overhead, rather than evaluation overhead. Yeah. Also, if I'm reading the example appropriately, Daniel's case *does* involve fetching more than a single column --- but the other ones are up near the start so we didn't use to have to deform very much of the tuple. > What if we instead load 8 bytes of the bitmap into a uint64 before enter= ing > the loop, and shift an "index" mask into the bitmap by one each iteratio= n > through the loop? Meh. Seems like a micro-optimization that does nothing for the big-O problem. One thing to think about is that I suspect "all the columns are null" is just a simple test case and not very representative of the real-world problem. In the real case, probably quite a few of the leading columns are non-null, which would make Daniel's issue even worse because slot_deform_tuple would have to do significantly more work that it didn't do before. Shaving cycles off the null-column fast path would be proportionally less useful too. It might well be that what you suggest is worth doing just to cut the cost of slot_deform_tuple across the board, but I don't think it's an answer to this complaint specifically. regards, tom lane