1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* paths.h
|
2005-06-06 00:32:58 +02:00
|
|
|
* prototypes for various files in optimizer/path
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
2007-01-05 23:20:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2007-09-26 20:51:51 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.99 2007/09/26 18:51:51 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef PATHS_H
|
|
|
|
#define PATHS_H
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-11-26 02:14:33 +01:00
|
|
|
#include "nodes/relation.h"
|
|
|
|
|
2003-01-24 04:58:44 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-07-27 08:23:12 +02:00
|
|
|
* allpaths.c
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2000-01-23 00:50:30 +01:00
|
|
|
extern bool enable_geqo;
|
2003-01-26 00:10:30 +01:00
|
|
|
extern int geqo_threshold;
|
2000-01-23 00:50:30 +01:00
|
|
|
|
2007-09-26 20:51:51 +02:00
|
|
|
/* Hook for plugins to replace standard_join_search() */
|
|
|
|
typedef RelOptInfo * (*join_search_hook_type) (PlannerInfo *root,
|
|
|
|
int levels_needed,
|
|
|
|
List *initial_rels);
|
|
|
|
extern PGDLLIMPORT join_search_hook_type join_search_hook;
|
|
|
|
|
|
|
|
|
2005-12-20 03:30:36 +01:00
|
|
|
extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist);
|
2007-09-26 20:51:51 +02:00
|
|
|
extern RelOptInfo *standard_join_search(PlannerInfo *root, int levels_needed,
|
|
|
|
List *initial_rels);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2001-10-18 18:11:42 +02:00
|
|
|
#ifdef OPTIMIZER_DEBUG
|
2005-06-06 00:32:58 +02:00
|
|
|
extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
|
2001-10-18 18:11:42 +02:00
|
|
|
#endif
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-07-27 08:23:12 +02:00
|
|
|
* indxpath.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines to generate index paths
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2005-11-25 20:47:50 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
/* Whether to use ScalarArrayOpExpr to build index qualifications */
|
|
|
|
SAOP_FORBID, /* Do not use ScalarArrayOpExpr */
|
|
|
|
SAOP_ALLOW, /* OK to use ScalarArrayOpExpr */
|
|
|
|
SAOP_REQUIRE /* Require ScalarArrayOpExpr */
|
|
|
|
} SaOpControl;
|
|
|
|
|
2005-06-06 00:32:58 +02:00
|
|
|
extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
|
|
|
|
extern List *generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
|
2005-04-25 03:30:14 +02:00
|
|
|
List *clauses, List *outer_clauses,
|
2006-06-06 19:59:58 +02:00
|
|
|
RelOptInfo *outer_rel);
|
2007-05-22 03:40:33 +02:00
|
|
|
extern void best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
|
|
|
|
RelOptInfo *outer_rel, JoinType jointype,
|
|
|
|
Path **cheapest_startup, Path **cheapest_total);
|
2005-04-22 23:58:32 +02:00
|
|
|
extern List *group_clauses_by_indexkey(IndexOptInfo *index,
|
2005-10-15 04:49:52 +02:00
|
|
|
List *clauses, List *outer_clauses,
|
|
|
|
Relids outer_relids,
|
2005-11-25 20:47:50 +01:00
|
|
|
SaOpControl saop_control,
|
2005-10-15 04:49:52 +02:00
|
|
|
bool *found_clause);
|
2007-01-20 21:45:41 +01:00
|
|
|
extern bool eclass_matches_any_index(EquivalenceClass *ec,
|
|
|
|
EquivalenceMember *em,
|
|
|
|
RelOptInfo *rel);
|
2005-04-12 01:06:57 +02:00
|
|
|
extern bool match_index_to_operand(Node *operand, int indexcol,
|
|
|
|
IndexOptInfo *index);
|
2005-03-27 08:29:49 +02:00
|
|
|
extern List *expand_indexqual_conditions(IndexOptInfo *index,
|
2005-10-15 04:49:52 +02:00
|
|
|
List *clausegroups);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern void check_partial_indexes(PlannerInfo *root, RelOptInfo *rel);
|
2004-01-06 00:39:54 +01:00
|
|
|
extern List *flatten_clausegroups_list(List *clausegroups);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-02-05 19:26:09 +01:00
|
|
|
/*
|
|
|
|
* orindxpath.c
|
|
|
|
* additional routines for indexable OR clauses
|
|
|
|
*/
|
2005-06-06 00:32:58 +02:00
|
|
|
extern bool create_or_index_quals(PlannerInfo *root, RelOptInfo *rel);
|
2000-02-05 19:26:09 +01:00
|
|
|
|
1999-11-23 21:07:06 +01:00
|
|
|
/*
|
|
|
|
* tidpath.h
|
|
|
|
* routines to generate tid paths
|
|
|
|
*/
|
2005-06-06 00:32:58 +02:00
|
|
|
extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-07-27 08:23:12 +02:00
|
|
|
* joinpath.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines to create join paths
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
2005-06-06 00:32:58 +02:00
|
|
|
extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
|
2001-03-22 05:01:46 +01:00
|
|
|
RelOptInfo *outerrel,
|
|
|
|
RelOptInfo *innerrel,
|
|
|
|
JoinType jointype,
|
|
|
|
List *restrictlist);
|
2000-02-07 05:41:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* joinrels.c
|
|
|
|
* routines to determine which relations to join
|
|
|
|
*/
|
2007-09-26 20:51:51 +02:00
|
|
|
extern List *join_search_one_level(PlannerInfo *root, int level,
|
|
|
|
List **joinrels);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern RelOptInfo *make_join_rel(PlannerInfo *root,
|
2005-12-20 03:30:36 +01:00
|
|
|
RelOptInfo *rel1, RelOptInfo *rel2);
|
Restructure code that is responsible for ensuring that clauseless joins are
considered when it is necessary to do so because of a join-order restriction
(that is, an outer-join or IN-subselect construct). The former coding was a
bit ad-hoc and inconsistent, and it missed some cases, as exposed by Mario
Weilguni's recent bug report. His specific problem was that an IN could be
turned into a "clauseless" join due to constant-propagation removing the IN's
joinclause, and if the IN's subselect involved more than one relation and
there was more than one such IN linking to the same upper relation, then the
only valid join orders involve "bushy" plans but we would fail to consider the
specific paths needed to get there. (See the example case added to the join
regression test.) On examining the code I wonder if there weren't some other
problem cases too; in particular it seems that GEQO was defending against a
different set of corner cases than the main planner was. There was also an
efficiency problem, in that when we did realize we needed a clauseless join
because of an IN, we'd consider clauseless joins against every other relation
whether this was sensible or not. It seems a better design is to use the
outer-join and in-clause lists as a backup heuristic, just as the rule of
joining only where there are joinclauses is a heuristic: we'll join two
relations if they have a usable joinclause *or* this might be necessary to
satisfy an outer-join or IN-clause join order restriction. I refactored the
code to have just one place considering this instead of three, and made sure
that it covered all the cases that any of them had been considering.
Backpatch as far as 8.1 (which has only the IN-clause form of the disease).
By rights 8.0 and 7.4 should have the bug too, but they accidentally fail
to fail, because the joininfo structure used in those releases preserves some
memory of there having once been a joinclause between the inner and outer
sides of an IN, and so it leads the code in the right direction anyway.
I'll be conservative and not touch them.
2007-02-16 01:14:01 +01:00
|
|
|
extern bool have_join_order_restriction(PlannerInfo *root,
|
|
|
|
RelOptInfo *rel1, RelOptInfo *rel2);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2007-01-20 21:45:41 +01:00
|
|
|
/*
|
|
|
|
* equivclass.c
|
|
|
|
* routines for managing EquivalenceClasses
|
|
|
|
*/
|
|
|
|
extern bool process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
|
|
|
|
bool below_outer_join);
|
|
|
|
extern void reconsider_outer_join_clauses(PlannerInfo *root);
|
|
|
|
extern EquivalenceClass *get_eclass_for_sort_expr(PlannerInfo *root,
|
|
|
|
Expr *expr,
|
|
|
|
Oid expr_datatype,
|
|
|
|
List *opfamilies);
|
|
|
|
extern void generate_base_implied_equalities(PlannerInfo *root);
|
|
|
|
extern List *generate_join_implied_equalities(PlannerInfo *root,
|
|
|
|
RelOptInfo *joinrel,
|
|
|
|
RelOptInfo *outer_rel,
|
|
|
|
RelOptInfo *inner_rel);
|
|
|
|
extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
|
|
|
|
extern void add_child_rel_equivalences(PlannerInfo *root,
|
|
|
|
AppendRelInfo *appinfo,
|
|
|
|
RelOptInfo *parent_rel,
|
|
|
|
RelOptInfo *child_rel);
|
|
|
|
extern List *find_eclass_clauses_for_index_join(PlannerInfo *root,
|
|
|
|
RelOptInfo *rel,
|
|
|
|
Relids outer_relids);
|
|
|
|
extern bool have_relevant_eclass_joinclause(PlannerInfo *root,
|
|
|
|
RelOptInfo *rel1, RelOptInfo *rel2);
|
|
|
|
extern bool has_relevant_eclass_joinclause(PlannerInfo *root,
|
|
|
|
RelOptInfo *rel1);
|
|
|
|
extern bool eclass_useful_for_merging(EquivalenceClass *eclass,
|
|
|
|
RelOptInfo *rel);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1999-08-16 04:17:58 +02:00
|
|
|
* pathkeys.c
|
|
|
|
* utilities for matching and building path keys
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1999-08-16 04:17:58 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
PATHKEYS_EQUAL, /* pathkeys are identical */
|
|
|
|
PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
|
|
|
|
PATHKEYS_BETTER2, /* vice versa */
|
|
|
|
PATHKEYS_DIFFERENT /* neither pathkey includes the other */
|
1999-08-16 04:17:58 +02:00
|
|
|
} PathKeysComparison;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2005-06-06 00:32:58 +02:00
|
|
|
extern List *canonicalize_pathkeys(PlannerInfo *root, List *pathkeys);
|
1999-08-16 04:17:58 +02:00
|
|
|
extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
|
|
|
|
extern bool pathkeys_contained_in(List *keys1, List *keys2);
|
1999-08-21 05:49:17 +02:00
|
|
|
extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
|
2000-04-12 19:17:23 +02:00
|
|
|
CostSelector cost_criterion);
|
2000-02-15 21:49:31 +01:00
|
|
|
extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths,
|
2000-04-12 19:17:23 +02:00
|
|
|
List *pathkeys,
|
|
|
|
double fraction);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern List *build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index,
|
2007-01-20 21:45:41 +01:00
|
|
|
ScanDirection scandir);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern List *convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
|
2005-10-15 04:49:52 +02:00
|
|
|
List *subquery_pathkeys);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern List *build_join_pathkeys(PlannerInfo *root,
|
2001-03-22 05:01:46 +01:00
|
|
|
RelOptInfo *joinrel,
|
2005-01-23 03:21:36 +01:00
|
|
|
JoinType jointype,
|
2001-03-22 05:01:46 +01:00
|
|
|
List *outer_pathkeys);
|
2007-01-20 21:45:41 +01:00
|
|
|
extern List *make_pathkeys_for_sortclauses(PlannerInfo *root,
|
|
|
|
List *sortclauses,
|
|
|
|
List *tlist,
|
|
|
|
bool canonicalize);
|
|
|
|
extern void cache_mergeclause_eclasses(PlannerInfo *root,
|
2001-10-25 07:50:21 +02:00
|
|
|
RestrictInfo *restrictinfo);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern List *find_mergeclauses_for_pathkeys(PlannerInfo *root,
|
2001-03-22 05:01:46 +01:00
|
|
|
List *pathkeys,
|
2007-01-20 21:45:41 +01:00
|
|
|
bool outer_keys,
|
2001-03-22 05:01:46 +01:00
|
|
|
List *restrictinfos);
|
2007-01-20 21:45:41 +01:00
|
|
|
extern List *select_outer_pathkeys_for_merge(PlannerInfo *root,
|
|
|
|
List *mergeclauses,
|
|
|
|
RelOptInfo *joinrel);
|
|
|
|
extern List *make_inner_pathkeys_for_merge(PlannerInfo *root,
|
|
|
|
List *mergeclauses,
|
|
|
|
List *outer_pathkeys);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern int pathkeys_useful_for_merging(PlannerInfo *root,
|
2001-03-22 05:01:46 +01:00
|
|
|
RelOptInfo *rel,
|
|
|
|
List *pathkeys);
|
2005-06-06 00:32:58 +02:00
|
|
|
extern int pathkeys_useful_for_ordering(PlannerInfo *root, List *pathkeys);
|
|
|
|
extern List *truncate_useless_pathkeys(PlannerInfo *root,
|
2001-03-22 05:01:46 +01:00
|
|
|
RelOptInfo *rel,
|
|
|
|
List *pathkeys);
|
2007-04-15 22:09:28 +02:00
|
|
|
extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PATHS_H */
|