From ae93e5fd6e8a7e2321e87d23165d9d7660cde598 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 5 Jun 2004 01:55:05 +0000 Subject: Make the world very nearly safe for composite-type columns in tables. 1. Solve the problem of not having TOAST references hiding inside composite values by establishing the rule that toasting only goes one level deep: a tuple can contain toasted fields, but a composite-type datum that is to be inserted into a tuple cannot. Enforcing this in heap_formtuple is relatively cheap and it avoids a large increase in the cost of running the tuptoaster during final storage of a row. 2. Fix some interesting problems in expansion of inherited queries that reference whole-row variables. We never really did this correctly before, but it's now relatively painless to solve by expanding the parent's whole-row Var into a RowExpr() selecting the proper columns from the child. If you dike out the preventive check in CheckAttributeType(), composite-type columns now seem to actually work. However, we surely cannot ship them like this --- without I/O for composite types, you can't get pg_dump to dump tables containing them. So a little more work still to do. --- src/backend/optimizer/util/relnode.c | 5 ++++- src/backend/optimizer/util/tlist.c | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src/backend/optimizer/util') diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 36e688135a..58d4f58880 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.59 2004/06/01 03:03:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.60 2004/06/05 01:55:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -381,6 +381,9 @@ build_joinrel_tlist(Query *root, RelOptInfo *joinrel) Var *var = (Var *) lfirst(vars); int ndx = var->varattno - baserel->min_attr; + /* We can't run into any child RowExprs here */ + Assert(IsA(var, Var)); + if (bms_nonempty_difference(baserel->attr_needed[ndx], relids)) { joinrel->reltargetlist = lappend(joinrel->reltargetlist, var); diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c index dcee4f8c31..4878ebb027 100644 --- a/src/backend/optimizer/util/tlist.c +++ b/src/backend/optimizer/util/tlist.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.64 2004/05/30 23:40:31 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/tlist.c,v 1.65 2004/06/05 01:55:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,6 +17,7 @@ #include "nodes/makefuncs.h" #include "optimizer/tlist.h" #include "optimizer/var.h" +#include "parser/parse_expr.h" /***************************************************************************** @@ -83,13 +84,28 @@ tlist_member(Node *node, List *targetlist) * create_tl_element * Creates a target list entry node and its associated (resdom var) pair * with its resdom number equal to 'resdomno'. + * + * Note: the argument is almost always a Var, but occasionally not. */ TargetEntry * create_tl_element(Var *var, int resdomno) { + Oid vartype; + int32 vartypmod; + + if (IsA(var, Var)) + { + vartype = var->vartype; + vartypmod = var->vartypmod; + } + else + { + vartype = exprType((Node *) var); + vartypmod = exprTypmod((Node *) var); + } return makeTargetEntry(makeResdom(resdomno, - var->vartype, - var->vartypmod, + vartype, + vartypmod, NULL, false), (Expr *) var); -- cgit v1.2.1