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 1qw13T-0093zG-Jq for pgsql-performance@arkaria.postgresql.org; Thu, 26 Oct 2023 14:09:47 +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 1qw13R-000kCi-4L for pgsql-performance@arkaria.postgresql.org; Thu, 26 Oct 2023 14:09:45 +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 1qw13Q-000kCa-QL for pgsql-performance@lists.postgresql.org; Thu, 26 Oct 2023 14:09:44 +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 1qw13K-002PtR-Pp for pgsql-performance@postgresql.org; Thu, 26 Oct 2023 14:09:43 +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 39QE9bse1157087; Thu, 26 Oct 2023 10:09:37 -0400 From: Tom Lane To: Alexander Okulovich cc: pgsql-performance@postgresql.org Subject: Re: Postgres 15 SELECT query doesn't use index under RLS In-reply-to: References: <5c1179bb-240b-4c1c-b4b3-2a24868e44bc@stiltsoft.com> <1570249.1697228785@sss.pgh.pa.us> <3153246.1697661350@sss.pgh.pa.us> Comments: In-reply-to Alexander Okulovich message dated "Thu, 26 Oct 2023 15:47:03 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1157085.1698329377.1@sss.pgh.pa.us> Date: Thu, 26 Oct 2023 10:09:37 -0400 Message-ID: <1157086.1698329377@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Okulovich writes: > I've attempted to reproduce this on my PC in Docker from the stage > database dump, but no luck. The first query execution on Postgres 15 > behaves like on the real stage, but subsequent ones use the index. Can you force it in either direction with "set enable_seqscan = off" (resp. "set enable_indexscan = off")? If so, how do the estimated costs compare for the two plan shapes? > Also, > they execute much faster. Looks like the hardware and(or) the data > structure on disk matters. Maybe your prod installation has a bloated index, and that's driving up the estimated cost enough to steer the planner away from it. regards, tom lane