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 1sNGtG-007ghf-4b for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Jun 2024 19:04:10 +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 1sNGtC-006OFI-Lu for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Jun 2024 19:04:06 +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 1sNGtC-006OF9-Dp for pgsql-bugs@lists.postgresql.org; Fri, 28 Jun 2024 19:04:06 +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 1sNGtA-0042Gd-AW for pgsql-bugs@lists.postgresql.org; Fri, 28 Jun 2024 19:04: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 45SJ42lQ2001237; Fri, 28 Jun 2024 15:04:02 -0400 From: Tom Lane To: blamario@protonmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18525: Boolean aggregate functions like EVERY/BOOL_AND should shortcut In-reply-to: <18525-b36c2e34bde50082@postgresql.org> References: <18525-b36c2e34bde50082@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 28 Jun 2024 07:14:21 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2001235.1719601442.1@sss.pgh.pa.us> Date: Fri, 28 Jun 2024 15:04:02 -0400 Message-ID: <2001236.1719601442@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > I was hoping that the EVERY aggregate functions would > _shortcut_ the aggregate as soon as a non-null value was encountered, and > furthermore that the SELECT statement would stop searching once all results > are established to be false. Don't hold your breath. That would require poking a lot of holes in our abstract API for aggregate functions, and the potential return seems rather, um, specialized. You can get an efficient plan for what you want along the lines of select exists(select * from large_table where field1 is not null), exists(select * from large_table where field2 is not null), ... This will result in a scan per EXISTS() rather than just one scan, but on the other hand the scans will be smart enough to use indexes where helpful. In any case they will stop at first match. regards, tom lane