pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Subject: Core dump in range_table_mutator()
Date: Fri, 24 Jun 2022 17:44:05 -0400
Message-ID: <545569.1656107045@sss.pgh.pa.us> (raw)

Commit 64919aaab made pull_up_simple_subquery set rte->subquery = NULL
after doing the deed, so that we don't waste cycles copying a
now-useless subquery tree around.  I discovered today while
working on another patch that if you invoke query_tree_mutator
or range_table_mutator on the whole Query after that point,
range_table_mutator dumps core, because it's expecting subquery
links to never be NULL.  There's apparently noplace in our core
code that does that today, but I'm a bit surprised we've not heard
complaints from anyone else.  I propose to do this to harden it:

inline patch 1: src/backend/nodes/nodeFuncs.c (+3/-1 lines) download inline-1.patchdiff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 876f84dd39..8d58265010 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -3788,7 +3788,9 @@ range_table_mutator(List *rtable, /* we don't bother to copy eref, aliases, etc; OK? */ break; case RTE_SUBQUERY: - if (!(flags & QTW_IGNORE_RT_SUBQUERIES)) + /* In the planner, subquery is null if it's been flattened */ + if (!(flags & QTW_IGNORE_RT_SUBQUERIES) && + rte->subquery != NULL) { CHECKFLATCOPY(newrte->subquery, rte->subquery, Query); MUTATE(newrte->subquery, newrte->subquery, Query *);
regards, tom lane

view thread (5+ messages)  latest in thread

Message-ID: <545569.1656107045@sss.pgh.pa.us>
Permalink:  ../545569.1656107045@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/545569.1656107045@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: Core dump in range_table_mutator()
  In-Reply-To: <545569.1656107045@sss.pgh.pa.us>
  References: <545569.1656107045@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox