Re: Performance Issue (Not using Index when joining two tables).

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gopisetty, Ramesh" <rameshg2(at)illinois(dot)edu>
Cc: Michael Lewis <mlewis(at)entrata(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, "pgsql-performance(at)lists(dot)postgresql(dot)org" <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: Performance Issue (Not using Index when joining two tables).
Date: 2020-09-14 17:40:11
Message-ID: 1124922.1600105211@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Gopisetty, Ramesh" <rameshg2(at)illinois(dot)edu> writes:
> Thanks for looking into the problem/issue. Let me give more details about the functions... Yes, we are using row level security.

Hm. If those expensive filter functions are being injected by RLS on the
target tables (rather than by something like an intermediate view), then
the planner is constrained to ensure that they execute before any query
conditions that it doesn't know to be "leakproof". So unless your join
operator is leakproof, the shape of plan that you're hoping for will not
be allowed. Since you haven't mentioned anything about data types, it's
hard to know whether that's the issue. (The hash condition seems to be
texteq, which is leakproof, but there are also casts involved which
might not be.)

The two queries you provided explain plans for are not the same, so
comparing their plans is a fairly pointless activity. *Of course*
the query runs faster when you restrict it to fetch fewer rows. The
original query has no restriction clause that corresponds to the
clauses being used for index conditions in the second query, so it's
hardly a surprise that you do not get that plan, RLS or no RLS.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Robert Treat 2020-09-14 23:11:12 autoanalyze creates bad plan, manual analyze fixes it?
Previous Message Gopisetty, Ramesh 2020-09-14 03:18:26 Re: Performance Issue (Not using Index when joining two tables).