Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables.

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, nikhil raj <nikhilraj474(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables.
Date: 2024-08-28 07:31:27
Message-ID: CAMbWs49gVdBxrjvz82Tqs9UL+ZDNV5cx85ZURhfxUaz-0wz-pQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Wed, Aug 28, 2024 at 7:58 AM David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> On Wed, 28 Aug 2024 at 11:37, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Oh, scratch that, I see you mean this is an additional way to do it
> > not the only way to do it. But I'm confused why it works for
> > t1.two+1 AS c1
> > but not
> > t1.two+t2.two AS c1
> > Those ought to look pretty much the same for this purpose.
>
> The bms_overlap(pull_varnos(rcon->root, newnode), rcon->relids) test
> is false with t1.two+1. Looks like there needs to be a Var from t2
> for the bms_overlap to be true

Exactly. What Tom's patch does is that if the expression contains
Vars/PHVs that belong to the subquery, and does not contain any
non-strict constructs, then it can escape being wrapped.

In expression 't1.two+t2.two', 't2.two' is a Var that belongs to the
subquery, and '+' is strict, so it can escape being wrapped.

The expression 't1.two+1' does not meet these conditions, so it is
wrapped into a PHV, and the PHV contains lateral reference to t1,
which results in a nestloop join with a parameterized inner path.
That's why Memoize can work in this query.

Thanks
Richard

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2024-08-28 08:56:34 Re: Strange behaviors with ranges
Previous Message Richard Guo 2024-08-28 07:08:16 Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables.

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2024-08-28 08:09:27 Add const qualifiers to XLogRegister*() functions
Previous Message Richard Guo 2024-08-28 07:08:16 Re: Significant Execution Time Difference Between PG13.14 and PG16.4 for Query on information_schema Tables.