1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-22 21:53:06 +03:00

Finished the Between patch Christopher started.

Implements between (symmetric / asymmetric) as a node.

Executes the left or right expression once, makes a Const out of the
resulting Datum and executes the >=, <= portions out of the Const sets.

Of course, the parser does a fair amount of preparatory work for this to
happen.

Rod Taylor
This commit is contained in:
Bruce Momjian
2002-07-18 04:41:46 +00:00
parent 7ea5f1d7f1
commit 3e22406ec6
15 changed files with 619 additions and 35 deletions

View File

@@ -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.194 2002/07/16 22:12:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.195 2002/07/18 04:41:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -999,6 +999,32 @@ _copyCaseExpr(CaseExpr *from)
return newnode;
}
/* ----------------
* _copyBetweenExpr
* ----------------
*/
static BetweenExpr *
_copyBetweenExpr(BetweenExpr *from)
{
BetweenExpr *newnode = makeNode(BetweenExpr);
/*
* copy remainder of node
*/
Node_Copy(from, newnode, expr);
Node_Copy(from, newnode, lexpr);
Node_Copy(from, newnode, rexpr);
Node_Copy(from, newnode, lthan);
Node_Copy(from, newnode, gthan);
newnode->symmetric = from->symmetric;
newnode->not = from->not;
newnode->typeId = from->typeId;
newnode->typeLen = from->typeLen;
newnode->typeByVal = from->typeByVal;
return newnode;
}
/* ----------------
* _copyCaseWhen
* ----------------
@@ -3052,6 +3078,9 @@ copyObject(void *from)
case T_CaseExpr:
retval = _copyCaseExpr(from);
break;
case T_BetweenExpr:
retval = _copyBetweenExpr(from);
break;
case T_CaseWhen:
retval = _copyCaseWhen(from);
break;

View File

@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.141 2002/07/16 22:12:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.142 2002/07/18 04:41:44 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1769,6 +1769,33 @@ _equalCaseExpr(CaseExpr *a, CaseExpr *b)
return true;
}
static bool
_equalBetweenExpr(BetweenExpr *a, BetweenExpr *b)
{
if (!equal(a->expr, b->expr))
return false;
if (!equal(a->lexpr, b->lexpr))
return false;
if (!equal(a->rexpr, b->rexpr))
return false;
if (!equal(a->lthan, b->lthan))
return false;
if (!equal(a->gthan, b->gthan))
return false;
if (a->symmetric != b->symmetric)
return false;
if (a->not != b->not)
return false;
if (a->typeId != b->typeId)
return false;
if (a->typeLen != b->typeLen)
return false;
if (a->typeByVal != b->typeByVal)
return false;
return true;
}
static bool
_equalCaseWhen(CaseWhen *a, CaseWhen *b)
{
@@ -2217,6 +2244,9 @@ equal(void *a, void *b)
case T_CaseExpr:
retval = _equalCaseExpr(a, b);
break;
case T_BetweenExpr:
retval = _equalBetweenExpr(a, b);
break;
case T_CaseWhen:
retval = _equalCaseWhen(a, b);
break;

View File

@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.163 2002/07/16 22:12:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.164 2002/07/18 04:41:44 momjian Exp $
*
* NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -1483,6 +1483,38 @@ _outCaseWhen(StringInfo str, CaseWhen *node)
_outNode(str, node->result);
}
/*
* BetweenExpr
*/
static void
_outBetweenExpr(StringInfo str, BetweenExpr *node)
{
appendStringInfo(str, " BETWEENEXPR :expr ");
_outNode(str, node->expr);
appendStringInfo(str, " :not %s",
booltostr(node->not));
appendStringInfo(str, " :symmetric %s",
booltostr(node->symmetric));
appendStringInfo(str, " :lexpr ");
_outNode(str, node->lexpr);
appendStringInfo(str, " :rexpr ");
_outNode(str, node->rexpr);
appendStringInfo(str, " :gthan ");
_outNode(str, node->gthan);
appendStringInfo(str, " :lthan ");
_outNode(str, node->lthan);
appendStringInfo(str, " :typeid %u :typelen %d :typebyval %s",
node->typeId, node->typeLen,
booltostr(node->typeByVal));
}
/*
* NullTest
*/
@@ -1767,6 +1799,9 @@ _outNode(StringInfo str, void *obj)
case T_CaseExpr:
_outCaseExpr(str, obj);
break;
case T_BetweenExpr:
_outBetweenExpr(str, obj);
break;
case T_CaseWhen:
_outCaseWhen(str, obj);
break;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.124 2002/07/04 15:23:54 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.125 2002/07/18 04:41:45 momjian Exp $
*
* NOTES
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -881,6 +881,53 @@ _readCaseWhen(void)
return local_node;
}
static BetweenExpr *
_readBetweenExpr(void)
{
BetweenExpr *local_node;
char *token;
int length;
local_node = makeNode(BetweenExpr);
token = pg_strtok(&length); /* eat :expr */
local_node->expr = nodeRead(true);
token = pg_strtok(&length); /* eat :not */
token = pg_strtok(&length); /* get not */
local_node->not = strtobool(token);
token = pg_strtok(&length); /* eat :symmetric */
token = pg_strtok(&length); /* get symmetric */
local_node->symmetric = strtobool(token);
token = pg_strtok(&length); /* eat :lexpr */
local_node->lexpr = nodeRead(true);
token = pg_strtok(&length); /* eat :rexpr */
local_node->rexpr = nodeRead(true);
token = pg_strtok(&length); /* eat :gthan */
local_node->gthan = nodeRead(true);
token = pg_strtok(&length); /* eat :lthan */
local_node->lthan = nodeRead(true);
token = pg_strtok(&length); /* eat :typeid */
token = pg_strtok(&length); /* get typeid */
local_node->typeId = atooid(token);
token = pg_strtok(&length); /* eat :typelen */
token = pg_strtok(&length); /* get typelen */
local_node->typeLen = atoui(token);
token = pg_strtok(&length); /* eat :typebyval */
token = pg_strtok(&length); /* get typebyval */
local_node->typeByVal = strtobool(token);
return local_node;
}
/* ----------------
* _readNullTest
*
@@ -2132,6 +2179,8 @@ parsePlanString(void)
return_value = _readNullTest();
else if (length == 11 && strncmp(token, "BOOLEANTEST", length) == 0)
return_value = _readBooleanTest();
else if (length == 11 && strncmp(token, "BETWEENEXPR", length) == 0)
return_value = _readBetweenExpr();
else
elog(ERROR, "badly formatted planstring \"%.10s\"...", token);