mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Support expressions of the form 'scalar op ANY (array)' and
'scalar op ALL (array)', where the operator is applied between the lefthand scalar and each element of the array. The operator must yield boolean; the result of the construct is the OR or AND of the per-element results, respectively. Original coding by Joe Conway, after an idea of Peter's. Rewritten by Tom to keep the implementation strictly separate from subqueries.
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.257 2003/06/27 14:45:28 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.258 2003/06/29 00:33:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -802,6 +802,22 @@ _copyDistinctExpr(DistinctExpr *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyScalarArrayOpExpr
|
||||
*/
|
||||
static ScalarArrayOpExpr *
|
||||
_copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
|
||||
{
|
||||
ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
|
||||
|
||||
COPY_SCALAR_FIELD(opno);
|
||||
COPY_SCALAR_FIELD(opfuncid);
|
||||
COPY_SCALAR_FIELD(useOr);
|
||||
COPY_NODE_FIELD(args);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyBoolExpr
|
||||
*/
|
||||
@@ -2546,6 +2562,9 @@ copyObject(void *from)
|
||||
case T_DistinctExpr:
|
||||
retval = _copyDistinctExpr(from);
|
||||
break;
|
||||
case T_ScalarArrayOpExpr:
|
||||
retval = _copyScalarArrayOpExpr(from);
|
||||
break;
|
||||
case T_BoolExpr:
|
||||
retval = _copyBoolExpr(from);
|
||||
break;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.200 2003/06/27 14:45:28 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.201 2003/06/29 00:33:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -287,6 +287,27 @@ _equalDistinctExpr(DistinctExpr *a, DistinctExpr *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalScalarArrayOpExpr(ScalarArrayOpExpr *a, ScalarArrayOpExpr *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(opno);
|
||||
/*
|
||||
* Special-case opfuncid: it is allowable for it to differ if one
|
||||
* node contains zero and the other doesn't. This just means that the
|
||||
* one node isn't as far along in the parse/plan pipeline and hasn't
|
||||
* had the opfuncid cache filled yet.
|
||||
*/
|
||||
if (a->opfuncid != b->opfuncid &&
|
||||
a->opfuncid != 0 &&
|
||||
b->opfuncid != 0)
|
||||
return false;
|
||||
|
||||
COMPARE_SCALAR_FIELD(useOr);
|
||||
COMPARE_NODE_FIELD(args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalBoolExpr(BoolExpr *a, BoolExpr *b)
|
||||
{
|
||||
@@ -1661,6 +1682,9 @@ equal(void *a, void *b)
|
||||
case T_DistinctExpr:
|
||||
retval = _equalDistinctExpr(a, b);
|
||||
break;
|
||||
case T_ScalarArrayOpExpr:
|
||||
retval = _equalScalarArrayOpExpr(a, b);
|
||||
break;
|
||||
case T_BoolExpr:
|
||||
retval = _equalBoolExpr(a, b);
|
||||
break;
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.21 2002/12/13 19:45:56 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/nodeFuncs.c,v 1.22 2003/06/29 00:33:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "nodes/nodeFuncs.h"
|
||||
#include "utils/lsyscache.h"
|
||||
|
||||
|
||||
static bool var_is_inner(Var *var);
|
||||
|
||||
@@ -72,20 +72,3 @@ var_is_rel(Var *var)
|
||||
return (bool)
|
||||
!(var_is_inner(var) || var_is_outer(var));
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* OPER nodes
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* set_opfuncid -
|
||||
*
|
||||
* Set the opfuncid (procedure OID) in an OpExpr node,
|
||||
* if it hasn't been set already.
|
||||
*/
|
||||
void
|
||||
set_opfuncid(OpExpr *opexpr)
|
||||
{
|
||||
if (opexpr->opfuncid == InvalidOid)
|
||||
opexpr->opfuncid = get_opcode(opexpr->opno);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.210 2003/06/25 21:30:29 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.211 2003/06/29 00:33:43 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@@ -668,6 +668,17 @@ _outDistinctExpr(StringInfo str, DistinctExpr *node)
|
||||
WRITE_NODE_FIELD(args);
|
||||
}
|
||||
|
||||
static void
|
||||
_outScalarArrayOpExpr(StringInfo str, ScalarArrayOpExpr *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("SCALARARRAYOPEXPR");
|
||||
|
||||
WRITE_OID_FIELD(opno);
|
||||
WRITE_OID_FIELD(opfuncid);
|
||||
WRITE_BOOL_FIELD(useOr);
|
||||
WRITE_NODE_FIELD(args);
|
||||
}
|
||||
|
||||
static void
|
||||
_outBoolExpr(StringInfo str, BoolExpr *node)
|
||||
{
|
||||
@@ -1333,6 +1344,16 @@ _outAExpr(StringInfo str, A_Expr *node)
|
||||
case AEXPR_NOT:
|
||||
appendStringInfo(str, " NOT");
|
||||
break;
|
||||
case AEXPR_OP_ANY:
|
||||
appendStringInfo(str, " ");
|
||||
WRITE_NODE_FIELD(name);
|
||||
appendStringInfo(str, " ANY ");
|
||||
break;
|
||||
case AEXPR_OP_ALL:
|
||||
appendStringInfo(str, " ");
|
||||
WRITE_NODE_FIELD(name);
|
||||
appendStringInfo(str, " ALL ");
|
||||
break;
|
||||
case AEXPR_DISTINCT:
|
||||
appendStringInfo(str, " DISTINCT ");
|
||||
WRITE_NODE_FIELD(name);
|
||||
@@ -1619,6 +1640,9 @@ _outNode(StringInfo str, void *obj)
|
||||
case T_DistinctExpr:
|
||||
_outDistinctExpr(str, obj);
|
||||
break;
|
||||
case T_ScalarArrayOpExpr:
|
||||
_outScalarArrayOpExpr(str, obj);
|
||||
break;
|
||||
case T_BoolExpr:
|
||||
_outBoolExpr(str, obj);
|
||||
break;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.156 2003/06/25 21:30:30 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.157 2003/06/29 00:33:43 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@@ -510,6 +510,32 @@ _readDistinctExpr(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readScalarArrayOpExpr
|
||||
*/
|
||||
static ScalarArrayOpExpr *
|
||||
_readScalarArrayOpExpr(void)
|
||||
{
|
||||
READ_LOCALS(ScalarArrayOpExpr);
|
||||
|
||||
READ_OID_FIELD(opno);
|
||||
READ_OID_FIELD(opfuncid);
|
||||
/*
|
||||
* The opfuncid is stored in the textual format primarily for debugging
|
||||
* and documentation reasons. We want to always read it as zero to force
|
||||
* it to be re-looked-up in the pg_operator entry. This ensures that
|
||||
* stored rules don't have hidden dependencies on operators' functions.
|
||||
* (We don't currently support an ALTER OPERATOR command, but might
|
||||
* someday.)
|
||||
*/
|
||||
local_node->opfuncid = InvalidOid;
|
||||
|
||||
READ_BOOL_FIELD(useOr);
|
||||
READ_NODE_FIELD(args);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readBoolExpr
|
||||
*/
|
||||
@@ -951,6 +977,8 @@ parseNodeString(void)
|
||||
return_value = _readOpExpr();
|
||||
else if (MATCH("DISTINCTEXPR", 12))
|
||||
return_value = _readDistinctExpr();
|
||||
else if (MATCH("SCALARARRAYOPEXPR", 17))
|
||||
return_value = _readScalarArrayOpExpr();
|
||||
else if (MATCH("BOOLEXPR", 8))
|
||||
return_value = _readBoolExpr();
|
||||
else if (MATCH("SUBLINK", 7))
|
||||
|
||||
Reference in New Issue
Block a user