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

Commit2d1f940

Browse files
committed
Minor code cleanup: remove no-longer-useful pull_subplans() function,
and convert pull_agg_clause() into count_agg_clause(), which is a moreefficient way of doing what it's really being used for.
1 parent85caf17 commit2d1f940

File tree

3 files changed

+20
-52
lines changed

3 files changed

+20
-52
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.143 2003/02/03 15:07:07 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.144 2003/02/04 00:50:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -623,11 +623,14 @@ grouping_planner(Query *parse, double tuple_fraction)
623623
* Will need actual number of aggregates for estimating costs.
624624
* Also, it's possible that optimization has eliminated all
625625
* aggregates, and we may as well check for that here.
626+
*
627+
* Note: we do not attempt to detect duplicate aggregates here;
628+
* a somewhat-overestimated count is okay for our present purposes.
626629
*/
627630
if (parse->hasAggs)
628631
{
629-
numAggs=length(pull_agg_clause((Node*)tlist))+
630-
length(pull_agg_clause(parse->havingQual));
632+
numAggs=count_agg_clause((Node*)tlist)+
633+
count_agg_clause(parse->havingQual);
631634
if (numAggs==0)
632635
parse->hasAggs= false;
633636
}

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

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.126 2003/02/03 21:15:44 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.127 2003/02/04 00:50:00 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -51,10 +51,9 @@ typedef struct
5151

5252
staticboolcontain_agg_clause_walker(Node*node,void*context);
5353
staticboolcontain_distinct_agg_clause_walker(Node*node,void*context);
54-
staticboolpull_agg_clause_walker(Node*node,List**listptr);
54+
staticboolcount_agg_clause_walker(Node*node,int*count);
5555
staticboolexpression_returns_set_walker(Node*node,void*context);
5656
staticboolcontain_subplans_walker(Node*node,void*context);
57-
staticboolpull_subplans_walker(Node*node,List**listptr);
5857
staticboolcontain_mutable_functions_walker(Node*node,void*context);
5958
staticboolcontain_volatile_functions_walker(Node*node,void*context);
6059
staticboolcontain_nonstrict_functions_walker(Node*node,void*context);
@@ -373,31 +372,28 @@ contain_distinct_agg_clause_walker(Node *node, void *context)
373372
}
374373

375374
/*
376-
* pull_agg_clause
377-
* Recursively pulls all Aggref nodes from an expression tree.
378-
*
379-
* Returns list of Aggref nodes found. Note the nodes themselves are not
380-
* copied, only referenced.
375+
* count_agg_clause
376+
* Recursively count the Aggref nodes in an expression tree.
381377
*
382378
* Note: this also checks for nested aggregates, which are an error.
383379
*/
384-
List*
385-
pull_agg_clause(Node*clause)
380+
int
381+
count_agg_clause(Node*clause)
386382
{
387-
List*result=NIL;
383+
intresult=0;
388384

389-
pull_agg_clause_walker(clause,&result);
385+
count_agg_clause_walker(clause,&result);
390386
returnresult;
391387
}
392388

393389
staticbool
394-
pull_agg_clause_walker(Node*node,List**listptr)
390+
count_agg_clause_walker(Node*node,int*count)
395391
{
396392
if (node==NULL)
397393
return false;
398394
if (IsA(node,Aggref))
399395
{
400-
*listptr=lappend(*listptr,node);
396+
(*count)++;
401397

402398
/*
403399
* Complain if the aggregate's argument contains any aggregates;
@@ -411,8 +407,8 @@ pull_agg_clause_walker(Node *node, List **listptr)
411407
*/
412408
return false;
413409
}
414-
returnexpression_tree_walker(node,pull_agg_clause_walker,
415-
(void*)listptr);
410+
returnexpression_tree_walker(node,count_agg_clause_walker,
411+
(void*)count);
416412
}
417413

418414

@@ -511,36 +507,6 @@ contain_subplans_walker(Node *node, void *context)
511507
returnexpression_tree_walker(node,contain_subplans_walker,context);
512508
}
513509

514-
/*
515-
* pull_subplans
516-
* Recursively pulls all subplans from an expression tree.
517-
*
518-
* Returns list of SubPlan nodes found. Note the nodes themselves
519-
* are not copied, only referenced.
520-
*/
521-
List*
522-
pull_subplans(Node*clause)
523-
{
524-
List*result=NIL;
525-
526-
pull_subplans_walker(clause,&result);
527-
returnresult;
528-
}
529-
530-
staticbool
531-
pull_subplans_walker(Node*node,List**listptr)
532-
{
533-
if (node==NULL)
534-
return false;
535-
if (is_subplan(node))
536-
{
537-
*listptr=lappend(*listptr,node);
538-
/* fall through to check args to subplan */
539-
}
540-
returnexpression_tree_walker(node,pull_subplans_walker,
541-
(void*)listptr);
542-
}
543-
544510

545511
/*****************************************************************************
546512
*Check clauses for mutable functions

‎src/include/optimizer/clauses.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: clauses.h,v 1.61 2003/01/17 03:25:04 tgl Exp $
10+
* $Id: clauses.h,v 1.62 2003/02/04 00:50:01 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -46,12 +46,11 @@ extern List *make_ands_implicit(Expr *clause);
4646

4747
externboolcontain_agg_clause(Node*clause);
4848
externboolcontain_distinct_agg_clause(Node*clause);
49-
externList*pull_agg_clause(Node*clause);
49+
externintcount_agg_clause(Node*clause);
5050

5151
externboolexpression_returns_set(Node*clause);
5252

5353
externboolcontain_subplans(Node*clause);
54-
externList*pull_subplans(Node*clause);
5554

5655
externboolcontain_mutable_functions(Node*clause);
5756
externboolcontain_volatile_functions(Node*clause);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp