diff options
| author | Tom Lane | 2005-04-25 01:30:14 +0000 |
|---|---|---|
| committer | Tom Lane | 2005-04-25 01:30:14 +0000 |
| commit | 5b05185262fd562080ecfd675c7b3634a69851c0 (patch) | |
| tree | b9a9ff51a51e72d5076d6828584b30a504335303 /src/include | |
| parent | 186655e9a53b62f75e57bcfc218129a6cfe8ea68 (diff) | |
Remove support for OR'd indexscans internal to a single IndexScan plan
node, as this behavior is now better done as a bitmap OR indexscan.
This allows considerable simplification in nodeIndexscan.c itself as
well as several planner modules concerned with indexscan plan generation.
Also we can improve the sharing of code between regular and bitmap
indexscans, since they are now working with nigh-identical Plan nodes.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/executor/nodeIndexscan.h | 12 | ||||
| -rw-r--r-- | src/include/nodes/execnodes.h | 38 | ||||
| -rw-r--r-- | src/include/nodes/plannodes.h | 52 | ||||
| -rw-r--r-- | src/include/nodes/relation.h | 46 | ||||
| -rw-r--r-- | src/include/optimizer/paths.h | 10 | ||||
| -rw-r--r-- | src/include/optimizer/planmain.h | 3 | ||||
| -rw-r--r-- | src/include/optimizer/restrictinfo.h | 5 |
7 files changed, 83 insertions, 83 deletions
diff --git a/src/include/executor/nodeIndexscan.h b/src/include/executor/nodeIndexscan.h index 530ac5117bb..69e7ea6ba9b 100644 --- a/src/include/executor/nodeIndexscan.h +++ b/src/include/executor/nodeIndexscan.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/executor/nodeIndexscan.h,v 1.22 2005/04/19 22:35:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/executor/nodeIndexscan.h,v 1.23 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -24,4 +24,14 @@ extern void ExecIndexMarkPos(IndexScanState *node); extern void ExecIndexRestrPos(IndexScanState *node); extern void ExecIndexReScan(IndexScanState *node, ExprContext *exprCtxt); +/* routines exported to share code with nodeBitmapIndexscan.c */ +extern bool ExecIndexBuildScanKeys(PlanState *planstate, List *quals, + List *strategies, List *subtypes, + ExprState ***runtimeKeyInfo, + ScanKey *scanKeys, int *numScanKeys); +extern void ExecIndexEvalRuntimeKeys(ExprContext *econtext, + ExprState **run_keys, + ScanKey scan_keys, + int n_keys); + #endif /* NODEINDEXSCAN_H */ diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 4a3af3cece0..ba665025df6 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.128 2005/04/24 18:16:38 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.129 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -862,40 +862,28 @@ typedef ScanState SeqScanState; /* ---------------- * IndexScanState information * - * indxqualorig execution state for indxqualorig expressions - * NumIndices number of indices in this scan - * IndexPtr current index in use - * MarkIndexPtr IndexPtr for marked scan point - * ScanKeys Skey structures to scan index rels - * NumScanKeys array of no of keys in each Skey struct - * RuntimeKeyInfo array of array of exprstates for Skeys + * indexqualorig execution state for indexqualorig expressions + * ScanKeys Skey structures to scan index rel + * NumScanKeys number of Skey structs + * RuntimeKeyInfo array of exprstates for Skeys * that will be evaluated at runtime * RuntimeContext expr context for evaling runtime Skeys * RuntimeKeysReady true if runtime Skeys have been computed - * RelationDescs ptr to array of relation descriptors - * ScanDescs ptr to array of scan descriptors - * LossyQuals ptr to array of qual lists for lossy operators - * DupHash hashtable for recognizing dups in multiple scan - * MaxHash max # entries we will allow in hashtable + * RelationDesc index relation descriptor + * ScanDesc index scan descriptor * ---------------- */ typedef struct IndexScanState { ScanState ss; /* its first field is NodeTag */ - List *indxqualorig; - int iss_NumIndices; - int iss_IndexPtr; - int iss_MarkIndexPtr; - ScanKey *iss_ScanKeys; - int *iss_NumScanKeys; - ExprState ***iss_RuntimeKeyInfo; + List *indexqualorig; + ScanKey iss_ScanKeys; + int iss_NumScanKeys; + ExprState **iss_RuntimeKeyInfo; ExprContext *iss_RuntimeContext; bool iss_RuntimeKeysReady; - RelationPtr iss_RelationDescs; - IndexScanDescPtr iss_ScanDescs; - List **iss_LossyQuals; - HTAB *iss_DupHash; - long iss_MaxHash; + Relation iss_RelationDesc; + IndexScanDesc iss_ScanDesc; } IndexScanState; /* ---------------- diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 4ab8473e562..6e2e01166c9 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.78 2005/04/19 22:35:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.79 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -182,22 +182,35 @@ typedef Scan SeqScan; /* ---------------- * index scan node * - * Note: this can actually represent N indexscans, all on the same table - * but potentially using different indexes, put together with OR semantics. - * (XXX that extension should probably go away, because bitmapindexscan will - * largely eliminate the need for it.) + * indexqualorig is an implicitly-ANDed list of index qual expressions, each + * in the same form it appeared in the query WHERE condition. Each should + * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey). + * The indexkey is a Var or expression referencing column(s) of the index's + * base table. The comparisonval might be any expression, but it won't use + * any columns of the base table. + * + * indexqual has the same form, but the expressions have been commuted if + * necessary to put the indexkeys on the left, and the indexkeys are replaced + * by Var nodes identifying the index columns (varattno is the index column + * position, not the base table's column, even though varno is for the base + * table). This is a bit hokey ... would be cleaner to use a special-purpose + * node type that could not be mistaken for a regular Var. But it will do + * for now. + * + * indexstrategy and indexsubtype are lists corresponding one-to-one with + * indexqual; they give information about the indexable operators that appear + * at the top of each indexqual. * ---------------- */ typedef struct IndexScan { Scan scan; - List *indxid; /* list of index OIDs (1 per scan) */ - List *indxqual; /* list of sublists of index quals */ - List *indxqualorig; /* the same in original form */ - List *indxstrategy; /* list of sublists of strategy numbers */ - List *indxsubtype; /* list of sublists of strategy subtypes */ - List *indxlossy; /* list of sublists of lossy flags (ints) */ - ScanDirection indxorderdir; /* forward or backward or don't care */ + Oid indexid; /* OID of index to scan */ + List *indexqual; /* list of index quals (OpExprs) */ + List *indexqualorig; /* the same in original form */ + List *indexstrategy; /* integer list of strategy numbers */ + List *indexsubtype; /* OID list of strategy subtypes */ + ScanDirection indexorderdir; /* forward or backward or don't care */ } IndexScan; /* ---------------- @@ -209,19 +222,22 @@ typedef struct IndexScan * intermediate BitmapAnd and/or BitmapOr nodes to combine it with * the results of other BitmapIndexScans. * + * The fields have the same meanings as for IndexScan, except we don't + * store a direction flag because direction is uninteresting. + * * In a BitmapIndexScan plan node, the targetlist and qual fields are - * not used and are always NIL. The indxqualorig field is useless at + * not used and are always NIL. The indexqualorig field is unused at * run time too, but is saved for the benefit of EXPLAIN. * ---------------- */ typedef struct BitmapIndexScan { Scan scan; - Oid indxid; /* OID of index to scan */ - List *indxqual; /* list of index quals */ - List *indxqualorig; /* list of original forms of index quals */ - List *indxstrategy; /* list of strategy numbers */ - List *indxsubtype; /* list of strategy subtypes */ + Oid indexid; /* OID of index to scan */ + List *indexqual; /* list of index quals (OpExprs) */ + List *indexqualorig; /* the same in original form */ + List *indexstrategy; /* integer list of strategy numbers */ + List *indexsubtype; /* OID list of strategy subtypes */ } BitmapIndexScan; /* ---------------- diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 945858e8a60..4618cf3a07e 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.108 2005/04/22 21:58:32 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.109 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -332,33 +332,20 @@ typedef struct Path } Path; /*---------- - * IndexPath represents an index scan. Although an indexscan can only read - * a single relation, it can scan it more than once, potentially using a - * different index during each scan. The result is the union (OR) of all the - * tuples matched during any scan. (The executor is smart enough not to return - * the same tuple more than once, even if it is matched in multiple scans.) + * IndexPath represents an index scan over a single index. * - * XXX bitmap index scans will probably obviate the need for plain OR - * indexscans, allowing a lot of this to be simplified. + * 'indexinfo' is the index to be scanned. * - * 'indexinfo' is a list of IndexOptInfo nodes, one per scan to be performed. - * - * 'indexclauses' is a list of index qualifications, also one per scan. - * Each entry in 'indexclauses' is a sublist of qualification clauses to be - * used for that scan, with implicit AND semantics across the sublist items. - * NOTE that the semantics of the top-level list in 'indexclauses' is OR - * combination, while the sublists are implicitly AND combinations! + * 'indexclauses' is a list of index qualification clauses, with implicit + * AND semantics across the list. Each clause is a RestrictInfo node from + * the query's WHERE or JOIN conditions. * * 'indexquals' has the same structure as 'indexclauses', but it contains - * the actual indexqual conditions that can be used with the index(es). + * the actual indexqual conditions that can be used with the index. * In simple cases this is identical to 'indexclauses', but when special * indexable operators appear in 'indexclauses', they are replaced by the * derived indexscannable conditions in 'indexquals'. * - * Both 'indexclauses' and 'indexquals' are lists of sublists of RestrictInfo - * nodes. (Before 8.0, we kept bare operator expressions in these lists, but - * storing RestrictInfos is more efficient since selectivities can be cached.) - * * 'isjoininner' is TRUE if the path is a nestloop inner scan (that is, * some of the index conditions are join rather than restriction clauses). * @@ -372,7 +359,8 @@ typedef struct Path * * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that * we need not recompute them when considering using the same index in a - * bitmap index/heap scan (see BitmapHeapPath). + * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath + * itself represent the costs of an IndexScan plan type. * * 'rows' is the estimated result tuple count for the indexscan. This * is the same as path.parent->rows for a simple indexscan, but it is @@ -384,7 +372,7 @@ typedef struct Path typedef struct IndexPath { Path path; - List *indexinfo; + IndexOptInfo *indexinfo; List *indexclauses; List *indexquals; bool isjoininner; @@ -402,13 +390,13 @@ typedef struct IndexPath * out in physical heap order no matter what the underlying indexes did. * * The individual indexscans are represented by IndexPath nodes, and any - * logic on top of them is represented by BitmapAndPath and BitmapOrPath. - * Notice that we can use the same IndexPath node both to represent a regular - * IndexScan plan, and as the child of a BitmapHeapPath that represents - * scanning the same index using a BitmapIndexScan. The startup_cost and - * total_cost figures of an IndexPath always represent the costs to use it - * as a regular IndexScan. The costs of a BitmapIndexScan can be computed - * using the IndexPath's indextotalcost and indexselectivity. + * logic on top of them is represented by a tree of BitmapAndPath and + * BitmapOrPath nodes. Notice that we can use the same IndexPath node both + * to represent a regular IndexScan plan, and as the child of a BitmapHeapPath + * that represents scanning the same index using a BitmapIndexScan. The + * startup_cost and total_cost figures of an IndexPath always represent the + * costs to use it as a regular IndexScan. The costs of a BitmapIndexScan + * can be computed using the IndexPath's indextotalcost and indexselectivity. * * BitmapHeapPaths can be nestloop inner indexscans. The isjoininner and * rows fields serve the same purpose as for plain IndexPaths. diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h index a91744fd5f0..3b90cd7f7c8 100644 --- a/src/include/optimizer/paths.h +++ b/src/include/optimizer/paths.h @@ -8,7 +8,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.82 2005/04/22 21:58:32 tgl Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.83 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -36,13 +36,15 @@ extern void debug_print_rel(Query *root, RelOptInfo *rel); * routines to generate index paths */ extern void create_index_paths(Query *root, RelOptInfo *rel); +extern List *generate_bitmap_or_paths(Query *root, RelOptInfo *rel, + List *clauses, List *outer_clauses, + bool isjoininner, + Relids outer_relids); extern Path *best_inner_indexscan(Query *root, RelOptInfo *rel, Relids outer_relids, JoinType jointype); extern List *group_clauses_by_indexkey(IndexOptInfo *index, List *clauses, List *outer_clauses, Relids outer_relids); -extern List *group_clauses_by_indexkey_for_or(IndexOptInfo *index, - Expr *orsubclause); extern bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index); extern List *expand_indexqual_conditions(IndexOptInfo *index, @@ -50,14 +52,12 @@ extern List *expand_indexqual_conditions(IndexOptInfo *index, extern void check_partial_indexes(Query *root, RelOptInfo *rel); extern bool pred_test(List *predicate_list, List *restrictinfo_list); extern List *flatten_clausegroups_list(List *clausegroups); -extern Expr *make_expr_from_indexclauses(List *indexclauses); /* * orindxpath.c * additional routines for indexable OR clauses */ extern bool create_or_index_quals(Query *root, RelOptInfo *rel); -extern void create_or_index_paths(Query *root, RelOptInfo *rel); /* * tidpath.h diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 4f39cc3527b..c98838a2b25 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.82 2005/04/12 05:11:28 tgl Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.83 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -33,6 +33,7 @@ extern Plan *optimize_minmax_aggregates(Query *root, List *tlist, * prototypes for plan/createplan.c */ extern Plan *create_plan(Query *root, Path *best_path); +extern List *create_bitmap_restriction(Path *bitmapqual); extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual, Index scanrelid, Plan *subplan); extern Append *make_append(List *appendplans, bool isTarget, List *tlist); diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h index 77c03bb4ec2..5c47a0d00b1 100644 --- a/src/include/optimizer/restrictinfo.h +++ b/src/include/optimizer/restrictinfo.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.27 2005/04/22 21:58:32 tgl Exp $ + * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.28 2005/04/25 01:30:14 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,9 +18,6 @@ extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down, bool valid_everywhere); -extern List *make_restrictinfo_from_indexclauses(List *indexclauses, - bool is_pushed_down, - bool valid_everywhere); extern bool restriction_is_or_clause(RestrictInfo *restrictinfo); extern List *get_actual_clauses(List *restrictinfo_list); extern void get_actual_join_clauses(List *restrictinfo_list, |
