mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Make eval_const_expressions simplify FieldSelect from a whole-row Var
into an ordinary one-field Var. Per example from Chris Mungall.
This commit is contained in:
		@@ -8,7 +8,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * IDENTIFICATION
 | 
					 * IDENTIFICATION
 | 
				
			||||||
 *	  $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.131 2003/03/10 03:53:50 tgl Exp $
 | 
					 *	  $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.132 2003/03/14 00:55:17 tgl Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * HISTORY
 | 
					 * HISTORY
 | 
				
			||||||
 *	  AUTHOR			DATE			MAJOR EVENT
 | 
					 *	  AUTHOR			DATE			MAJOR EVENT
 | 
				
			||||||
@@ -1497,6 +1497,28 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
 | 
				
			|||||||
		newcoalesce->args = newargs;
 | 
							newcoalesce->args = newargs;
 | 
				
			||||||
		return (Node *) newcoalesce;
 | 
							return (Node *) newcoalesce;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (IsA(node, FieldSelect))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							/*
 | 
				
			||||||
 | 
							 * We can optimize field selection from a whole-row Var into a
 | 
				
			||||||
 | 
							 * simple Var.  (This case won't be generated directly by the
 | 
				
			||||||
 | 
							 * parser, because ParseComplexProjection short-circuits it.
 | 
				
			||||||
 | 
							 * But it can arise while simplifying functions.)  If the argument
 | 
				
			||||||
 | 
							 * isn't a whole-row Var, just fall through to do generic processing.
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							FieldSelect *fselect = (FieldSelect *) node;
 | 
				
			||||||
 | 
							Var		   *argvar = (Var *) fselect->arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (argvar && IsA(argvar, Var) &&
 | 
				
			||||||
 | 
								argvar->varattno == InvalidAttrNumber)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return (Node *) makeVar(argvar->varno,
 | 
				
			||||||
 | 
														fselect->fieldnum,
 | 
				
			||||||
 | 
														fselect->resulttype,
 | 
				
			||||||
 | 
														fselect->resulttypmod,
 | 
				
			||||||
 | 
														argvar->varlevelsup);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * For any node type not handled above, we recurse using
 | 
						 * For any node type not handled above, we recurse using
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user