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.96) (envelope-from ) id 1vtQVi-006sRH-1H for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Feb 2026 13:25:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vtQVh-007xYM-13 for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Feb 2026 13:25:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vtQVh-007xYD-06 for pgsql-hackers@lists.postgresql.org; Fri, 20 Feb 2026 13:25:33 +0000 Received: from forward500b.mail.yandex.net ([178.154.239.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vtQVb-00000000Muh-3miw for pgsql-hackers@lists.postgresql.org; Fri, 20 Feb 2026 13:25:32 +0000 Received: from mail-nwsmtp-smtp-production-main-58.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-58.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1619:0:640:56cf:0]) by forward500b.mail.yandex.net (Yandex) with ESMTPS id A976BC0328; Fri, 20 Feb 2026 16:25:25 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-58.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id OPccdPdG9iE0-RCNThtxn; Fri, 20 Feb 2026 16:25:25 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tantorlabs.com; s=mail; t=1771593925; bh=kI/VgfHAff6Sdhz1GSpW3HS2cG7nz6eyNwUdoRUbEic=; h=In-Reply-To:References:To:Subject:Message-ID:Date:From; b=kVe3SlyB0th7mWvgwbyynMDVhKSq9yqsNwMLKzfM4MaxMrkAG9vxJGRODYulwSirv Erjrt7JlnQW+Xi1TMt8UGp+pZdX2rvAyuemv6aG5MpG0G8xO261O4JdhgHYlZxcbs4 s0FXYSZ9HboMipIsyf/R+bNvQVIOUfz0wvUg1mTE= Authentication-Results: mail-nwsmtp-smtp-production-main-58.iva.yp-c.yandex.net; dkim=pass header.i=@tantorlabs.com Content-Type: multipart/alternative; boundary="------------gqsCI3Hyil0YEqrZ7CL04qJp" Message-ID: Date: Fri, 20 Feb 2026 16:25:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reduce planning time for large NOT IN lists containing NULL From: Ilia Evdokimov To: David Geier , PostgreSQL Developers References: <52596e08-0902-475b-ad0f-265ec6918f19@gmail.com> <7791ec74-369d-48c7-969c-cf4ad18024f2@tantorlabs.com> Content-Language: en-US In-Reply-To: <7791ec74-369d-48c7-969c-cf4ad18024f2@tantorlabs.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------gqsCI3Hyil0YEqrZ7CL04qJp Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/20/26 12:06, Ilia Evdokimov wrote: > There is already ARR_HASNULL() which allows us to detect the presence > of NULL in ArrayType. > I've moved the NULL check higher, placing it immediately after DatumGetArrayTypeP(). This allows us to detect the presence of NULL elements before decontructing the array. I tested this with several queries of the form: WHERE x NOT IN (NULL, ...) In my tests (with column x having detailed statistics, so selectivity estimation performs more work), planning time decreases from *5-200 ms before the patch* to *~ 1-2 ms after the patch*, depending on the list size. -- Best regards. Ilia Evdokimov, Tantor Labs LLC, https://tantorlabs.com/ --------------gqsCI3Hyil0YEqrZ7CL04qJp Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

On 2/20/26 12:06, Ilia Evdokimov wrote:

There is already ARR_HASNULL() which allows us to detect the presence of NULL in ArrayType.

I've moved the NULL check higher, placing it immediately after DatumGetArrayTypeP(). This allows us to detect the presence of NULL elements before decontructing the array.


I tested this with several queries of the form:

WHERE x NOT IN (NULL, ...)

In my tests (with column x having detailed statistics, so selectivity estimation performs more work), planning time decreases from 5-200 ms before the patch to ~ 1-2 ms after the patch, depending on the list size.

--
Best regards.
Ilia Evdokimov,
Tantor Labs LLC,
https://tantorlabs.com/

--------------gqsCI3Hyil0YEqrZ7CL04qJp--