Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -536,11 +536,16 @@ flatten_rtes_walker(Node *node, flatten_rtes_walker_context *cxt)
536
536
* Recurse into subselects. Must update cxt->query to this query so
537
537
* that the rtable and rteperminfos correspond with each other.
538
538
*/
539
+ Query * save_query = cxt -> query ;
540
+ bool result ;
541
+
539
542
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 ;
544
549
}
545
550
return expression_tree_walker (node , flatten_rtes_walker ,
546
551
(void * ) cxt );
Original file line number Diff line number Diff line change @@ -5569,6 +5569,18 @@ select atts.relid::regclass, s.* from pg_stats s join
5569
5569
ERROR: column atts.relid does not exist
5570
5570
LINE 1: select atts.relid::regclass, s.* from pg_stats s join
5571
5571
^
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
+
5572
5584
--
5573
5585
-- Test LATERAL
5574
5586
--
Original file line number Diff line number Diff line change @@ -2086,6 +2086,12 @@ select atts.relid::regclass, s.* from pg_stats s join
2086
2086
indexrelid from pg_index i) atts on atts .attnum = a .attnum where
2087
2087
schemaname != ' pg_catalog' ;
2088
2088
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
+
2089
2095
--
2090
2096
-- Test LATERAL
2091
2097
--
0 commit comments