Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
269755ef
Commit
269755ef
authored
Nov 28, 2011
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pgindent clauses.c, per request from Tom.
parent
a04161f2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
924 additions
and
889 deletions
+924
-889
src/backend/optimizer/util/clauses.c
src/backend/optimizer/util/clauses.c
+924
-889
No files found.
src/backend/optimizer/util/clauses.c
View file @
269755ef
...
...
@@ -2126,10 +2126,10 @@ eval_const_expressions_mutator(Node *node,
if
(
context
->
estimate
||
(
prm
->
pflags
&
PARAM_FLAG_CONST
))
{
/*
* Return a Const representing the param value. Must copy
* pass-by-ref datatypes, since the Param might be in a
* memory context shorter-lived than our output plan
*
should be.
* Return a Const representing the param value.
* Must copy pass-by-ref datatypes, since the
* Param might be in a memory context
* shorter-lived than our output plan
should be.
*/
int16
typLen
;
bool
typByVal
;
...
...
@@ -2151,7 +2151,11 @@ eval_const_expressions_mutator(Node *node,
}
}
}
/* Not replaceable, so just copy the Param (no need to recurse) */
/*
* Not replaceable, so just copy the Param (no need to
* recurse)
*/
return
(
Node
*
)
copyObject
(
param
);
}
case
T_FuncExpr
:
...
...
@@ -2164,8 +2168,8 @@ eval_const_expressions_mutator(Node *node,
ListCell
*
lc
;
/*
* Reduce constants in the FuncExpr's arguments, and check to see if
*
there are any named args.
* Reduce constants in the FuncExpr's arguments, and check to
* see if
there are any named args.
*/
args
=
NIL
;
has_named_args
=
false
;
...
...
@@ -2180,10 +2184,11 @@ eval_const_expressions_mutator(Node *node,
}
/*
* Code for op/func reduction is pretty bulky, so split it out as a
* separate function. Note: exprTypmod normally returns -1 for a
* FuncExpr, but not when the node is recognizably a length coercion;
* we want to preserve the typmod in the eventual Const if so.
* Code for op/func reduction is pretty bulky, so split it out
* as a separate function. Note: exprTypmod normally returns
* -1 for a FuncExpr, but not when the node is recognizably a
* length coercion; we want to preserve the typmod in the
* eventual Const if so.
*/
simple
=
simplify_function
((
Expr
*
)
expr
,
expr
->
funcid
,
...
...
@@ -2196,10 +2201,10 @@ eval_const_expressions_mutator(Node *node,
return
(
Node
*
)
simple
;
/*
* The expression cannot be simplified any further, so build an
d
* return a replacement FuncExpr node using the possibly-simplified
* arguments. Note that we have also converted the argument list t
o
*
positional notation.
* The expression cannot be simplified any further, so buil
d
* and return a replacement FuncExpr node using the
* possibly-simplified arguments. Note that we have als
o
* converted the argument list to
positional notation.
*/
newexpr
=
makeNode
(
FuncExpr
);
newexpr
->
funcid
=
expr
->
funcid
;
...
...
@@ -2220,23 +2225,24 @@ eval_const_expressions_mutator(Node *node,
OpExpr
*
newexpr
;
/*
* Reduce constants in the OpExpr's arguments. We know args is either
* NIL or a List node, so we can call expression_tree_mutator directly
* rather than recursing to self.
* Reduce constants in the OpExpr's arguments. We know args
* is either NIL or a List node, so we can call
* expression_tree_mutator directly rather than recursing to
* self.
*/
args
=
(
List
*
)
expression_tree_mutator
((
Node
*
)
expr
->
args
,
eval_const_expressions_mutator
,
(
void
*
)
context
);
/*
* Need to get OID of underlying function. Okay to scribble on input
*
to this extent.
* Need to get OID of underlying function. Okay to scribble
* on input
to this extent.
*/
set_opfuncid
(
expr
);
/*
* Code for op/func reduction is pretty bulky, so split it out as a
*
separate function.
* Code for op/func reduction is pretty bulky, so split it out
* as a
separate function.
*/
simple
=
simplify_function
((
Expr
*
)
expr
,
expr
->
opfuncid
,
...
...
@@ -2249,9 +2255,9 @@ eval_const_expressions_mutator(Node *node,
return
(
Node
*
)
simple
;
/*
* If the operator is boolean equality or inequality, we know how to
* simplify cases involving one constant and one non-constant
*
argument.
* If the operator is boolean equality or inequality, we know
* how to simplify cases involving one constant and one
* non-constant
argument.
*/
if
(
expr
->
opno
==
BooleanEqualOperator
||
expr
->
opno
==
BooleanNotEqualOperator
)
...
...
@@ -2262,9 +2268,9 @@ eval_const_expressions_mutator(Node *node,
}
/*
* The expression cannot be simplified any further, so build an
d
* return a replacement OpExpr node using the possibly-simplified
*
arguments.
* The expression cannot be simplified any further, so buil
d
* and return a replacement OpExpr node using the
* possibly-simplified
arguments.
*/
newexpr
=
makeNode
(
OpExpr
);
newexpr
->
opno
=
expr
->
opno
;
...
...
@@ -2289,9 +2295,10 @@ eval_const_expressions_mutator(Node *node,
DistinctExpr
*
newexpr
;
/*
* Reduce constants in the DistinctExpr's arguments. We know args is
* either NIL or a List node, so we can call expression_tree_mutator
* directly rather than recursing to self.
* Reduce constants in the DistinctExpr's arguments. We know
* args is either NIL or a List node, so we can call
* expression_tree_mutator directly rather than recursing to
* self.
*/
args
=
(
List
*
)
expression_tree_mutator
((
Node
*
)
expr
->
args
,
eval_const_expressions_mutator
,
...
...
@@ -2299,7 +2306,8 @@ eval_const_expressions_mutator(Node *node,
/*
* We must do our own check for NULLs because DistinctExpr has
* different results for NULL input than the underlying operator does.
* different results for NULL input than the underlying
* operator does.
*/
foreach
(
arg
,
args
)
{
...
...
@@ -2327,14 +2335,15 @@ eval_const_expressions_mutator(Node *node,
/* (NOT okay to try to inline it, though!) */
/*
* Need to get OID of underlying function. Okay to scribble on
*
input to this extent.
* Need to get OID of underlying function. Okay to
* scribble on
input to this extent.
*/
set_opfuncid
((
OpExpr
*
)
expr
);
/* rely on struct equivalence */
set_opfuncid
((
OpExpr
*
)
expr
);
/* rely on struct
* equivalence */
/*
* Code for op/func reduction is pretty bulky, so split it out as
*
a separate function.
* Code for op/func reduction is pretty bulky, so split it
* out as
a separate function.
*/
simple
=
simplify_function
((
Expr
*
)
expr
,
expr
->
opfuncid
,
...
...
@@ -2346,8 +2355,8 @@ eval_const_expressions_mutator(Node *node,
if
(
simple
)
/* successfully simplified it */
{
/*
* Since the underlying operator is "=", must negate its
*
result
* Since the underlying operator is "=", must negate
* its
result
*/
Const
*
csimple
=
(
Const
*
)
simple
;
...
...
@@ -2359,8 +2368,8 @@ eval_const_expressions_mutator(Node *node,
}
/*
* The expression cannot be simplified any further, so build an
d
*
return a replacement DistinctExpr node using the
* The expression cannot be simplified any further, so buil
d
* and
return a replacement DistinctExpr node using the
* possibly-simplified arguments.
*/
newexpr
=
makeNode
(
DistinctExpr
);
...
...
@@ -2395,7 +2404,11 @@ eval_const_expressions_mutator(Node *node,
/* If all the inputs are FALSE, result is FALSE */
if
(
newargs
==
NIL
)
return
makeBoolConst
(
false
,
false
);
/* If only one nonconst-or-NULL input, it's the result */
/*
* If only one nonconst-or-NULL input, it's the
* result
*/
if
(
list_length
(
newargs
)
==
1
)
return
(
Node
*
)
linitial
(
newargs
);
/* Else we still need an OR node */
...
...
@@ -2416,7 +2429,11 @@ eval_const_expressions_mutator(Node *node,
/* If all the inputs are TRUE, result is TRUE */
if
(
newargs
==
NIL
)
return
makeBoolConst
(
true
,
false
);
/* If only one nonconst-or-NULL input, it's the result */
/*
* If only one nonconst-or-NULL input, it's the
* result
*/
if
(
list_length
(
newargs
)
==
1
)
return
(
Node
*
)
linitial
(
newargs
);
/* Else we still need an AND node */
...
...
@@ -2431,8 +2448,8 @@ eval_const_expressions_mutator(Node *node,
context
);
/*
* Use negate_clause() to see if we can simplify away the
*
NOT.
* Use negate_clause() to see if we can simplify
* away the
NOT.
*/
return
negate_clause
(
arg
);
}
...
...
@@ -2445,19 +2462,21 @@ eval_const_expressions_mutator(Node *node,
}
case
T_SubPlan
:
case
T_AlternativeSubPlan
:
/*
* Return a SubPlan unchanged --- too late to do anything with it.
*
* XXX should we ereport() here instead? Probably this routine should
*
never be invoked after SubPlan creation.
* XXX should we ereport() here instead? Probably this routine
* should
never be invoked after SubPlan creation.
*/
return
node
;
case
T_RelabelType
:
{
/*
* If we can simplify the input to a constant, then we don't need the
* RelabelType node anymore: just change the type field of the Const
* node. Otherwise, must copy the RelabelType node.
* If we can simplify the input to a constant, then we don't
* need the RelabelType node anymore: just change the type
* field of the Const node. Otherwise, must copy the
* RelabelType node.
*/
RelabelType
*
relabel
=
(
RelabelType
*
)
node
;
Node
*
arg
;
...
...
@@ -2466,8 +2485,8 @@ eval_const_expressions_mutator(Node *node,
context
);
/*
* If we find stacked RelabelTypes (eg, from foo :: int :: oid) we can
*
discard all but the top one.
* If we find stacked RelabelTypes (eg, from foo :: int ::
* oid) we can
discard all but the top one.
*/
while
(
arg
&&
IsA
(
arg
,
RelabelType
))
arg
=
(
Node
*
)
((
RelabelType
*
)
arg
)
->
arg
;
...
...
@@ -2514,13 +2533,13 @@ eval_const_expressions_mutator(Node *node,
args
=
list_make1
(
arg
);
/*
* CoerceViaIO represents calling the source type's output function
* then the result type's input function. So, try to simplify it as
* though it were a stack of two such function calls. First we need
*
to know what the functions are.
* CoerceViaIO represents calling the source type's output
* function then the result type's input function. So, try to
* simplify it as though it were a stack of two such function
* calls. First we need
to know what the functions are.
*
* Note that the coercion functions are assumed not to care about
*
input collation, so we just pass InvalidOid for that.
* Note that the coercion functions are assumed not to care
* about
input collation, so we just pass InvalidOid for that.
*/
getTypeOutputInfo
(
exprType
((
Node
*
)
arg
),
&
outfunc
,
&
outtypisvarlena
);
getTypeInputInfo
(
expr
->
resulttype
,
&
infunc
,
&
intypioparam
);
...
...
@@ -2535,8 +2554,9 @@ eval_const_expressions_mutator(Node *node,
if
(
simple
)
/* successfully simplified output fn */
{
/*
* Input functions may want 1 to 3 arguments. We always supply
* all three, trusting that nothing downstream will complain.
* Input functions may want 1 to 3 arguments. We always
* supply all three, trusting that nothing downstream will
* complain.
*/
args
=
list_make3
(
simple
,
makeConst
(
OIDOID
,
-
1
,
InvalidOid
,
sizeof
(
Oid
),
...
...
@@ -2558,9 +2578,9 @@ eval_const_expressions_mutator(Node *node,
}
/*
* The expression cannot be simplified any further, so build an
d
* return a replacement CoerceViaIO node using the possibly-simplified
*
argument.
* The expression cannot be simplified any further, so buil
d
* and return a replacement CoerceViaIO node using the
* possibly-simplified
argument.
*/
newexpr
=
makeNode
(
CoerceViaIO
);
newexpr
->
arg
=
arg
;
...
...
@@ -2577,8 +2597,8 @@ eval_const_expressions_mutator(Node *node,
ArrayCoerceExpr
*
newexpr
;
/*
* Reduce constants in the ArrayCoerceExpr's argument, then build a
*
new ArrayCoerceExpr.
* Reduce constants in the ArrayCoerceExpr's argument, then
* build a
new ArrayCoerceExpr.
*/
arg
=
(
Expr
*
)
eval_const_expressions_mutator
((
Node
*
)
expr
->
arg
,
context
);
...
...
@@ -2594,8 +2614,8 @@ eval_const_expressions_mutator(Node *node,
newexpr
->
location
=
expr
->
location
;
/*
* If constant argument and it's a binary-coercible or immutable
*
conversion, we can simplify it to a constant.
* If constant argument and it's a binary-coercible or
* immutable
conversion, we can simplify it to a constant.
*/
if
(
arg
&&
IsA
(
arg
,
Const
)
&&
(
!
OidIsValid
(
newexpr
->
elemfuncid
)
||
...
...
@@ -2611,11 +2631,12 @@ eval_const_expressions_mutator(Node *node,
case
T_CollateExpr
:
{
/*
* If we can simplify the input to a constant, then we don't need the
* CollateExpr node at all: just change the constcollid field of the
* Const node. Otherwise, replace the CollateExpr with a RelabelType.
* (We do that so as to improve uniformity of expression
* representation and thus simplify comparison of expressions.)
* If we can simplify the input to a constant, then we don't
* need the CollateExpr node at all: just change the
* constcollid field of the Const node. Otherwise, replace
* the CollateExpr with a RelabelType. (We do that so as to
* improve uniformity of expression representation and thus
* simplify comparison of expressions.)
*/
CollateExpr
*
collate
=
(
CollateExpr
*
)
node
;
Node
*
arg
;
...
...
@@ -2702,7 +2723,8 @@ eval_const_expressions_mutator(Node *node,
if
(
newarg
&&
IsA
(
newarg
,
Const
))
{
context
->
case_val
=
newarg
;
newarg
=
NULL
;
/* not needed anymore, see comment above */
newarg
=
NULL
;
/* not needed anymore, see comment
* above */
}
else
context
->
case_val
=
NULL
;
...
...
@@ -2724,8 +2746,9 @@ eval_const_expressions_mutator(Node *node,
context
);
/*
* If the test condition is constant FALSE (or NULL), then drop
* this WHEN clause completely, without processing the result.
* If the test condition is constant FALSE (or NULL), then
* drop this WHEN clause completely, without processing
* the result.
*/
if
(
casecond
&&
IsA
(
casecond
,
Const
))
{
...
...
@@ -2733,7 +2756,8 @@ eval_const_expressions_mutator(Node *node,
if
(
const_input
->
constisnull
||
!
DatumGetBool
(
const_input
->
constvalue
))
continue
;
/* drop alternative with FALSE condition */
continue
;
/* drop alternative with FALSE
* condition */
/* Else it's constant TRUE */
const_true_cond
=
true
;
}
...
...
@@ -2756,8 +2780,9 @@ eval_const_expressions_mutator(Node *node,
}
/*
* Found a TRUE condition, so none of the remaining alternatives
* can be reached. We treat the result as the default result.
* Found a TRUE condition, so none of the remaining
* alternatives can be reached. We treat the result as
* the default result.
*/
defresult
=
caseresult
;
break
;
...
...
@@ -2771,7 +2796,10 @@ eval_const_expressions_mutator(Node *node,
context
->
case_val
=
save_case_val
;
/* If no non-FALSE alternatives, CASE reduces to the default result */
/*
* If no non-FALSE alternatives, CASE reduces to the default
* result
*/
if
(
newargs
==
NIL
)
return
defresult
;
/* Otherwise we need a new CASE node */
...
...
@@ -2787,9 +2815,9 @@ eval_const_expressions_mutator(Node *node,
case
T_CaseTestExpr
:
{
/*
* If we know a constant test value for the current CASE construct,
* substitute it for the placeholder. Else just return the
*
placeholder as-is.
* If we know a constant test value for the current CASE
* construct, substitute it for the placeholder. Else just
* return the
placeholder as-is.
*/
if
(
context
->
case_val
)
return
copyObject
(
context
->
case_val
);
...
...
@@ -2848,11 +2876,12 @@ eval_const_expressions_mutator(Node *node,
context
);
/*
* We can remove null constants from the list. For a non-null
* constant, if it has not been preceded by any other
* non-null-constant expressions then it is the result. Otherwise,
* it's the next argument, but we can drop following arguments
* since they will never be reached.
* We can remove null constants from the list. For a
* non-null constant, if it has not been preceded by any
* other non-null-constant expressions then it is the
* result. Otherwise, it's the next argument, but we can
* drop following arguments since they will never be
* reached.
*/
if
(
IsA
(
e
,
Const
))
{
...
...
@@ -2866,7 +2895,10 @@ eval_const_expressions_mutator(Node *node,
newargs
=
lappend
(
newargs
,
e
);
}
/* If all the arguments were constant null, the result is just null */
/*
* If all the arguments were constant null, the result is just
* null
*/
if
(
newargs
==
NIL
)
return
(
Node
*
)
makeNullConst
(
coalesceexpr
->
coalescetype
,
-
1
,
...
...
@@ -2882,15 +2914,16 @@ eval_const_expressions_mutator(Node *node,
case
T_FieldSelect
:
{
/*
* We can optimize field selection from a whole-row Var into a simple
* Var. (This case won't be generated directly by the parser, becaus
e
* ParseComplexProjection short-circuits it. But it can arise while
* simplifying functions.) Also, we can optimize field selection from
*
a RowExpr construct.
* We can optimize field selection from a whole-row Var into a
* simple Var. (This case won't be generated directly by th
e
* parser, because ParseComplexProjection short-circuits it.
* But it can arise while simplifying functions.) Also, we
* can optimize field selection from
a RowExpr construct.
*
* We must however check that the declared type of the field is still
* the same as when the FieldSelect was created --- this can change if
* someone did ALTER COLUMN TYPE on the rowtype.
* We must however check that the declared type of the field
* is still the same as when the FieldSelect was created ---
* this can change if someone did ALTER COLUMN TYPE on the
* rowtype.
*/
FieldSelect
*
fselect
=
(
FieldSelect
*
)
node
;
FieldSelect
*
newfselect
;
...
...
@@ -2953,9 +2986,10 @@ eval_const_expressions_mutator(Node *node,
if
(
arg
&&
IsA
(
arg
,
RowExpr
))
{
/*
* We break ROW(...) IS [NOT] NULL into separate tests on its
* component fields. This form is usually more efficient to
* evaluate, as well as being more amenable to optimization.
* We break ROW(...) IS [NOT] NULL into separate tests on
* its component fields. This form is usually more
* efficient to evaluate, as well as being more amenable
* to optimization.
*/
RowExpr
*
rarg
=
(
RowExpr
*
)
arg
;
List
*
newargs
=
NIL
;
...
...
@@ -2968,8 +3002,8 @@ eval_const_expressions_mutator(Node *node,
Node
*
relem
=
(
Node
*
)
lfirst
(
l
);
/*
* A constant field refutes the whole NullTest if it's of the
*
wrong nullness; else we can discard it.
* A constant field refutes the whole NullTest if it's
* of the
wrong nullness; else we can discard it.
*/
if
(
relem
&&
IsA
(
relem
,
Const
))
{
...
...
@@ -3078,12 +3112,13 @@ eval_const_expressions_mutator(Node *node,
return
(
Node
*
)
newbtest
;
}
case
T_PlaceHolderVar
:
/*
* In estimation mode, just strip the PlaceHolderVar node altogether;
* this amounts to estimating that the contained value won't be forced
* to null by an outer join. In regular mode we just use the default
* behavior (ie, simplify the expression but leave the PlaceHolderVar
*
node intact).
* In estimation mode, just strip the PlaceHolderVar node
* altogether; this amounts to estimating that the contained value
* won't be forced to null by an outer join. In regular mode we
* just use the default behavior (ie, simplify the expression but
* leave the PlaceHolderVar
node intact).
*/
if
(
context
->
estimate
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment