Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita04161f

Browse files
committed
Convert eval_const_expressions's long series of IsA tests into a switch.
This function has now grown enough cases that a switch seems appropriate.This results in a measurable speed improvement on some platforms, andshould certainly not hurt. The code's in need of a pgindent run now,though.Andres Freund
1 parent5943d40 commita04161f

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

‎src/backend/optimizer/util/clauses.c

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,9 @@ eval_const_expressions_mutator(Node *node,
21062106
{
21072107
if (node==NULL)
21082108
returnNULL;
2109-
if (IsA(node,Param))
2109+
switch (nodeTag(node))
2110+
{
2111+
caseT_Param:
21102112
{
21112113
Param*param= (Param*)node;
21122114

@@ -2152,7 +2154,7 @@ eval_const_expressions_mutator(Node *node,
21522154
/* Not replaceable, so just copy the Param (no need to recurse) */
21532155
return (Node*)copyObject(param);
21542156
}
2155-
if (IsA(node,FuncExpr))
2157+
caseT_FuncExpr:
21562158
{
21572159
FuncExpr*expr= (FuncExpr*)node;
21582160
List*args;
@@ -2210,7 +2212,7 @@ eval_const_expressions_mutator(Node *node,
22102212
newexpr->location=expr->location;
22112213
return (Node*)newexpr;
22122214
}
2213-
if (IsA(node,OpExpr))
2215+
caseT_OpExpr:
22142216
{
22152217
OpExpr*expr= (OpExpr*)node;
22162218
List*args;
@@ -2275,7 +2277,7 @@ eval_const_expressions_mutator(Node *node,
22752277
newexpr->location=expr->location;
22762278
return (Node*)newexpr;
22772279
}
2278-
if (IsA(node,DistinctExpr))
2280+
caseT_DistinctExpr:
22792281
{
22802282
DistinctExpr*expr= (DistinctExpr*)node;
22812283
List*args;
@@ -2372,7 +2374,7 @@ eval_const_expressions_mutator(Node *node,
23722374
newexpr->location=expr->location;
23732375
return (Node*)newexpr;
23742376
}
2375-
if (IsA(node,BoolExpr))
2377+
caseT_BoolExpr:
23762378
{
23772379
BoolExpr*expr= (BoolExpr*)node;
23782380

@@ -2439,19 +2441,18 @@ eval_const_expressions_mutator(Node *node,
24392441
(int)expr->boolop);
24402442
break;
24412443
}
2444+
break;
24422445
}
2443-
if (IsA(node,SubPlan)||
2444-
IsA(node,AlternativeSubPlan))
2445-
{
2446+
caseT_SubPlan:
2447+
caseT_AlternativeSubPlan:
24462448
/*
24472449
* Return a SubPlan unchanged --- too late to do anything with it.
24482450
*
24492451
* XXX should we ereport() here instead? Probably this routine should
24502452
* never be invoked after SubPlan creation.
24512453
*/
24522454
returnnode;
2453-
}
2454-
if (IsA(node,RelabelType))
2455+
caseT_RelabelType:
24552456
{
24562457
/*
24572458
* If we can simplify the input to a constant, then we don't need the
@@ -2493,7 +2494,7 @@ eval_const_expressions_mutator(Node *node,
24932494
return (Node*)newrelabel;
24942495
}
24952496
}
2496-
if (IsA(node,CoerceViaIO))
2497+
caseT_CoerceViaIO:
24972498
{
24982499
CoerceViaIO*expr= (CoerceViaIO*)node;
24992500
Expr*arg;
@@ -2569,7 +2570,7 @@ eval_const_expressions_mutator(Node *node,
25692570
newexpr->location=expr->location;
25702571
return (Node*)newexpr;
25712572
}
2572-
if (IsA(node,ArrayCoerceExpr))
2573+
caseT_ArrayCoerceExpr:
25732574
{
25742575
ArrayCoerceExpr*expr= (ArrayCoerceExpr*)node;
25752576
Expr*arg;
@@ -2607,7 +2608,7 @@ eval_const_expressions_mutator(Node *node,
26072608
/* Else we must return the partially-simplified node */
26082609
return (Node*)newexpr;
26092610
}
2610-
if (IsA(node,CollateExpr))
2611+
caseT_CollateExpr:
26112612
{
26122613
/*
26132614
* If we can simplify the input to a constant, then we don't need the
@@ -2652,7 +2653,7 @@ eval_const_expressions_mutator(Node *node,
26522653
return (Node*)relabel;
26532654
}
26542655
}
2655-
if (IsA(node,CaseExpr))
2656+
caseT_CaseExpr:
26562657
{
26572658
/*----------
26582659
* CASE expressions can be simplified if there are constant
@@ -2783,7 +2784,7 @@ eval_const_expressions_mutator(Node *node,
27832784
newcase->location=caseexpr->location;
27842785
return (Node*)newcase;
27852786
}
2786-
if (IsA(node,CaseTestExpr))
2787+
caseT_CaseTestExpr:
27872788
{
27882789
/*
27892790
* If we know a constant test value for the current CASE construct,
@@ -2795,7 +2796,7 @@ eval_const_expressions_mutator(Node *node,
27952796
else
27962797
returncopyObject(node);
27972798
}
2798-
if (IsA(node,ArrayExpr))
2799+
caseT_ArrayExpr:
27992800
{
28002801
ArrayExpr*arrayexpr= (ArrayExpr*)node;
28012802
ArrayExpr*newarray;
@@ -2831,7 +2832,7 @@ eval_const_expressions_mutator(Node *node,
28312832

28322833
return (Node*)newarray;
28332834
}
2834-
if (IsA(node,CoalesceExpr))
2835+
caseT_CoalesceExpr:
28352836
{
28362837
CoalesceExpr*coalesceexpr= (CoalesceExpr*)node;
28372838
CoalesceExpr*newcoalesce;
@@ -2878,7 +2879,7 @@ eval_const_expressions_mutator(Node *node,
28782879
newcoalesce->location=coalesceexpr->location;
28792880
return (Node*)newcoalesce;
28802881
}
2881-
if (IsA(node,FieldSelect))
2882+
caseT_FieldSelect:
28822883
{
28832884
/*
28842885
* We can optimize field selection from a whole-row Var into a simple
@@ -2941,7 +2942,7 @@ eval_const_expressions_mutator(Node *node,
29412942
newfselect->resultcollid=fselect->resultcollid;
29422943
return (Node*)newfselect;
29432944
}
2944-
if (IsA(node,NullTest))
2945+
caseT_NullTest:
29452946
{
29462947
NullTest*ntest= (NullTest*)node;
29472948
NullTest*newntest;
@@ -3024,7 +3025,7 @@ eval_const_expressions_mutator(Node *node,
30243025
newntest->argisrow=ntest->argisrow;
30253026
return (Node*)newntest;
30263027
}
3027-
if (IsA(node,BooleanTest))
3028+
caseT_BooleanTest:
30283029
{
30293030
BooleanTest*btest= (BooleanTest*)node;
30303031
BooleanTest*newbtest;
@@ -3076,19 +3077,24 @@ eval_const_expressions_mutator(Node *node,
30763077
newbtest->booltesttype=btest->booltesttype;
30773078
return (Node*)newbtest;
30783079
}
3079-
if (IsA(node,PlaceHolderVar)&&context->estimate)
3080-
{
3080+
caseT_PlaceHolderVar:
30813081
/*
30823082
* In estimation mode, just strip the PlaceHolderVar node altogether;
30833083
* this amounts to estimating that the contained value won't be forced
30843084
* to null by an outer join. In regular mode we just use the default
30853085
* behavior (ie, simplify the expression but leave the PlaceHolderVar
30863086
* node intact).
30873087
*/
3088-
PlaceHolderVar*phv= (PlaceHolderVar*)node;
3088+
if (context->estimate)
3089+
{
3090+
PlaceHolderVar*phv= (PlaceHolderVar*)node;
30893091

3090-
returneval_const_expressions_mutator((Node*)phv->phexpr,
3091-
context);
3092+
returneval_const_expressions_mutator((Node*)phv->phexpr,
3093+
context);
3094+
}
3095+
break;
3096+
default:
3097+
break;
30923098
}
30933099

30943100
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp