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 1oxqkf-0002Sv-MS for pgsql-general@arkaria.postgresql.org; Wed, 23 Nov 2022 14:29:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oxqke-00084A-J0 for pgsql-general@arkaria.postgresql.org; Wed, 23 Nov 2022 14:29:24 +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 1oxqke-000840-81 for pgsql-general@lists.postgresql.org; Wed, 23 Nov 2022 14:29:24 +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 1oxqkb-0005dC-Rd for pgsql-general@postgresql.org; Wed, 23 Nov 2022 14:29:23 +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 2ANETJeD3695030; Wed, 23 Nov 2022 09:29:19 -0500 From: Tom Lane To: Danny Shemesh cc: Laurenz Albe , pgsql-general@postgresql.org Subject: Re: Index filter instead of index condition w/ IN / ANY queries above certain set size In-reply-to: References: Comments: In-reply-to Danny Shemesh message dated "Wed, 23 Nov 2022 15:38:47 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3695028.1669213759.1@sss.pgh.pa.us> Date: Wed, 23 Nov 2022 09:29:19 -0500 Message-ID: <3695029.1669213759@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Danny Shemesh writes: > -> Index Only Scan using > idx_hashes on refs (cost=0.56..722735.47 rows=33715 width=16) (actual > time=1727.208..1727.208 rows=1 loops=1) > Index Cond: (tid = > '13371337-1337-1337-1337-133713371337'::uuid) > * Filter: (tidh = ANY > ('{13391339-1339-1339-1339-133913391339}'::uuid[])) <<<<<<<<<<<<<<<- > Note this line* Rows Removed > by Filter: 109087 > Heap Fetches: 16976 > Buffers: shared hit=13051 > read=14561 > I/O Timings: read=53405.294 This doesn't match up terribly well with the table definition you showed before, but I wonder whether tidh is a low-order index column. If you need to optimize this specific shape of query you need to pay attention to the index column order, per https://www.postgresql.org/docs/current/indexes-multicolumn.html That is, tid and tidh need to be the first two index columns. regards, tom lane