mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Ignore extra subquery outputs in set_subquery_size_estimates().
In commit 0f61d4dd1b, I added code to copy up
column width estimates for each column of a subquery.  That code supposed
that the subquery couldn't have any output columns that didn't correspond
to known columns of the current query level --- which is true when a query
is parsed from scratch, but the assumption fails when planning a view that
depends on another view that's been redefined (adding output columns) since
the upper view was made.  This results in an assertion failure or even a
crash, as per bug #8025 from lindebg.  Remove the Assert and instead skip
the column if its resno is out of the expected range.
			
			
This commit is contained in:
		@@ -3741,6 +3741,15 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
 | 
				
			|||||||
		if (te->resjunk)
 | 
							if (te->resjunk)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * The subquery could be an expansion of a view that's had columns
 | 
				
			||||||
 | 
							 * added to it since the current query was parsed, so that there are
 | 
				
			||||||
 | 
							 * non-junk tlist columns in it that don't correspond to any column
 | 
				
			||||||
 | 
							 * visible at our query level.  Ignore such columns.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							if (te->resno < rel->min_attr || te->resno > rel->max_attr)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * XXX This currently doesn't work for subqueries containing set
 | 
							 * XXX This currently doesn't work for subqueries containing set
 | 
				
			||||||
		 * operations, because the Vars in their tlists are bogus references
 | 
							 * operations, because the Vars in their tlists are bogus references
 | 
				
			||||||
@@ -3762,7 +3771,6 @@ set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			item_width = subrel->attr_widths[var->varattno - subrel->min_attr];
 | 
								item_width = subrel->attr_widths[var->varattno - subrel->min_attr];
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		Assert(te->resno >= rel->min_attr && te->resno <= rel->max_attr);
 | 
					 | 
				
			||||||
		rel->attr_widths[te->resno - rel->min_attr] = item_width;
 | 
							rel->attr_widths[te->resno - rel->min_attr] = item_width;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user