Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7839d35

Browse files
committed
Add an "argisrow" field to NullTest nodes, following a plan made way back in
8.2beta but never carried out. This avoids repetitive tests of whether the argument is of scalar or composite type. Also, be a bit more paranoid about composite arguments in some places where we previously weren't checking.
1 parent 29c4ad9 commit 7839d35

File tree

14 files changed

+41
-30
lines changed

14 files changed

+41
-30
lines changed

src/backend/executor/execQual.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.257 2009/12/29 17:40:59 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.258 2010/01/01 23:03:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3475,7 +3475,7 @@ ExecEvalNullTest(NullTestState *nstate,
34753475
if (isDone && *isDone == ExprEndResult)
34763476
return result; /* nothing to check */
34773477

3478-
if (nstate->argisrow && !(*isNull))
3478+
if (ntest->argisrow && !(*isNull))
34793479
{
34803480
HeapTupleHeader tuple;
34813481
Oid tupType;
@@ -4704,7 +4704,6 @@ ExecInitExpr(Expr *node, PlanState *parent)
47044704

47054705
nstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecEvalNullTest;
47064706
nstate->arg = ExecInitExpr(ntest->arg, parent);
4707-
nstate->argisrow = type_is_rowtype(exprType((Node *) ntest->arg));
47084707
nstate->argdesc = NULL;
47094708
state = (ExprState *) nstate;
47104709
}

src/backend/nodes/copyfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.456 2009/12/29 20:11:45 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.457 2010/01/01 23:03:09 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1506,6 +1506,7 @@ _copyNullTest(NullTest *from)
15061506

15071507
COPY_NODE_FIELD(arg);
15081508
COPY_SCALAR_FIELD(nulltesttype);
1509+
COPY_SCALAR_FIELD(argisrow);
15091510

15101511
return newnode;
15111512
}

src/backend/nodes/equalfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.377 2009/12/23 02:35:21 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.378 2010/01/01 23:03:10 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -623,6 +623,7 @@ _equalNullTest(NullTest *a, NullTest *b)
623623
{
624624
COMPARE_NODE_FIELD(arg);
625625
COMPARE_SCALAR_FIELD(nulltesttype);
626+
COMPARE_SCALAR_FIELD(argisrow);
626627

627628
return true;
628629
}

src/backend/nodes/outfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.377 2009/12/29 20:11:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.378 2010/01/01 23:03:10 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1229,6 +1229,7 @@ _outNullTest(StringInfo str, NullTest *node)
12291229

12301230
WRITE_NODE_FIELD(arg);
12311231
WRITE_ENUM_FIELD(nulltesttype, NullTestType);
1232+
WRITE_BOOL_FIELD(argisrow);
12321233
}
12331234

12341235
static void

src/backend/nodes/readfuncs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.228 2009/12/15 17:57:46 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.229 2010/01/01 23:03:10 tgl Exp $
1212
*
1313
* NOTES
1414
* Path and Plan nodes do not have any readfuncs support, because we
@@ -963,6 +963,7 @@ _readNullTest(void)
963963

964964
READ_NODE_FIELD(arg);
965965
READ_ENUM_FIELD(nulltesttype, NullTestType);
966+
READ_BOOL_FIELD(argisrow);
966967

967968
READ_DONE();
968969
}

