mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Provide tunable knob for x = NULL -> x IS NULL transformation, default to off.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.251 2001/09/18 01:59:06 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.252 2001/09/20 14:20:27 petere Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -89,7 +89,6 @@ static void insertSelectOptions(SelectStmt *stmt,
|
||||
List *sortClause, List *forUpdate,
|
||||
Node *limitOffset, Node *limitCount);
|
||||
static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
|
||||
static bool exprIsNullConstant(Node *arg);
|
||||
static Node *doNegate(Node *n);
|
||||
static void doNegateFloat(Value *v);
|
||||
|
||||
@@ -4465,29 +4464,7 @@ a_expr: c_expr
|
||||
| a_expr '>' a_expr
|
||||
{ $$ = makeA_Expr(OP, ">", $1, $3); }
|
||||
| a_expr '=' a_expr
|
||||
{
|
||||
/*
|
||||
* Special-case "foo = NULL" and "NULL = foo" for
|
||||
* compatibility with standards-broken products
|
||||
* (like Microsoft's). Turn these into IS NULL exprs.
|
||||
*/
|
||||
if (exprIsNullConstant($3))
|
||||
{
|
||||
NullTest *n = makeNode(NullTest);
|
||||
n->arg = $1;
|
||||
n->nulltesttype = IS_NULL;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
else if (exprIsNullConstant($1))
|
||||
{
|
||||
NullTest *n = makeNode(NullTest);
|
||||
n->arg = $3;
|
||||
n->nulltesttype = IS_NULL;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
else
|
||||
$$ = makeA_Expr(OP, "=", $1, $3);
|
||||
}
|
||||
{ $$ = makeA_Expr(OP, "=", $1, $3); }
|
||||
|
||||
| a_expr Op a_expr
|
||||
{ $$ = makeA_Expr(OP, $2, $1, $3); }
|
||||
@@ -6137,7 +6114,7 @@ Oid param_type(int t)
|
||||
/*
|
||||
* Test whether an a_expr is a plain NULL constant or not.
|
||||
*/
|
||||
static bool
|
||||
bool
|
||||
exprIsNullConstant(Node *arg)
|
||||
{
|
||||
if (arg && IsA(arg, A_Const))
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.99 2001/08/09 18:28:17 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.100 2001/09/20 14:20:27 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,9 +34,10 @@
|
||||
|
||||
|
||||
int max_expr_depth = DEFAULT_MAX_EXPR_DEPTH;
|
||||
|
||||
static int expr_depth_counter = 0;
|
||||
|
||||
bool Transform_null_equals = false;
|
||||
|
||||
static Node *parser_typecast_constant(Value *expr, TypeName *typename);
|
||||
static Node *parser_typecast_expression(ParseState *pstate,
|
||||
Node *expr, TypeName *typename);
|
||||
@@ -157,14 +158,35 @@ transformExpr(ParseState *pstate, Node *expr, int precedence)
|
||||
{
|
||||
case OP:
|
||||
{
|
||||
Node *lexpr = transformExpr(pstate,
|
||||
a->lexpr,
|
||||
precedence);
|
||||
Node *rexpr = transformExpr(pstate,
|
||||
a->rexpr,
|
||||
precedence);
|
||||
/*
|
||||
* Special-case "foo = NULL" and "NULL = foo" for
|
||||
* compatibility with standards-broken products
|
||||
* (like Microsoft's). Turn these into IS NULL exprs.
|
||||
*/
|
||||
if (Transform_null_equals && strcmp(a->opname, "=")==0
|
||||
&& (exprIsNullConstant(a->lexpr) || exprIsNullConstant(a->rexpr)))
|
||||
{
|
||||
NullTest *n = makeNode(NullTest);
|
||||
n->nulltesttype = IS_NULL;
|
||||
|
||||
result = (Node *) make_op(a->opname, lexpr, rexpr);
|
||||
if (exprIsNullConstant(a->lexpr))
|
||||
n->arg = a->rexpr;
|
||||
else
|
||||
n->arg = a->lexpr;
|
||||
|
||||
result = transformExpr(pstate, n, precedence);
|
||||
}
|
||||
else
|
||||
{
|
||||
Node *lexpr = transformExpr(pstate,
|
||||
a->lexpr,
|
||||
precedence);
|
||||
Node *rexpr = transformExpr(pstate,
|
||||
a->rexpr,
|
||||
precedence);
|
||||
|
||||
result = (Node *) make_op(a->opname, lexpr, rexpr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AND:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Support for grand unified configuration scheme, including SET
|
||||
* command, configuration file, and command line options.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.48 2001/09/12 14:06:37 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.49 2001/09/20 14:20:27 petere Exp $
|
||||
*
|
||||
* Copyright 2000 by PostgreSQL Global Development Group
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
@@ -247,12 +247,10 @@ static struct config_bool
|
||||
{"show_source_port", PGC_SIGHUP, &ShowPortNumber, false, NULL},
|
||||
|
||||
{"sql_inheritance", PGC_USERSET, &SQL_inheritance, true, NULL},
|
||||
|
||||
{"australian_timezones", PGC_USERSET, &Australian_timezones, false, ClearDateCache},
|
||||
|
||||
{"fixbtree", PGC_POSTMASTER, &FixBTree, true, NULL},
|
||||
|
||||
{"password_encryption", PGC_USERSET, &Password_encryption, false, NULL},
|
||||
{"transform_null_equals", PGC_USERSET, &Transform_null_equals, false, NULL},
|
||||
|
||||
{NULL, 0, NULL, false, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user