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 1rYSYn-00G6nh-P6 for pgsql-performance@arkaria.postgresql.org; Fri, 09 Feb 2024 15:13:02 +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 1rYSYm-009MpU-HG for pgsql-performance@arkaria.postgresql.org; Fri, 09 Feb 2024 15:13:00 +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.94.2) (envelope-from ) id 1rYSYm-009MpM-3L for pgsql-performance@lists.postgresql.org; Fri, 09 Feb 2024 15:13:00 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rYSYj-005u79-M2 for pgsql-performance@lists.postgresql.org; Fri, 09 Feb 2024 15:12:58 +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 419FCtIV1394634; Fri, 9 Feb 2024 10:12:55 -0500 From: Tom Lane To: kimaidou cc: pgsql-performance@lists.postgresql.org Subject: Re: Simple JOIN on heavy table not using expected index In-reply-to: References: Comments: In-reply-to kimaidou message dated "Fri, 09 Feb 2024 15:14:31 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1394632.1707491575.1@sss.pgh.pa.us> Date: Fri, 09 Feb 2024 10:12:55 -0500 Message-ID: <1394633.1707491575@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk kimaidou writes: > It seems PostgreSQL does not use the index parcelles_dep_idx on "dep" (text > field), even if the corresponding number of lines for this WHERE clause is > a smal subset of the entire data: > approx 6M against 80M in total 6M out of 80M rows is not a "small subset". Typically I'd expect the planner to use an index-based scan for up to 1 or 2 percent of the table. Beyond that, you're going to be touching most pages of the table anyway. You can try reducing random_page_cost to favor indexscans, but you might not find that the query gets any faster. regards, tom lane