Commit 926e8a00 authored by Tom Lane's avatar Tom Lane

Add a back-link from IndexOptInfo structs to their parent RelOptInfo

structs.  There are many places in the planner where we were passing
both a rel and an index to subroutines, and now need only pass the
index struct.  Notationally simpler, and perhaps a tad faster.
parent febc9a61
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.138 2005/03/06 22:15:04 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.139 2005/03/27 06:29:35 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -227,7 +227,6 @@ cost_nonsequential_access(double relpages) ...@@ -227,7 +227,6 @@ cost_nonsequential_access(double relpages)
* but here we consider the cost of just one pass. * but here we consider the cost of just one pass.
* *
* 'root' is the query root * 'root' is the query root
* 'baserel' is the base relation the index is for
* 'index' is the index to be used * 'index' is the index to be used
* 'indexQuals' is the list of applicable qual clauses (implicit AND semantics) * 'indexQuals' is the list of applicable qual clauses (implicit AND semantics)
* 'is_injoin' is T if we are considering using the index scan as the inside * 'is_injoin' is T if we are considering using the index scan as the inside
...@@ -243,11 +242,11 @@ cost_nonsequential_access(double relpages) ...@@ -243,11 +242,11 @@ cost_nonsequential_access(double relpages)
*/ */
void void
cost_index(Path *path, Query *root, cost_index(Path *path, Query *root,
RelOptInfo *baserel,
IndexOptInfo *index, IndexOptInfo *index,
List *indexQuals, List *indexQuals,
bool is_injoin) bool is_injoin)
{ {
RelOptInfo *baserel = index->rel;
Cost startup_cost = 0; Cost startup_cost = 0;
Cost run_cost = 0; Cost run_cost = 0;
Cost indexStartupCost; Cost indexStartupCost;
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.66 2005/03/26 23:29:17 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.67 2005/03/27 06:29:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -383,7 +383,7 @@ best_or_subclause_index(Query *root, ...@@ -383,7 +383,7 @@ best_or_subclause_index(Query *root,
} }
/* Collect index clauses usable with this index */ /* Collect index clauses usable with this index */
indexclauses = group_clauses_by_indexkey_for_or(rel, index, subclause); indexclauses = group_clauses_by_indexkey_for_or(index, subclause);
/* /*
* Ignore index if it doesn't match the subclause at all; except * Ignore index if it doesn't match the subclause at all; except
...@@ -398,9 +398,9 @@ best_or_subclause_index(Query *root, ...@@ -398,9 +398,9 @@ best_or_subclause_index(Query *root,
continue; continue;
/* Convert clauses to indexquals the executor can handle */ /* Convert clauses to indexquals the executor can handle */
indexquals = expand_indexqual_conditions(rel, index, indexclauses); indexquals = expand_indexqual_conditions(index, indexclauses);
cost_index(&subclause_path, root, rel, index, indexquals, false); cost_index(&subclause_path, root, index, indexquals, false);
if (!found || subclause_path.total_cost < *retTotalCost) if (!found || subclause_path.total_cost < *retTotalCost)
{ {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.64 2005/01/23 02:21:26 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.65 2005/03/27 06:29:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -648,7 +648,6 @@ get_cheapest_fractional_path_for_pathkeys(List *paths, ...@@ -648,7 +648,6 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
*/ */
List * List *
build_index_pathkeys(Query *root, build_index_pathkeys(Query *root,
RelOptInfo *rel,
IndexOptInfo *index, IndexOptInfo *index,
ScanDirection scandir) ScanDirection scandir)
{ {
...@@ -675,7 +674,8 @@ build_index_pathkeys(Query *root, ...@@ -675,7 +674,8 @@ build_index_pathkeys(Query *root,
if (*indexkeys != 0) if (*indexkeys != 0)
{ {
/* simple index column */ /* simple index column */
indexkey = (Node *) find_indexkey_var(root, rel, *indexkeys); indexkey = (Node *) find_indexkey_var(root, index->rel,
*indexkeys);
} }
else else
{ {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.176 2005/03/10 23:21:22 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.177 2005/03/27 06:29:38 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -65,16 +65,13 @@ static void fix_indxqual_references(List *indexquals, IndexPath *index_path, ...@@ -65,16 +65,13 @@ static void fix_indxqual_references(List *indexquals, IndexPath *index_path,
List **indxstrategy, List **indxstrategy,
List **indxsubtype, List **indxsubtype,
List **indxlossy); List **indxlossy);
static void fix_indxqual_sublist(List *indexqual, static void fix_indxqual_sublist(List *indexqual, IndexOptInfo *index,
Relids baserelids, int baserelid,
IndexOptInfo *index,
List **fixed_quals, List **fixed_quals,
List **strategy, List **strategy,
List **subtype, List **subtype,
List **lossy); List **lossy);
static Node *fix_indxqual_operand(Node *node, int baserelid, static Node *fix_indxqual_operand(Node *node, IndexOptInfo *index,
IndexOptInfo *index, Oid *opclass);
Oid *opclass);
static List *get_switched_clauses(List *clauses, Relids outerrelids); static List *get_switched_clauses(List *clauses, Relids outerrelids);
static List *order_qual_clauses(Query *root, List *clauses); static List *order_qual_clauses(Query *root, List *clauses);
static void copy_path_costsize(Plan *dest, Path *src); static void copy_path_costsize(Plan *dest, Path *src);
...@@ -1179,8 +1176,6 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path, ...@@ -1179,8 +1176,6 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path,
List **indxsubtype, List **indxsubtype,
List **indxlossy) List **indxlossy)
{ {
Relids baserelids = index_path->path.parent->relids;
int baserelid = index_path->path.parent->relid;
List *index_info = index_path->indexinfo; List *index_info = index_path->indexinfo;
ListCell *iq, ListCell *iq,
*ii; *ii;
...@@ -1198,7 +1193,7 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path, ...@@ -1198,7 +1193,7 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path,
List *subtype; List *subtype;
List *lossy; List *lossy;
fix_indxqual_sublist(indexqual, baserelids, baserelid, index, fix_indxqual_sublist(indexqual, index,
&fixed_qual, &strategy, &subtype, &lossy); &fixed_qual, &strategy, &subtype, &lossy);
*fixed_indexquals = lappend(*fixed_indexquals, fixed_qual); *fixed_indexquals = lappend(*fixed_indexquals, fixed_qual);
*indxstrategy = lappend(*indxstrategy, strategy); *indxstrategy = lappend(*indxstrategy, strategy);
...@@ -1222,9 +1217,7 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path, ...@@ -1222,9 +1217,7 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path,
* the integer list of lossiness flags (1/0) * the integer list of lossiness flags (1/0)
*/ */
static void static void
fix_indxqual_sublist(List *indexqual, fix_indxqual_sublist(List *indexqual, IndexOptInfo *index,
Relids baserelids, int baserelid,
IndexOptInfo *index,
List **fixed_quals, List **fixed_quals,
List **strategy, List **strategy,
List **subtype, List **subtype,
...@@ -1265,7 +1258,7 @@ fix_indxqual_sublist(List *indexqual, ...@@ -1265,7 +1258,7 @@ fix_indxqual_sublist(List *indexqual,
* the clause. The indexkey should be the side that refers to * the clause. The indexkey should be the side that refers to
* (only) the base relation. * (only) the base relation.
*/ */
if (!bms_equal(rinfo->left_relids, baserelids)) if (!bms_equal(rinfo->left_relids, index->rel->relids))
CommuteClause(newclause); CommuteClause(newclause);
/* /*
...@@ -1273,7 +1266,6 @@ fix_indxqual_sublist(List *indexqual, ...@@ -1273,7 +1266,6 @@ fix_indxqual_sublist(List *indexqual,
* indexkey operand as needed, and get the index opclass. * indexkey operand as needed, and get the index opclass.
*/ */
linitial(newclause->args) = fix_indxqual_operand(linitial(newclause->args), linitial(newclause->args) = fix_indxqual_operand(linitial(newclause->args),
baserelid,
index, index,
&opclass); &opclass);
...@@ -1295,8 +1287,7 @@ fix_indxqual_sublist(List *indexqual, ...@@ -1295,8 +1287,7 @@ fix_indxqual_sublist(List *indexqual,
} }
static Node * static Node *
fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index, fix_indxqual_operand(Node *node, IndexOptInfo *index, Oid *opclass)
Oid *opclass)
{ {
/* /*
* We represent index keys by Var nodes having the varno of the base * We represent index keys by Var nodes having the varno of the base
...@@ -1316,7 +1307,7 @@ fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index, ...@@ -1316,7 +1307,7 @@ fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index,
node = (Node *) ((RelabelType *) node)->arg; node = (Node *) ((RelabelType *) node)->arg;
if (IsA(node, Var) && if (IsA(node, Var) &&
((Var *) node)->varno == baserelid) ((Var *) node)->varno == index->rel->relid)
{ {
/* Try to match against simple index columns */ /* Try to match against simple index columns */
int varatt = ((Var *) node)->varattno; int varatt = ((Var *) node)->varattno;
...@@ -1353,7 +1344,7 @@ fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index, ...@@ -1353,7 +1344,7 @@ fix_indxqual_operand(Node *node, int baserelid, IndexOptInfo *index,
if (equal(node, indexkey)) if (equal(node, indexkey))
{ {
/* Found a match */ /* Found a match */
result = makeVar(baserelid, pos + 1, result = makeVar(index->rel->relid, pos + 1,
exprType(lfirst(indexpr_item)), -1, exprType(lfirst(indexpr_item)), -1,
0); 0);
/* return the correct opclass, too */ /* return the correct opclass, too */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.113 2005/03/26 23:29:18 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.114 2005/03/27 06:29:42 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -417,8 +417,7 @@ create_seqscan_path(Query *root, RelOptInfo *rel) ...@@ -417,8 +417,7 @@ create_seqscan_path(Query *root, RelOptInfo *rel)
* create_index_path * create_index_path
* Creates a path node for an index scan. * Creates a path node for an index scan.
* *
* 'rel' is the parent rel * 'index' is a usable index.
* 'index' is an index on 'rel'
* 'restriction_clauses' is a list of lists of RestrictInfo nodes * 'restriction_clauses' is a list of lists of RestrictInfo nodes
* to be used as index qual conditions in the scan. * to be used as index qual conditions in the scan.
* 'pathkeys' describes the ordering of the path. * 'pathkeys' describes the ordering of the path.
...@@ -430,7 +429,6 @@ create_seqscan_path(Query *root, RelOptInfo *rel) ...@@ -430,7 +429,6 @@ create_seqscan_path(Query *root, RelOptInfo *rel)
*/ */
IndexPath * IndexPath *
create_index_path(Query *root, create_index_path(Query *root,
RelOptInfo *rel,
IndexOptInfo *index, IndexOptInfo *index,
List *restriction_clauses, List *restriction_clauses,
List *pathkeys, List *pathkeys,
...@@ -440,11 +438,11 @@ create_index_path(Query *root, ...@@ -440,11 +438,11 @@ create_index_path(Query *root,
List *indexquals; List *indexquals;
pathnode->path.pathtype = T_IndexScan; pathnode->path.pathtype = T_IndexScan;
pathnode->path.parent = rel; pathnode->path.parent = index->rel;
pathnode->path.pathkeys = pathkeys; pathnode->path.pathkeys = pathkeys;
/* Convert clauses to indexquals the executor can handle */ /* Convert clauses to indexquals the executor can handle */
indexquals = expand_indexqual_conditions(rel, index, restriction_clauses); indexquals = expand_indexqual_conditions(index, restriction_clauses);
/* Flatten the clause-groups list to produce indexclauses list */ /* Flatten the clause-groups list to produce indexclauses list */
restriction_clauses = flatten_clausegroups_list(restriction_clauses); restriction_clauses = flatten_clausegroups_list(restriction_clauses);
...@@ -466,9 +464,9 @@ create_index_path(Query *root, ...@@ -466,9 +464,9 @@ create_index_path(Query *root,
* The number of rows is the same as the parent rel's estimate, since * The number of rows is the same as the parent rel's estimate, since
* this isn't a join inner indexscan. * this isn't a join inner indexscan.
*/ */
pathnode->rows = rel->rows; pathnode->rows = index->rel->rows;
cost_index(&pathnode->path, root, rel, index, indexquals, false); cost_index(&pathnode->path, root, index, indexquals, false);
return pathnode; return pathnode;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.101 2005/03/24 19:14:49 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.102 2005/03/27 06:29:42 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -124,6 +124,7 @@ get_relation_info(Oid relationObjectId, RelOptInfo *rel) ...@@ -124,6 +124,7 @@ get_relation_info(Oid relationObjectId, RelOptInfo *rel)
info = makeNode(IndexOptInfo); info = makeNode(IndexOptInfo);
info->indexoid = index->indexrelid; info->indexoid = index->indexrelid;
info->rel = rel;
info->ncolumns = ncolumns = index->indnatts; info->ncolumns = ncolumns = index->indnatts;
/* /*
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.103 2005/02/21 06:43:04 neilc Exp $ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.104 2005/03/27 06:29:45 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -253,6 +253,7 @@ typedef struct IndexOptInfo ...@@ -253,6 +253,7 @@ typedef struct IndexOptInfo
NodeTag type; NodeTag type;
Oid indexoid; /* OID of the index relation */ Oid indexoid; /* OID of the index relation */
RelOptInfo *rel; /* back-link to index's table */
/* statistics from pg_class */ /* statistics from pg_class */
BlockNumber pages; /* number of disk pages in index */ BlockNumber pages; /* number of disk pages in index */
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.62 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.63 2005/03/27 06:29:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,10 +50,8 @@ extern bool enable_mergejoin; ...@@ -50,10 +50,8 @@ extern bool enable_mergejoin;
extern bool enable_hashjoin; extern bool enable_hashjoin;
extern double clamp_row_est(double nrows); extern double clamp_row_est(double nrows);
extern void cost_seqscan(Path *path, Query *root, extern void cost_seqscan(Path *path, Query *root, RelOptInfo *baserel);
RelOptInfo *baserel); extern void cost_index(Path *path, Query *root, IndexOptInfo *index,
extern void cost_index(Path *path, Query *root,
RelOptInfo *baserel, IndexOptInfo *index,
List *indexQuals, bool is_injoin); List *indexQuals, bool is_injoin);
extern void cost_tidscan(Path *path, Query *root, extern void cost_tidscan(Path *path, Query *root,
RelOptInfo *baserel, List *tideval); RelOptInfo *baserel, List *tideval);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/pathnode.h,v 1.56 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/pathnode.h,v 1.57 2005/03/27 06:29:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,7 +28,7 @@ extern void set_cheapest(RelOptInfo *parent_rel); ...@@ -28,7 +28,7 @@ extern void set_cheapest(RelOptInfo *parent_rel);
extern void add_path(RelOptInfo *parent_rel, Path *new_path); extern void add_path(RelOptInfo *parent_rel, Path *new_path);
extern Path *create_seqscan_path(Query *root, RelOptInfo *rel); extern Path *create_seqscan_path(Query *root, RelOptInfo *rel);
extern IndexPath *create_index_path(Query *root, RelOptInfo *rel, extern IndexPath *create_index_path(Query *root,
IndexOptInfo *index, IndexOptInfo *index,
List *restriction_clauses, List *restriction_clauses,
List *pathkeys, List *pathkeys,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.79 2005/03/26 23:29:20 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.80 2005/03/27 06:29:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -38,11 +38,9 @@ extern void debug_print_rel(Query *root, RelOptInfo *rel); ...@@ -38,11 +38,9 @@ extern void debug_print_rel(Query *root, RelOptInfo *rel);
extern void create_index_paths(Query *root, RelOptInfo *rel); extern void create_index_paths(Query *root, RelOptInfo *rel);
extern Path *best_inner_indexscan(Query *root, RelOptInfo *rel, extern Path *best_inner_indexscan(Query *root, RelOptInfo *rel,
Relids outer_relids, JoinType jointype); Relids outer_relids, JoinType jointype);
extern List *group_clauses_by_indexkey_for_or(RelOptInfo *rel, extern List *group_clauses_by_indexkey_for_or(IndexOptInfo *index,
IndexOptInfo *index,
Expr *orsubclause); Expr *orsubclause);
extern List *expand_indexqual_conditions(RelOptInfo *rel, extern List *expand_indexqual_conditions(IndexOptInfo *index,
IndexOptInfo *index,
List *clausegroups); List *clausegroups);
extern void check_partial_indexes(Query *root, RelOptInfo *rel); extern void check_partial_indexes(Query *root, RelOptInfo *rel);
extern bool pred_test(List *predicate_list, List *restrictinfo_list); extern bool pred_test(List *predicate_list, List *restrictinfo_list);
...@@ -108,8 +106,7 @@ extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, ...@@ -108,8 +106,7 @@ extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths, extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths,
List *pathkeys, List *pathkeys,
double fraction); double fraction);
extern List *build_index_pathkeys(Query *root, RelOptInfo *rel, extern List *build_index_pathkeys(Query *root, IndexOptInfo *index,
IndexOptInfo *index,
ScanDirection scandir); ScanDirection scandir);
extern List *build_subquery_pathkeys(Query *root, RelOptInfo *rel, extern List *build_subquery_pathkeys(Query *root, RelOptInfo *rel,
Query *subquery); Query *subquery);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment