mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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.
This commit is contained in:
@ -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);
|
||||
@ -1033,6 +1030,23 @@ _copyRowExpr(RowExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _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
|
||||
*/
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
@ -440,6 +438,18 @@ _equalRowExpr(RowExpr *a, RowExpr *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
@ -855,6 +852,18 @@ _outRowExpr(StringInfo str, RowExpr *node)
|
||||
WRITE_ENUM_FIELD(row_format, CoercionForm);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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;
|
||||
|
@ -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();
|
||||
@ -645,6 +643,23 @@ _readRowExpr(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _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
|
||||
*/
|
||||
@ -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))
|
||||
|
Reference in New Issue
Block a user