Commit 47549313 authored by Marc G. Fournier's avatar Marc G. Fournier

|Subject: Postgres patch: Assert attribute type match

|
|Here's a patch for Version 2 only.  It just adds an Assert to catch some
|inconsistencies in the catalog classes.
|
|--
|Bryan Henderson                                    Phone 408-227-6803
|San Jose, California
|
parent c5dd2920
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.1.1.1 1996/07/09 06:21:25 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.2 1996/09/16 05:33:20 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -172,8 +172,24 @@ ExecEvalAggreg(Aggreg *agg, ExprContext *econtext, bool *isNull) ...@@ -172,8 +172,24 @@ ExecEvalAggreg(Aggreg *agg, ExprContext *econtext, bool *isNull)
* *
* Returns a Datum whose value is the value of a range * Returns a Datum whose value is the value of a range
* variable with respect to given expression context. * variable with respect to given expression context.
* ---------------------------------------------------------------- *
*/ *
* As an entry condition, we expect that the the datatype the
* plan expects to get (as told by our "variable" argument) is in
* fact the datatype of the attribute the plan says to fetch (as
* seen in the current context, identified by our "econtext"
* argument).
*
* If we fetch a Type A attribute and Caller treats it as if it
* were Type B, there will be undefined results (e.g. crash).
* One way these might mismatch now is that we're accessing a
* catalog class and the type information in the pg_attribute
* class does not match the hardcoded pg_attribute information
* (in pg_attribute.h) for the class in question.
*
* We have an Assert to make sure this entry condition is met.
*
* ---------------------------------------------------------------- */
Datum Datum
ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull) ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull)
{ {
...@@ -214,6 +230,10 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull) ...@@ -214,6 +230,10 @@ ExecEvalVar(Var *variable, ExprContext *econtext, bool *isNull)
attnum = variable->varattno; attnum = variable->varattno;
/* (See prolog for explanation of this Assert) */
Assert(attnum < 0 ||
variable->vartype == tuple_type->attrs[attnum-1]->atttypid)
/* /*
* If the attribute number is invalid, then we are supposed to * If the attribute number is invalid, then we are supposed to
* return the entire tuple, we give back a whole slot so that * return the entire tuple, we give back a whole slot so that
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: tupdesc.h,v 1.1 1996/08/27 21:50:26 scrappy Exp $ * $Id: tupdesc.h,v 1.2 1996/09/16 05:33:13 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,21 +18,16 @@ ...@@ -18,21 +18,16 @@
#include "nodes/pg_list.h" /* for List */ #include "nodes/pg_list.h" /* for List */
#include "catalog/pg_attribute.h" #include "catalog/pg_attribute.h"
/*
* a TupleDesc is an array of AttributeTupleForms, each of which is a
* pointer to a AttributeTupleForm
*/
/* typedef AttributeTupleForm *TupleDesc; */
/* a TupleDesc is a pointer to a structure which includes an array of */
/* AttributeTupleForms, i.e. pg_attribute information, and the size of */
/* the array, i.e. the number of attributes */
/* in short, a TupleDesc completely captures the attribute information */
/* for a tuple */
typedef struct tupleDesc { typedef struct tupleDesc {
/*------------------------------------------------------------------------
This structure contains all the attribute information (i.e. from Class
pg_attribute) for a tuple.
-------------------------------------------------------------------------*/
int natts; int natts;
/* Number of attributes in the tuple */
AttributeTupleForm *attrs; AttributeTupleForm *attrs;
/* attrs[N] is a pointer to the description of Attribute Number N+1. */
} *TupleDesc; } *TupleDesc;
extern TupleDesc CreateTemplateTupleDesc(int natts); extern TupleDesc CreateTemplateTupleDesc(int natts);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment