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

Commitd404f10

Browse files
committed
Fix for select 1=1 or 2=2, select 1=1 and 2=2, and select sum(2+2).
1 parent78a055a commitd404f10

File tree

10 files changed

+69
-56
lines changed

10 files changed

+69
-56
lines changed

‎src/backend/commands/defind.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.17 1997/09/18 20:20:20 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/defind.c,v 1.18 1997/12/22 05:41:49 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -385,9 +385,7 @@ CheckPredExpr(Node *predicate, List *rangeTable, Oid baseRelOid)
385385
CheckPredClause((Expr*)predicate,rangeTable,baseRelOid);
386386
return;
387387
}
388-
elseif (or_clause(predicate))
389-
clauses= ((Expr*)predicate)->args;
390-
elseif (and_clause(predicate))
388+
elseif (or_clause(predicate)||and_clause(predicate))
391389
clauses= ((Expr*)predicate)->args;
392390
else
393391
elog(WARN,"Unsupported partial-index predicate expression type");

‎src/backend/executor/nodeAgg.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,19 @@ ExecInitAgg(Agg *node, EState *estate, Plan *parent)
534534
outerPlan=outerPlan(node);
535535
ExecInitNode(outerPlan,estate, (Plan*)node);
536536

537+
/*
538+
*Result runs in its own context, but make it use our aggregates
539+
*fix for 'select sum(2+2)'
540+
*/
541+
if (nodeTag(outerPlan)==T_Result)
542+
{
543+
((Result*)outerPlan)->resstate->cstate.cs_ProjInfo->pi_exprContext->ecxt_values=
544+
econtext->ecxt_values;
545+
((Result*)outerPlan)->resstate->cstate.cs_ProjInfo->pi_exprContext->ecxt_nulls=
546+
econtext->ecxt_nulls;
547+
}
548+
549+
537550
/* ----------------
538551
*initialize tuple type.
539552
* ----------------

‎src/backend/optimizer/path/xfunc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.8 1997/12/11 17:36:29 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.9 1997/12/22 05:41:59 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -451,7 +451,7 @@ xfunc_local_expense(LispValue clause)
451451
(LispValue)get_funcargs(clause)));
452452
elseif (fast_not_clause(clause))
453453
return (xfunc_local_expense(lsecond(clause)));
454-
elseif (fast_or_clause(clause))
454+
elseif (fast_or_clause(clause)||fast_and_clause(clause))
455455
{
456456
/* find cost of evaluating each disjunct */
457457
for (tmpclause=lnext(clause);tmpclause!=LispNil;
@@ -845,7 +845,7 @@ xfunc_find_references(LispValue clause)
845845
}
846846
elseif (fast_not_clause(clause))
847847
return (xfunc_find_references(lsecond(clause)));
848-
elseif (fast_or_clause(clause))
848+
elseif (fast_or_clause(clause)||fast_and_clause(clause))
849849
{
850850
/* string together result of all operands of OR */
851851
for (tmpclause=lnext(clause);tmpclause!=LispNil;
@@ -1186,7 +1186,7 @@ xfunc_fixvars(LispValue clause, /* clause being pulled up */
11861186
xfunc_fixvars(lfirst(tmpclause),rel,varno);
11871187
elseif (fast_not_clause(clause))
11881188
xfunc_fixvars(lsecond(clause),rel,varno);
1189-
elseif (fast_or_clause(clause))
1189+
elseif (fast_or_clause(clause)||fast_and_clause(clause))
11901190
for (tmpclause=lnext(clause);tmpclause!=LispNil;
11911191
tmpclause=lnext(tmpclause))
11921192
xfunc_fixvars(lfirst(tmpclause),rel,varno);

‎src/backend/optimizer/plan/planmain.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.12 1997/12/20 07:59:25 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.13 1997/12/22 05:42:04 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -69,7 +69,7 @@ query_planner(Query *root,
6969
List*qual)
7070
{
7171
List*constant_qual=NIL;
72-
List*flattened_tlist=NIL;
72+
List*var_only_tlist=NIL;
7373
List*level_tlist=NIL;
7474
Plan*subplan= (Plan*)NULL;
7575

@@ -109,24 +109,20 @@ query_planner(Query *root,
109109
* Create a target list that consists solely of (resdom var) target
110110
* list entries, i.e., contains no arbitrary expressions.
111111
*/
112-
flattened_tlist=flatten_tlist(tlist);
113-
if (flattened_tlist)
114-
{
115-
level_tlist=flattened_tlist;
116-
}
112+
var_only_tlist=flatten_tlist(tlist);
113+
if (var_only_tlist)
114+
level_tlist=var_only_tlist;
117115
else
118-
{
119116
/* from old code. the logic is beyond me. - ay 2/95 */
120117
level_tlist=tlist;
121-
}
122118

123119
/*
124120
* A query may have a non-variable target list and a non-variable
125121
* qualification only under certain conditions: - the query creates
126122
* all-new tuples, or - the query is a replace (a scan must still be
127123
* done in this case).
128124
*/
129-
if (flattened_tlist==NULL&&qual==NULL)
125+
if (var_only_tlist==NULL&&qual==NULL)
130126
{
131127

132128
switch (command_type)
@@ -192,11 +188,30 @@ query_planner(Query *root,
192188
return (plan);
193189
}
194190

191+
/*
192+
* fix up the flattened target list of the plan root node so that
193+
* expressions are evaluated. this forces expression evaluations that
194+
* may involve expensive function calls to be delayed to the very last
195+
* stage of query execution. this could be bad. but it is joey's
196+
* responsibility to optimally push these expressions down the plan
197+
* tree. -- Wei
198+
*
199+
* But now nothing to do if there are GroupBy and/or Aggregates: 1.
200+
* make_groupPlan fixes tlist; 2. flatten_tlist_vars does nothing with
201+
* aggregates fixing only other entries (i.e. - GroupBy-ed and so
202+
* fixed by make_groupPlan). - vadim 04/05/97
203+
*/
204+
if (root->groupClause==NULL&&root->qry_aggs==NULL)
205+
{
206+
subplan->targetlist=flatten_tlist_vars(tlist,
207+
subplan->targetlist);
208+
}
209+
210+
#ifdefNOT_USED
195211
/*
196212
* Destructively modify the query plan's targetlist to add fjoin lists
197213
* to flatten functions that return sets of base types
198214
*/
199-
#ifdefNOT_USED
200215
subplan->targetlist=generate_fjoin(subplan->targetlist);
201216
#endif
202217

‎src/backend/optimizer/plan/planner.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.14 1997/12/20 07:59:27 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.15 1997/12/22 05:42:08 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -74,7 +74,6 @@ planner(Query *parse)
7474
List*rangetable=parse->rtable;
7575
char*uniqueflag=parse->uniqueFlag;
7676
List*sortclause=parse->sortClause;
77-
Agg*aggplan=NULL;
7877

7978
Plan*result_plan= (Plan*)NULL;
8079

@@ -141,7 +140,7 @@ planner(Query *parse)
141140
*/
142141
if (parse->qry_aggs)
143142
{
144-
aggplan=make_agg(tlist,
143+
result_plan=(Plan*)make_agg(tlist,
145144
parse->qry_numAgg,
146145
parse->qry_aggs,
147146
result_plan);
@@ -153,29 +152,8 @@ planner(Query *parse)
153152
* pointers, after a few dozen's of copying, they're not the same
154153
* as those in the target list.)
155154
*/
156-
set_agg_tlist_references(aggplan);
157-
set_agg_agglist_references(aggplan);
158-
159-
result_plan= (Plan*)aggplan;
160-
}
161-
162-
/*
163-
* fix up the flattened target list of the plan root node so that
164-
* expressions are evaluated. this forces expression evaluations that
165-
* may involve expensive function calls to be delayed to the very last
166-
* stage of query execution. this could be bad. but it is joey's
167-
* responsibility to optimally push these expressions down the plan
168-
* tree. -- Wei
169-
*
170-
* But now nothing to do if there are GroupBy and/or Aggregates: 1.
171-
* make_groupPlan fixes tlist; 2. flatten_tlist_vars does nothing with
172-
* aggregates fixing only other entries (i.e. - GroupBy-ed and so
173-
* fixed by make_groupPlan). - vadim 04/05/97
174-
*/
175-
if (parse->groupClause==NULL&&aggplan==NULL)
176-
{
177-
result_plan->targetlist=flatten_tlist_vars(tlist,
178-
result_plan->targetlist);
155+
set_agg_tlist_references((Agg*)result_plan);
156+
set_agg_agglist_references((Agg*)result_plan);
179157
}
180158

181159
/*

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.9 1997/12/20 07:59:28 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.10 1997/12/22 05:42:10 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -329,6 +329,15 @@ replace_clause_joinvar_refs(Expr *clause,
329329
{
330330
return ((List*)clause);
331331
}
332+
elseif (and_clause((Node*)clause))
333+
{
334+
List*andclause=
335+
replace_subclause_joinvar_refs(((Expr*)clause)->args,
336+
outer_tlist,
337+
inner_tlist);
338+
339+
return ((List*)make_andclause(andclause));
340+
}
332341
elseif (or_clause((Node*)clause))
333342
{
334343
List*orclause=

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.12 1997/09/25 12:48:15 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.13 1997/12/22 05:42:14 momjian Exp $
1111
*
1212
* HISTORY
1313
* AUTHORDATEMAJOR EVENT
@@ -431,7 +431,7 @@ contains_not(Node *clause)
431431
if (not_clause(clause))
432432
return (true);
433433

434-
if (or_clause(clause))
434+
if (or_clause(clause)||and_clause(clause))
435435
{
436436
List*a;
437437

@@ -518,7 +518,7 @@ fix_opid(Node *clause)
518518
{
519519
;
520520
}
521-
elseif (or_clause(clause))
521+
elseif (or_clause(clause)||and_clause(clause))
522522
{
523523
fix_opids(((Expr*)clause)->args);
524524
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.6 1997/09/08 21:45:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/var.c,v 1.7 1997/12/22 05:42:16 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -85,7 +85,7 @@ contain_var_clause(Node *clause)
8585
returncontain_var_clause(((Iter*)clause)->iterexpr);
8686
elseif (single_node(clause))
8787
return FALSE;
88-
elseif (or_clause(clause))
88+
elseif (or_clause(clause)||and_clause(clause))
8989
{
9090
List*temp;
9191

@@ -156,7 +156,7 @@ pull_var_clause(Node *clause)
156156
retval=pull_var_clause(((Iter*)clause)->iterexpr);
157157
elseif (single_node(clause))
158158
retval=NIL;
159-
elseif (or_clause(clause))
159+
elseif (or_clause(clause)||and_clause(clause))
160160
{
161161
List*temp;
162162

‎src/backend/parser/parse_agg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.3 1997/11/26 03:42:37 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.4 1997/12/22 05:42:19 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -108,7 +108,7 @@ contain_agg_clause(Node *clause)
108108
returncontain_agg_clause(((Iter*)clause)->iterexpr);
109109
elseif (single_node(clause))
110110
return FALSE;
111-
elseif (or_clause(clause))
111+
elseif (or_clause(clause)||and_clause(clause))
112112
{
113113
List*temp;
114114

‎src/backend/parser/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.30 1997/11/26 01:11:36 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/parser/parser.c,v 1.31 1997/12/22 05:42:25 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -141,7 +141,7 @@ define_sets(Node *clause)
141141
{
142142
return;
143143
}
144-
elseif (or_clause(clause))
144+
elseif (or_clause(clause)||and_clause(clause))
145145
{
146146
List*temp;
147147

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp