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 1tAqFF-000OoZ-5i for pgsql-general@arkaria.postgresql.org; Tue, 12 Nov 2024 12:43:44 +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 1tAqFB-0066Uy-Vk for pgsql-general@arkaria.postgresql.org; Tue, 12 Nov 2024 12:43:42 +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 1tAqFB-0066Up-IU for pgsql-general@lists.postgresql.org; Tue, 12 Nov 2024 12:43:42 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAqF8-001XMD-7Z for pgsql-general@postgresql.org; Tue, 12 Nov 2024 12:43:41 +0000 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-83ab94452a7so235131139f.3 for ; Tue, 12 Nov 2024 04:43:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ilm.com; s=google; t=1731415417; x=1732020217; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Azf4DaIRcdAabmkrzQN9vFHe9SEhhE3vfTTX5fig/aw=; b=F3FbWn+ZMlrsfc6V9voD+Ej43c8kje2NZwjvgd0DYNvynT8qDw5EAtoiLQlmwMkeTX 2y6VlAok3F2II7TpGGBLj8YbgUqxGqKfm3w8r6vxm2W9bXslhSNBbsCtqk82HHsPS5Mh 0JA2ESeoHDlkLhBG1IWZCsXw56/wBb+//v+oU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731415417; x=1732020217; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Azf4DaIRcdAabmkrzQN9vFHe9SEhhE3vfTTX5fig/aw=; b=NeKkQp1Iy+qPe4bsN/QT6tM8tsXbaiQp8gCZsfowWvdkUSbyBtbnxNUSNRHFdctP8s oMqKDt+tazfHaCotNLeHYIDTWtstH0D9+0FsxsBp6PtJ2NXfGYhgPRx+WuVtV1knWfe5 tgQBNYyqK5GDWn6iAlRFHSqk/bNoNqRUb0+g/MwHKxuWknmNaXB57qGvN9eZN7hmjpNg vKuOaWVyeErjrblQIGCCAb/KZi+NdiakZP74msU3YWowl3kWkwCsiFDcncfOmPCyBCYT jvg6Uy1kdKulyxodarAhqOvK3jLdq6YStckaC0K77AkjZPdDAZ9JXDu2MLbxEjF8IZ2Z yFYA== X-Gm-Message-State: AOJu0YxcccaT0ixx9eT7pquZz37K5FlvG32SjJb9U0wtjQ8fVj/ZimOr mO2fycPiYlfN8Yydfu1Eajv86sowqbl+NcMZFlhfQPsXA/hh+UL7oKjbFW52wNGDtaDc43bT2C+ 4C/k2dYCDJL8OMnyoqsmHVbxhKAcXubnlWE6wAjN67Qj6qaezqqo= X-Google-Smtp-Source: AGHT+IEz3bPcINr9eZNj+tqy1pUDA1reyH3l/9K/gjUrzaTDJ7kcfyt5bKpJ+s5k36by0ytRAWnv4n8d3+ktJJ1/6c4= X-Received: by 2002:a05:6602:29d1:b0:82d:754:5026 with SMTP id ca18e2360f4ac-83e431a3269mr313275339f.4.1731415417479; Tue, 12 Nov 2024 04:43:37 -0800 (PST) MIME-Version: 1.0 From: Jim Vanns Date: Tue, 12 Nov 2024 12:43:26 +0000 Message-ID: Subject: BitmapOr node not used in plan for ANY/IN but is for sequence of ORs ... To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000eb0d170626b6909a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000eb0d170626b6909a Content-Type: text/plain; charset="UTF-8" In PG16.4, we have a table of key/pair data (around 30M rows) where there are about 7 distinct keys and each has a conditional or partial index on them (the distribution is different for each key/value pair combination). I've found that when we have a query that uses an OR then those partial indexes are used but not if the query is written to use ANY/IN, which is more convenient from a programmer POV (especially any with 3rd party query generators etc.). Naturally, the result sets returned by the queries are identical due to the filter semantics of any of the 3 solution variants. Here's a shareable, MRP; https://dbfiddle.uk/OKs_7HWv Is there any trick I can do to get the planner to make use of the conditional/partial index? Or is this simply an unoptimised code path yet to be exploited!? Cheers, Jim -- Jim Vanns Principal Production Engineer Industrial Light & Magic, London --000000000000eb0d170626b6909a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In PG16.4, we have a table of key/pair data (around 3= 0M rows) where there are about 7 distinct keys and each has a conditional o= r partial index on them (the distribution is different for each key/value p= air combination).=C2=A0 I've found that when we have a query that uses = an OR then those partial indexes are used but not if the query is written t= o use ANY/IN, which is more convenient from a programmer POV (especially an= y with 3rd party query generators etc.). Naturally, the result sets returne= d by the queries are identical due to the filter semantics of any of the 3 = solution variants.

Here's a shareable, MRP;


Is there any trick I can do = to get the planner to make use of the conditional/partial index? Or is this= simply an unoptimised code path yet to be exploited!?

=
Cheers,

Jim

--
Jim Vanns
= Principal Production Engineer
Industrial Light & Magic, London
=
--000000000000eb0d170626b6909a--