diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-28 01:30:02 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-28 01:30:02 +0000 |
| commit | 6e07709760a29d8dbfb93b9846c905bd40689082 (patch) | |
| tree | 9bf0084587d7e313ba087ce53c24bc748c63a456 /src/backend/nodes | |
| parent | a37422e042a6114ab0e513f50dac4a47fab22313 (diff) | |
| download | postgresql-6e07709760a29d8dbfb93b9846c905bd40689082.tar.gz | |
Implement SQL-compliant treatment of row comparisons for < <= > >= cases
(previously we only did = and <> correctly). Also, allow row comparisons
with any operators that are in btree opclasses, not only those with these
specific names. This gets rid of a whole lot of indefensible assumptions
about the behavior of particular operators based on their names ... though
it's still true that IN and NOT IN expand to "= ANY". The patch adds a
RowCompareExpr expression node type, and makes some changes in the
representation of ANY/ALL/ROWCOMPARE SubLinks so that they can share code
with RowCompareExpr.
I have not yet done anything about making RowCompareExpr an indexable
operator, but will look at that soon.
initdb forced due to changes in stored rules.
Diffstat (limited to 'src/backend/nodes')
| -rw-r--r-- | src/backend/nodes/copyfuncs.c | 29 | ||||
| -rw-r--r-- | src/backend/nodes/equalfuncs.c | 25 | ||||
| -rw-r--r-- | src/backend/nodes/outfuncs.c | 24 | ||||
| -rw-r--r-- | src/backend/nodes/readfuncs.c | 25 |
4 files changed, 81 insertions, 22 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 1d816ead3a..7a16cbcff5 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.323 2005/12/20 02:30:35 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.324 2005/12/28 01:29:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -862,10 +862,8 @@ _copySubLink(SubLink *from) SubLink *newnode = makeNode(SubLink); COPY_SCALAR_FIELD(subLinkType); - COPY_SCALAR_FIELD(useOr); - COPY_NODE_FIELD(lefthand); + COPY_NODE_FIELD(testexpr); COPY_NODE_FIELD(operName); - COPY_NODE_FIELD(operOids); COPY_NODE_FIELD(subselect); return newnode; @@ -880,8 +878,7 @@ _copySubPlan(SubPlan *from) SubPlan *newnode = makeNode(SubPlan); COPY_SCALAR_FIELD(subLinkType); - COPY_SCALAR_FIELD(useOr); - COPY_NODE_FIELD(exprs); + COPY_NODE_FIELD(testexpr); COPY_NODE_FIELD(paramIds); COPY_NODE_FIELD(plan); COPY_SCALAR_FIELD(plan_id); @@ -1034,6 +1031,23 @@ _copyRowExpr(RowExpr *from) } /* + * _copyRowCompareExpr + */ +static RowCompareExpr * +_copyRowCompareExpr(RowCompareExpr *from) +{ + RowCompareExpr *newnode = makeNode(RowCompareExpr); + + COPY_SCALAR_FIELD(rctype); + COPY_NODE_FIELD(opnos); + COPY_NODE_FIELD(opclasses); + COPY_NODE_FIELD(largs); + COPY_NODE_FIELD(rargs); + + return newnode; +} + +/* * _copyCoalesceExpr */ static CoalesceExpr * @@ -2876,6 +2890,9 @@ copyObject(void *from) case T_RowExpr: retval = _copyRowExpr(from); break; + case T_RowCompareExpr: + retval = _copyRowCompareExpr(from); + break; case T_CoalesceExpr: retval = _copyCoalesceExpr(from); break; diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 824a7ff82c..b006cec150 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -18,7 +18,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.259 2005/12/20 02:30:35 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.260 2005/12/28 01:29:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -156,6 +156,7 @@ _equalParam(Param *a, Param *b) break; case PARAM_NUM: case PARAM_EXEC: + case PARAM_SUBLINK: COMPARE_SCALAR_FIELD(paramid); break; default: @@ -295,10 +296,8 @@ static bool _equalSubLink(SubLink *a, SubLink *b) { COMPARE_SCALAR_FIELD(subLinkType); - COMPARE_SCALAR_FIELD(useOr); - COMPARE_NODE_FIELD(lefthand); + COMPARE_NODE_FIELD(testexpr); COMPARE_NODE_FIELD(operName); - COMPARE_NODE_FIELD(operOids); COMPARE_NODE_FIELD(subselect); return true; @@ -308,8 +307,7 @@ static bool _equalSubPlan(SubPlan *a, SubPlan *b) { COMPARE_SCALAR_FIELD(subLinkType); - COMPARE_SCALAR_FIELD(useOr); - COMPARE_NODE_FIELD(exprs); + COMPARE_NODE_FIELD(testexpr); COMPARE_NODE_FIELD(paramIds); /* should compare plans, but have to settle for comparing plan IDs */ COMPARE_SCALAR_FIELD(plan_id); @@ -441,6 +439,18 @@ _equalRowExpr(RowExpr *a, RowExpr *b) } static bool +_equalRowCompareExpr(RowCompareExpr *a, RowCompareExpr *b) +{ + COMPARE_SCALAR_FIELD(rctype); + COMPARE_NODE_FIELD(opnos); + COMPARE_NODE_FIELD(opclasses); + COMPARE_NODE_FIELD(largs); + COMPARE_NODE_FIELD(rargs); + + return true; +} + +static bool _equalCoalesceExpr(CoalesceExpr *a, CoalesceExpr *b) { COMPARE_SCALAR_FIELD(coalescetype); @@ -1919,6 +1929,9 @@ equal(void *a, void *b) case T_RowExpr: retval = _equalRowExpr(a, b); break; + case T_RowCompareExpr: + retval = _equalRowCompareExpr(a, b); + break; case T_CoalesceExpr: retval = _equalCoalesceExpr(a, b); break; diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index aa5fd99db8..b60eab31fd 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.265 2005/12/20 02:30:35 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.266 2005/12/28 01:29:59 tgl Exp $ * * NOTES * Every node type that can appear in stored rules' parsetrees *must* @@ -736,10 +736,8 @@ _outSubLink(StringInfo str, SubLink *node) WRITE_NODE_TYPE("SUBLINK"); WRITE_ENUM_FIELD(subLinkType, SubLinkType); - WRITE_BOOL_FIELD(useOr); - WRITE_NODE_FIELD(lefthand); + WRITE_NODE_FIELD(testexpr); WRITE_NODE_FIELD(operName); - WRITE_NODE_FIELD(operOids); WRITE_NODE_FIELD(subselect); } @@ -749,8 +747,7 @@ _outSubPlan(StringInfo str, SubPlan *node) WRITE_NODE_TYPE("SUBPLAN"); WRITE_ENUM_FIELD(subLinkType, SubLinkType); - WRITE_BOOL_FIELD(useOr); - WRITE_NODE_FIELD(exprs); + WRITE_NODE_FIELD(testexpr); WRITE_NODE_FIELD(paramIds); WRITE_NODE_FIELD(plan); WRITE_INT_FIELD(plan_id); @@ -856,6 +853,18 @@ _outRowExpr(StringInfo str, RowExpr *node) } static void +_outRowCompareExpr(StringInfo str, RowCompareExpr *node) +{ + WRITE_NODE_TYPE("ROWCOMPARE"); + + WRITE_ENUM_FIELD(rctype, RowCompareType); + WRITE_NODE_FIELD(opnos); + WRITE_NODE_FIELD(opclasses); + WRITE_NODE_FIELD(largs); + WRITE_NODE_FIELD(rargs); +} + +static void _outCoalesceExpr(StringInfo str, CoalesceExpr *node) { WRITE_NODE_TYPE("COALESCE"); @@ -1936,6 +1945,9 @@ _outNode(StringInfo str, void *obj) case T_RowExpr: _outRowExpr(str, obj); break; + case T_RowCompareExpr: + _outRowCompareExpr(str, obj); + break; case T_CoalesceExpr: _outCoalesceExpr(str, obj); break; diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 46c9983446..eb2886d843 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.182 2005/10/15 02:49:19 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.183 2005/12/28 01:29:59 tgl Exp $ * * NOTES * Path and Plan nodes do not have any readfuncs support, because we @@ -494,10 +494,8 @@ _readSubLink(void) READ_LOCALS(SubLink); READ_ENUM_FIELD(subLinkType, SubLinkType); - READ_BOOL_FIELD(useOr); - READ_NODE_FIELD(lefthand); + READ_NODE_FIELD(testexpr); READ_NODE_FIELD(operName); - READ_NODE_FIELD(operOids); READ_NODE_FIELD(subselect); READ_DONE(); @@ -646,6 +644,23 @@ _readRowExpr(void) } /* + * _readRowCompareExpr + */ +static RowCompareExpr * +_readRowCompareExpr(void) +{ + READ_LOCALS(RowCompareExpr); + + READ_ENUM_FIELD(rctype, RowCompareType); + READ_NODE_FIELD(opnos); + READ_NODE_FIELD(opclasses); + READ_NODE_FIELD(largs); + READ_NODE_FIELD(rargs); + + READ_DONE(); +} + +/* * _readCoalesceExpr */ static CoalesceExpr * @@ -996,6 +1011,8 @@ parseNodeString(void) return_value = _readArrayExpr(); else if (MATCH("ROW", 3)) return_value = _readRowExpr(); + else if (MATCH("ROWCOMPARE", 10)) + return_value = _readRowCompareExpr(); else if (MATCH("COALESCE", 8)) return_value = _readCoalesceExpr(); else if (MATCH("MINMAX", 6)) |
