Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c7468c7

Browse files
committed
Fix buggy recursion in flatten_rtes_walker().
Must save-and-restore the context we are modifying. Oversight in commit a61b1f7. Tender Wang Discussion: https://postgr.es/m/CAHewXNnnNySD_YcKNuFpQDV2gxWA7_YLWqHmYVcyoOYxn8kY2A@mail.gmail.com Discussion: https://postgr.es/m/20230212233711.GA1316@telsasoft.com
1 parent f50f029 commit c7468c7

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/backend/optimizer/plan/setrefs.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,16 @@ flatten_rtes_walker(Node *node, flatten_rtes_walker_context *cxt)
536536
* Recurse into subselects. Must update cxt->query to this query so
537537
* that the rtable and rteperminfos correspond with each other.
538538
*/
539+
Query *save_query = cxt->query;
540+
bool result;
541+
539542
cxt->query = (Query *) node;
540-
return query_tree_walker((Query *) node,
541-
flatten_rtes_walker,
542-
(void *) cxt,
543-
QTW_EXAMINE_RTES_BEFORE);
543+
result = query_tree_walker((Query *) node,
544+
flatten_rtes_walker,
545+
(void *) cxt,
546+
QTW_EXAMINE_RTES_BEFORE);
547+
cxt->query = save_query;
548+
return result;
544549
}
545550
return expression_tree_walker(node, flatten_rtes_walker,
546551
(void *) cxt);

src/test/regress/expected/join.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5569,6 +5569,18 @@ select atts.relid::regclass, s.* from pg_stats s join
55695569
ERROR: column atts.relid does not exist
55705570
LINE 1: select atts.relid::regclass, s.* from pg_stats s join
55715571
^
5572+
-- Test bug in rangetable flattening
5573+
explain (verbose, costs off)
5574+
select 1 from
5575+
(select * from int8_tbl where q1 <> (select 42) offset 0) ss
5576+
where false;
5577+
QUERY PLAN
5578+
--------------------------
5579+
Result
5580+
Output: 1
5581+
One-Time Filter: false
5582+
(3 rows)
5583+
55725584
--
55735585
-- Test LATERAL
55745586
--

src/test/regress/sql/join.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,12 @@ select atts.relid::regclass, s.* from pg_stats s join
20862086
indexrelid from pg_index i) atts on atts.attnum = a.attnum where
20872087
schemaname != 'pg_catalog';
20882088

2089+
-- Test bug in rangetable flattening
2090+
explain (verbose, costs off)
2091+
select 1 from
2092+
(select * from int8_tbl where q1 <> (select 42) offset 0) ss
2093+
where false;
2094+
20892095
--
20902096
-- Test LATERAL
20912097
--

0 commit comments

Comments
 (0)