From af95d7aa63be1d03bad6070d090874d3dfa046e8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 7 Aug 2008 19:35:02 +0000 Subject: Improve INTERSECT/EXCEPT hashing by realizing that we don't need to make any hashtable entries for tuples that are found only in the second input: they can never contribute to the output. Furthermore, this implies that the planner should endeavor to put first the smaller (in number of groups) input relation for an INTERSECT. Implement that, and upgrade prepunion's estimation of the number of rows returned by setops so that there's some amount of sanity in the estimate of which one is smaller. --- src/include/optimizer/planmain.h | 6 +++--- src/include/optimizer/tlist.h | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/include/optimizer') diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 616f0ea2ad..0aa1d32f94 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.109 2008/08/07 03:04:04 tgl Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.110 2008/08/07 19:35:02 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -62,8 +62,8 @@ extern Unique *make_unique(Plan *lefttree, List *distinctList); extern Limit *make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount, int64 offset_est, int64 count_est); extern SetOp *make_setop(SetOpCmd cmd, SetOpStrategy strategy, Plan *lefttree, - List *distinctList, AttrNumber flagColIdx, long numGroups, - double outputRows); + List *distinctList, AttrNumber flagColIdx, int firstFlag, + long numGroups, double outputRows); extern Result *make_result(PlannerInfo *root, List *tlist, Node *resconstantqual, Plan *subplan); extern bool is_projection_capable_plan(Plan *plan); diff --git a/src/include/optimizer/tlist.h b/src/include/optimizer/tlist.h index 9899b14c82..d2c7f42e05 100644 --- a/src/include/optimizer/tlist.h +++ b/src/include/optimizer/tlist.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/tlist.h,v 1.51 2008/08/07 01:11:52 tgl Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/tlist.h,v 1.52 2008/08/07 19:35:02 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -23,6 +23,9 @@ extern TargetEntry *tlist_member_ignore_relabel(Node *node, List *targetlist); extern List *flatten_tlist(List *tlist); extern List *add_to_flat_tlist(List *tlist, List *vars); +extern List *get_tlist_exprs(List *tlist, bool includeJunk); +extern bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK); + extern TargetEntry *get_sortgroupref_tle(Index sortref, List *targetList); extern TargetEntry *get_sortgroupclause_tle(SortGroupClause *sgClause, @@ -37,6 +40,4 @@ extern AttrNumber *extract_grouping_cols(List *groupClause, List *tlist); extern bool grouping_is_sortable(List *groupClause); extern bool grouping_is_hashable(List *groupClause); -extern bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK); - #endif /* TLIST_H */ -- cgit v1.2.1