Re: Postgres 15 SELECT query doesn't use index under RLS - Mailing list pgsql-performance

From Alexander Okulovich
Subject Re: Postgres 15 SELECT query doesn't use index under RLS
Date
Msg-id 6c888a16-b206-4817-b5ca-9e09b904edde@stiltsoft.com
Whole thread Raw
In response to Re: Postgres 15 SELECT query doesn't use index under RLS  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Postgres Locking  ("Dirschel, Steve" <steve.dirschel@thomsonreuters.com>)
List pgsql-performance

Hi Tom,

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?
Here are the results from the prod instance:

seqscan off

indexscan_off

Just noticed that the WHEN clause differs from the initial one (392 ids under RLS). Probably, this is why the execution time isn't so catastrophic. Please let me know if this matters, and I'll rerun this with the initial request. Speaking of the stage vs local Docker Postgres instance, the execution time on stage is so short (0.1 ms with seq scan, 0.195 with index scan) that we probably should not consider them. But I'll execute the requests if it's necessary.

Maybe your prod installation has a bloated index, and that's driving
up the estimated cost enough to steer the planner away from it.
We tried to make REINDEX CONCURRENTLY on a prod copy, but the planner still used Seq Scan instead of Index Scan afterward.

Kind regards,

Alexander

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Postgres 15 SELECT query doesn't use index under RLS
Next
From: "Dirschel, Steve"
Date:
Subject: Postgres Locking