pgsql: Skip unnecessary get_relids_in_jointree() when there are no PHVs

From: Richard Guo <rguo(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Skip unnecessary get_relids_in_jointree() when there are no PHVs
Date: 2026-07-20 03:18:37
Message-ID: E1wleWc-000Cus-0u@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Skip unnecessary get_relids_in_jointree() when there are no PHVs

Commit 1df9e8d96 made remove_useless_result_rtes() compute the set of
baserels in the jointree, to pass down to the find_dependent_phvs()
checks. But those checks are no-ops when the query contains no PHVs,
since find_dependent_phvs() and find_dependent_phvs_in_jointree() both
return early in that case. So we can avoid the
get_relids_in_jointree() scan altogether when root->glob->lastPHId is
zero, leaving baserels as NULL.

Author: Richard Guo <guofenglinux(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/CAMbWs49H275KzgZr3Cd1Hy+6Lmwp35bZ+5PrVc62k3HDLj6hNQ@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/72457f1df803bba077b338d5ed3fb8418e69967d

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2026-07-20 05:51:42 pgsql: Handle concurrent sequence refreshes.
Previous Message Peter Geoghegan 2026-07-20 02:16:26 pgsql: Run nbtree test module tests under autoconf builds