Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2d1f940

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 more efficient way of doing what it's really being used for.
1 parent 85caf17 commit 2d1f940

File tree

3 files changed

+20
-52
lines changed

3 files changed

+20
-52
lines changed

src/backend/optimizer/plan/planner.c

+6-3
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

+12-46
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
* AUTHOR DATE MAJOR EVENT
@@ -51,10 +51,9 @@ typedef struct
5151

5252
static bool contain_agg_clause_walker(Node *node, void *context);
5353
static bool contain_distinct_agg_clause_walker(Node *node, void *context);
54-
static bool pull_agg_clause_walker(Node *node, List **listptr);
54+
static bool count_agg_clause_walker(Node *node, int *count);
5555
static bool expression_returns_set_walker(Node *node, void *context);
5656
static bool contain_subplans_walker(Node *node, void *context);
57-
static bool pull_subplans_walker(Node *node, List **listptr);
5857
static bool contain_mutable_functions_walker(Node *node, void *context);
5958
static bool contain_volatile_functions_walker(Node *node, void *context);
6059
static bool contain_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+
int result = 0;
388384

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

393389
static bool
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-
return expression_tree_walker(node, pull_agg_clause_walker,
415-
(void *) listptr);
410+
return expression_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
return expression_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-
return result;
528-
}
529-
530-
static bool
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-
return expression_tree_walker(node, pull_subplans_walker,
541-
(void *) listptr);
542-
}
543-
544510

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

src/include/optimizer/clauses.h

+2-3
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
extern bool contain_agg_clause(Node *clause);
4848
extern bool contain_distinct_agg_clause(Node *clause);
49-
extern List *pull_agg_clause(Node *clause);
49+
extern int count_agg_clause(Node *clause);
5050

5151
extern bool expression_returns_set(Node *clause);
5252

5353
extern bool contain_subplans(Node *clause);
54-
extern List *pull_subplans(Node *clause);
5554

5655
extern bool contain_mutable_functions(Node *clause);
5756
extern bool contain_volatile_functions(Node *clause);

0 commit comments

Comments
 (0)