src/backend/optimizer/path/indxpath.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.243 2010/01/01 21:53:49 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.244 2010/01/01 23:03:10 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1256,7 +1256,8 @@ match_clause_to_indexcol(IndexOptInfo *index,
12561256
{
12571257
NullTest *nt = (NullTest *) clause;
12581258

1259-
if (match_index_to_operand((Node *) nt->arg, indexcol, index))
1259+
if (!nt->argisrow &&
1260+
match_index_to_operand((Node *) nt->arg, indexcol, index))
12601261
return true;
12611262
return false;
12621263
}

src/backend/optimizer/plan/planagg.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.48 2010/01/01 21:53:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.49 2010/01/01 23:03:10 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -308,6 +308,9 @@ build_minmax_path(PlannerInfo *root, RelOptInfo *rel, MinMaxAggInfo *info)
308308
ntest = makeNode(NullTest);
309309
ntest->nulltesttype = IS_NOT_NULL;
310310
ntest->arg = copyObject(info->target);
311+
ntest->argisrow = type_is_rowtype(exprType((Node *) ntest->arg));
312+
if (ntest->argisrow)
313+
return false; /* punt on composites */
311314
info->notnulltest = ntest;
312315

313316
/*

src/backend/optimizer/util/clauses.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.281 2009/12/15 17:57:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.282 2010/01/01 23:03:10 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHOR DATE MAJOR EVENT
@@ -1295,7 +1295,7 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
12951295
/* IS NOT NULL can be considered strict, but only at top level */
12961296
NullTest *expr = (NullTest *) node;
12971297

1298-
if (top_level && expr->nulltesttype == IS_NOT_NULL)
1298+
if (top_level && expr->nulltesttype == IS_NOT_NULL && !expr->argisrow)
12991299
result = find_nonnullable_rels_walker((Node *) expr->arg, false);
13001300
}
13011301
else if (IsA(node, BooleanTest))
@@ -1497,7 +1497,7 @@ find_nonnullable_vars_walker(Node *node, bool top_level)
14971497
/* IS NOT NULL can be considered strict, but only at top level */
14981498
NullTest *expr = (NullTest *) node;
14991499

1500-
if (top_level && expr->nulltesttype == IS_NOT_NULL)
1500+
if (top_level && expr->nulltesttype == IS_NOT_NULL && !expr->argisrow)
15011501
result = find_nonnullable_vars_walker((Node *) expr->arg, false);
15021502
}
15031503
else if (IsA(node, BooleanTest))
@@ -1601,7 +1601,7 @@ find_forced_null_var(Node *node)
16011601
/* check for var IS NULL */
16021602
NullTest *expr = (NullTest *) node;
16031603

1604-
if (expr->nulltesttype == IS_NULL)
1604+
if (expr->nulltesttype == IS_NULL && !expr->argisrow)
16051605
{
16061606
Var *var = (Var *) expr->arg;
16071607

@@ -2856,6 +2856,7 @@ eval_const_expressions_mutator(Node *node,
28562856
newntest = makeNode(NullTest);
28572857
newntest->arg = (Expr *) relem;
28582858
newntest->nulltesttype = ntest->nulltesttype;
2859+
newntest->argisrow = ntest->argisrow;
28592860
newargs = lappend(newargs, newntest);
28602861
}
28612862
/* If all the inputs were constants, result is TRUE */
@@ -2867,7 +2868,7 @@ eval_const_expressions_mutator(Node *node,
28672868
/* Else we need an AND node */
28682869
return (Node *) make_andclause(newargs);
28692870
}
2870-
if (arg && IsA(arg, Const))
2871+
if (!ntest->argisrow && arg && IsA(arg, Const))
28712872
{
28722873
Const *carg = (Const *) arg;
28732874
bool result;
@@ -2893,6 +2894,7 @@ eval_const_expressions_mutator(Node *node,
28932894
newntest = makeNode(NullTest);
28942895
newntest->arg = (Expr *) arg;
28952896
newntest->nulltesttype = ntest->nulltesttype;
2897+
newntest->argisrow = ntest->argisrow;
28962898
return (Node *) newntest;
28972899
}
28982900
if (IsA(node, BooleanTest))

src/backend/optimizer/util/plancat.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.159 2009/07/16 06:33:43 petere Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.160 2010/01/01 23:03:10 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -541,6 +541,7 @@ get_relation_constraints(PlannerInfo *root,
541541
att->atttypmod,
542542
0);
543543
ntest->nulltesttype = IS_NOT_NULL;
544+
ntest->argisrow = type_is_rowtype(att->atttypid);
544545
result = lappend(result, ntest);
545546
}
546547
}

src/backend/optimizer/util/predtest.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.28 2009/12/27 18:55:52 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/util/predtest.c,v 1.29 2010/01/01 23:03:10 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -1043,7 +1043,7 @@ predicate_implied_by_simple_clause(Expr *predicate, Node *clause)
10431043
Expr *nonnullarg = ((NullTest *) predicate)->arg;
10441044

10451045
/* row IS NOT NULL does not act in the simple way we have in mind */
1046-
if (!type_is_rowtype(exprType((Node *) nonnullarg)))
1046+
if (!((NullTest *) predicate)->argisrow)
10471047
{
10481048
if (is_opclause(clause) &&
10491049
list_member_strip(((OpExpr *) clause)->args, nonnullarg) &&
@@ -1102,7 +1102,7 @@ predicate_refuted_by_simple_clause(Expr *predicate, Node *clause)
11021102
Expr *isnullarg = ((NullTest *) predicate)->arg;
11031103

11041104
/* row IS NULL does not act in the simple way we have in mind */
1105-
if (type_is_rowtype(exprType((Node *) isnullarg)))
1105+
if (((NullTest *) predicate)->argisrow)
11061106
return false;
11071107

11081108
/* Any strict op/func on foo refutes foo IS NULL */
@@ -1118,6 +1118,7 @@ predicate_refuted_by_simple_clause(Expr *predicate, Node *clause)
11181118
/* foo IS NOT NULL refutes foo IS NULL */
11191119
if (clause && IsA(clause, NullTest) &&
11201120
((NullTest *) clause)->nulltesttype == IS_NOT_NULL &&
1121+
!((NullTest *) clause)->argisrow &&
11211122
equal(((NullTest *) clause)->arg, isnullarg))
11221123
return true;
11231124

@@ -1131,12 +1132,13 @@ predicate_refuted_by_simple_clause(Expr *predicate, Node *clause)
11311132
Expr *isnullarg = ((NullTest *) clause)->arg;
11321133

11331134
/* row IS NULL does not act in the simple way we have in mind */
1134-
if (type_is_rowtype(exprType((Node *) isnullarg)))
1135+
if (((NullTest *) clause)->argisrow)
11351136
return false;
11361137

11371138
/* foo IS NULL refutes foo IS NOT NULL */
11381139
if (predicate && IsA(predicate, NullTest) &&
11391140
((NullTest *) predicate)->nulltesttype == IS_NOT_NULL &&
1141+
!((NullTest *) predicate)->argisrow &&
11401142
equal(((NullTest *) predicate)->arg, isnullarg))
11411143
return true;
11421144

src/backend/parser/parse_expr.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.251 2009/12/15 17:57:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.252 2010/01/01 23:03:10 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -276,6 +276,7 @@ transformExpr(ParseState *pstate, Node *expr)
276276

277277
n->arg = (Expr *) transformExpr(pstate, (Node *) n->arg);
278278
/* the argument can be any type, so don't coerce it */
279+
n->argisrow = type_is_rowtype(exprType((Node *) n->arg));
279280
result = expr;
280281
break;
281282
}

src/include/catalog/catversion.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.563 2009/12/29 22:00:14 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.564 2010/01/01 23:03:10 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200912291
56+
#define CATALOG_VERSION_NO 201001011
5757

5858
#endif

src/include/nodes/execnodes.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.214 2009/12/15 04:57:48 rhaas Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.215 2010/01/01 23:03:10 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -886,8 +886,7 @@ typedef struct NullTestState
886886
{
887887
ExprState xprstate;
888888
ExprState *arg; /* input expression */
889-
bool argisrow; /* T if input is of a composite type */
890-
/* used only if argisrow: */
889+
/* used only if input is of composite type: */
891890
TupleDesc argdesc; /* tupdesc for most recent input */
892891
} NullTestState;
893892

src/include/nodes/primnodes.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.152 2009/12/15 17:57:47 tgl Exp $
13+
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.153 2010/01/01 23:03:10 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -936,9 +936,7 @@ typedef OpExpr NullIfExpr;
936936
* The appropriate test is performed and returned as a boolean Datum.
937937
*
938938
* NOTE: the semantics of this for rowtype inputs are noticeably different
939-
* from the scalar case. It would probably be a good idea to include an
940-
* "argisrow" flag in the struct to reflect that, but for the moment,
941-
* we do not do so to avoid forcing an initdb during 8.2beta.
939+
* from the scalar case. We provide an "argisrow" flag to reflect that.
942940
* ----------------
943941
*/
944942

@@ -952,6 +950,7 @@ typedef struct NullTest
952950
Expr xpr;
953951
Expr *arg; /* input expression */
954952
NullTestType nulltesttype; /* IS NULL, IS NOT NULL */
953+
bool argisrow; /* T if input is of a composite type */
955954
} NullTest;
956955

957956
/*

0 commit comments

Comments
 (0)