|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.lucidera.lcs.LcsIndexOptimizer
public class LcsIndexOptimizer
LcsIndexOptimizer optimizes the access path to use index based on cost.
Nested Class Summary | |
---|---|
static class |
LcsIndexOptimizer.CandidateIndex
|
private static class |
LcsIndexOptimizer.Filter2IndexMapping
|
class |
LcsIndexOptimizer.IndexFilterTuple
|
static class |
LcsIndexOptimizer.IndexLengthComparator
|
private static class |
LcsIndexOptimizer.IndexPageCountComparator
|
private static class |
LcsIndexOptimizer.MappedFilterSelectivityComparator
|
private static class |
LcsIndexOptimizer.RowCountComparator
RowCountComparator is used to sort RelNodes based on their rowcounts, provided the counts are known. |
static class |
LcsIndexOptimizer.SargColumnFilter
|
static class |
LcsIndexOptimizer.SargColumnFilterSelectivityComparator
|
Constructor Summary | |
---|---|
LcsIndexOptimizer(LcsRowScanRel rowScanRel)
|
Method Summary | |
---|---|
private static LcsIndexIntersectRel |
addIntersect(RelNode oldIndexAccessRel,
RelOptRuleCall call,
int rowScanRelPosInCall,
FemLocalIndex index,
RelNode keyInput,
Integer[] inputKeyProj,
Integer[] inputDirectiveProj,
FennelRelParamId startRidParamId,
FennelRelParamId rowLimitParamId,
boolean requireMerge,
Double indexSelectivity)
Add new index access rel and intersect that with the oldIndexAccessRel. |
static RelNode |
addNewIndexAccessRel(RelNode oldIndexAccessRel,
RelOptRuleCall call,
int rowScanRelPosInCall,
FemLocalIndex index,
RelNode keyInput,
Integer[] inputKeyProj,
Integer[] inputDirectiveProj,
boolean requireMerge,
Double indexSelectivity)
Add new index access rel using a given index to the input of the row scan rel matched by the call. |
private Double |
costIndexAccess(List<LcsIndexOptimizer.SargColumnFilter> pointList,
List<LcsIndexOptimizer.SargColumnFilter> intervalList,
LcsIndexOptimizer.Filter2IndexMapping candidateMapping)
Calculate the cost of using index access and residual filtering with a row scan. |
private Double |
costIndexAccessWithInputRel(RelNode dimRel,
List<Integer> factKeyList,
List<Integer> dimKeyList,
FemLocalIndex index,
int matchedPos)
Calculate the cost of using index access, driven by an input rel, on a row scan. |
static Integer[] |
findIndexOnlyProjection(LcsRowScanRel rowScan,
FemLocalIndex index)
Search for a projection of a bitmap index that satisfies the row scan. |
private LcsIndexOptimizer.SargColumnFilter |
findSargFilterForColumn(LcsRowScanRel rowScanRel,
Set<LcsIndexOptimizer.SargColumnFilter> filterSet,
FemAbstractColumn col)
From a list of filters on distinct columns, find the one on a given column. |
FemLocalIndex |
findSemiJoinIndexByCost(RelNode dimRel,
List<Integer> factKeyList,
List<Integer> dimKeyList,
List<Integer> bestFactKeyOrder)
Find the index with the best cost to filter the LHS of a join that originates from a single LcsRowScanRel. |
private void |
getBestIndex(List<LcsIndexOptimizer.SargColumnFilter> pointList,
List<LcsIndexOptimizer.SargColumnFilter> intervalList)
Find the set of indexes that gives the lowest access time for the query. |
static Map<CwmColumn,SargIntervalSequence> |
getCol2SeqMap(LcsRowScanRel rowScan,
List<SargBinding> sargBindingList)
Converts a list of SargBidning to a map of column to sarg sequence. |
private Double |
getCombinedSelectivity(Set<LcsIndexOptimizer.SargColumnFilter> filterSet)
Calculate the combined selectivity of a set of sargable filters. |
private static Double |
getCombinedSelectivity(Set<LcsIndexOptimizer.SargColumnFilter> filterSet,
RelStatSource tabStat)
Calculate the combined selectivity of a set of sargable filters. |
private Map<FemLocalIndex,Integer> |
getIndex2MatchedPos(List<List<LcsIndexOptimizer.SargColumnFilter>> colFilterLists)
This is the algorithm that maps indexes to search key columns. |
Map<FemLocalIndex,Integer> |
getIndex2MatchedPosByCost(List<List<LcsIndexOptimizer.SargColumnFilter>> filterLists)
Find the best filter to index mapping based on cost. |
private Double |
getIndexBitmapBitOpCost(int numIndexesUsed)
Calculates the cost of performing bitmap operations for a bitmapped index. |
private Double |
getIndexBitmapCount(FemLocalIndex index,
int mappedPos,
LcsIndexOptimizer.SargColumnFilter lastFilter)
Calculate the number of bitmaps(distinct key values) satisfying the index search keys. |
private Double |
getIndexBitmapScanCost(FemLocalIndex index)
Calculate the cost of scanning an entire bitmap index. |
private Double |
getIndexBitmapScanCost(FemLocalIndex index,
Double scannedBitmapCount)
Calculate the cost of scanning part of a bitmap index. |
private Double |
getIndexBitmapSortCost(Double scannedBitmapCount)
Calculate the cost of sorting the bitmap entries in an index. |
static FemAbstractColumn |
getIndexColumn(FemLocalIndex index,
int position)
Get the column at a given index key position. |
private Double |
getIndexSearchCost(Map<FemLocalIndex,Integer> index2MatchedPosMap,
Map<FemLocalIndex,LcsIndexOptimizer.SargColumnFilter> index2LastFilterMap)
Calculate the cost of an index search. |
static FemLocalIndex |
getIndexWithMinDiskPages(LcsRowScanRelBase rowScan)
Selects from the clustered indexes on a table the one with the fewest number of pages. |
private Double |
getLcsTableBlockCount(LcsTable lcsTable)
Calculate the total number of disk blocks used by a lcs table. |
private Double |
getTableScanCostWithIndexSearch(Double indexSearchSelectivity)
Calculate the cost of scanning a table with index search applied. |
private Double |
getTableScanCostWithResidual(Set<LcsIndexOptimizer.SargColumnFilter> indexSearchFilterSet,
Set<LcsIndexOptimizer.SargColumnFilter> residualFilterSet)
Calculate the cost of scanning a table with residual filters applied. |
static List<FemLocalIndex> |
getUnclusteredIndexes(LcsRowScanRel rowScan)
Get a list of all unclustered indexes on the table scanned by a LcsRowScanRel |
private boolean |
mapIndexToFilter(List<FemLocalIndex> usableIndexes,
List<LcsIndexOptimizer.SargColumnFilter> pointList,
List<LcsIndexOptimizer.SargColumnFilter> intervalList,
Set<LcsIndexOptimizer.SargColumnFilter> mappedIndexSet,
TreeSet<LcsIndexOptimizer.IndexFilterTuple> indexFilterSet)
maps each index in the list of usable indexes to filters satisfiable by the index and populates the indexFilterSet with tuples (index, satisfiable filters). |
static FennelSingleRel |
newIndexRel(FennelRelImplementor relImplementor,
RelOptCluster cluster,
LcsTable lcsTable,
FemLocalIndex index,
RelNode keyInput,
Integer[] inputKeyProj,
Integer[] inputDirectiveProj,
FennelRelParamId startRidParamId,
FennelRelParamId rowLimitParamId,
boolean requireMerge,
Double indexSelectivity)
Create a new index search rel using an given index. |
private void |
rebuildTreeSet(TreeSet<LcsIndexOptimizer.IndexFilterTuple> indexFilterSet,
Set<LcsIndexOptimizer.SargColumnFilter> mappedFilters)
recalculate effective selectivity and rebuild the tree set effective selectivity of an index may be changed if some other indexes has satisfied some of the filters |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static Double IOCostPerBlock
private static Double SetOpCostPerBlock
private static Double ResidualFilterEvalCostPerMillionRow
private static Double SortCostConstant
private static Double ColumnCorrelationFactor
private static int ByteLength
private static int SmallTableRowCount
private static Double IndexSearchSeletivityThreshold
private LcsRowScanRel rowScanRel
private List<FemLocalIndex> usableIndexes
private int tableColumnCount
private int dbBlockSize
RelStatSource tableStats
private Double tableBlockCount
private Double tableRowCount
private Double rowScanRelRowCount
private Double deletionIndexScanCost
private boolean useCost
private Double avgColumnLength
private Double estimatedBitmapBlockCount
private Double estimatedBitmapRowCount
private Set<LcsIndexOptimizer.SargColumnFilter> tmpResidualFilterSet
private Map<FemLocalIndex,LcsIndexOptimizer.SargColumnFilter> tmpIndex2LastFilterMap
private LcsIndexOptimizer.Filter2IndexMapping bestMapping
private Double bestCost
private Timestamp labelTimestamp
Logger tracer
Constructor Detail |
---|
public LcsIndexOptimizer(LcsRowScanRel rowScanRel)
Method Detail |
---|
public static List<FemLocalIndex> getUnclusteredIndexes(LcsRowScanRel rowScan)
rowScan
-
public static FemAbstractColumn getIndexColumn(FemLocalIndex index, int position)
index
- the index whose key contains the columnposition
- the index key position for the column
private LcsIndexOptimizer.SargColumnFilter findSargFilterForColumn(LcsRowScanRel rowScanRel, Set<LcsIndexOptimizer.SargColumnFilter> filterSet, FemAbstractColumn col)
rowScanRel
- filterSet
- col
-
public static Integer[] findIndexOnlyProjection(LcsRowScanRel rowScan, FemLocalIndex index)
index
- the index which is to be projected
private Map<FemLocalIndex,Integer> getIndex2MatchedPos(List<List<LcsIndexOptimizer.SargColumnFilter>> colFilterLists)
colFilterLists
- two SargColumnFilter lists: the first one contains
the "point" column filters, the second one contains the "interval" column
filters.
public final Map<FemLocalIndex,Integer> getIndex2MatchedPosByCost(List<List<LcsIndexOptimizer.SargColumnFilter>> filterLists)
filterLists
- two lists of sarg column filters: one for point
filters, and one for interval filters.
private void getBestIndex(List<LcsIndexOptimizer.SargColumnFilter> pointList, List<LcsIndexOptimizer.SargColumnFilter> intervalList)
pointList
- list of point filtersintervalList
- list of interval filtersprivate boolean mapIndexToFilter(List<FemLocalIndex> usableIndexes, List<LcsIndexOptimizer.SargColumnFilter> pointList, List<LcsIndexOptimizer.SargColumnFilter> intervalList, Set<LcsIndexOptimizer.SargColumnFilter> mappedIndexSet, TreeSet<LcsIndexOptimizer.IndexFilterTuple> indexFilterSet)
usableIndexes
- list of indexes to be mappedpointList
- list of point filtersintervalList
- list of interval filtersmappedIndexSet
- indexFilterSet
- the tree set to be populated
private void rebuildTreeSet(TreeSet<LcsIndexOptimizer.IndexFilterTuple> indexFilterSet, Set<LcsIndexOptimizer.SargColumnFilter> mappedFilters)
indexFilterSet
- mappedFilters
- private Double costIndexAccess(List<LcsIndexOptimizer.SargColumnFilter> pointList, List<LcsIndexOptimizer.SargColumnFilter> intervalList, LcsIndexOptimizer.Filter2IndexMapping candidateMapping)
pointList
- list of point filtersintervalList
- list of interval filterscandidateMapping
- the candidate mapping from filter to index
private Double costIndexAccessWithInputRel(RelNode dimRel, List<Integer> factKeyList, List<Integer> dimKeyList, FemLocalIndex index, int matchedPos)
dimRel
- input rel that drives the index searchfactKeyList
- keys on which the row scan is filtereddimKeyList
- keys which the input rel produces to drive the index
searchindex
- index to be used in the index searchmatchedPos
- leading key positions of this index
public static Map<CwmColumn,SargIntervalSequence> getCol2SeqMap(LcsRowScanRel rowScan, List<SargBinding> sargBindingList)
sargBindingList
- list of sarg binding.
public final FemLocalIndex findSemiJoinIndexByCost(RelNode dimRel, List<Integer> factKeyList, List<Integer> dimKeyList, List<Integer> bestFactKeyOrder)
dimRel
- RHS of a join, e.g. scanning the dimension table.factKeyList
- LHS join key positionsdimKeyList
- RHS join key positionsbestFactKeyOrder
- join keys that can be filtered by the index
private Double getIndexSearchCost(Map<FemLocalIndex,Integer> index2MatchedPosMap, Map<FemLocalIndex,LcsIndexOptimizer.SargColumnFilter> index2LastFilterMap)
index2MatchedPosMap
- map from index to searched positionindex2LastFilterMap
- map from index to last filter satisfied by
this index.
private Double getIndexBitmapScanCost(FemLocalIndex index)
index
- index to be scanned.
private Double getIndexBitmapScanCost(FemLocalIndex index, Double scannedBitmapCount)
index
- index to be scanned.scannedBitmapCount
- number of bitmaps scanned
private Double getIndexBitmapBitOpCost(int numIndexesUsed)
numIndexesUsed
- number of indexes used in the index access path.
private Double getIndexBitmapSortCost(Double scannedBitmapCount)
scannedBitmapCount
- number of bitmaps scaned
private Double getIndexBitmapCount(FemLocalIndex index, int mappedPos, LcsIndexOptimizer.SargColumnFilter lastFilter)
index
- index to be scanned.mappedPos
- key postitions mapped to this index.lastFilter
- the last filter satisfied by this index
private Double getLcsTableBlockCount(LcsTable lcsTable)
lcsTable
-
private static Double getCombinedSelectivity(Set<LcsIndexOptimizer.SargColumnFilter> filterSet, RelStatSource tabStat)
filterSet
- set of filterstabStat
- stat for underlying table these filters are based on
private Double getCombinedSelectivity(Set<LcsIndexOptimizer.SargColumnFilter> filterSet)
filterSet
- set of filters
private Double getTableScanCostWithResidual(Set<LcsIndexOptimizer.SargColumnFilter> indexSearchFilterSet, Set<LcsIndexOptimizer.SargColumnFilter> residualFilterSet)
indexSearchFilterSet
- index search filtersresidualFilterSet
- residual column filters
private Double getTableScanCostWithIndexSearch(Double indexSearchSelectivity)
indexSearchSelectivity
-
public static FemLocalIndex getIndexWithMinDiskPages(LcsRowScanRelBase rowScan)
rowScan
- the table
public static FennelSingleRel newIndexRel(FennelRelImplementor relImplementor, RelOptCluster cluster, LcsTable lcsTable, FemLocalIndex index, RelNode keyInput, Integer[] inputKeyProj, Integer[] inputDirectiveProj, FennelRelParamId startRidParamId, FennelRelParamId rowLimitParamId, boolean requireMerge, Double indexSelectivity)
cluster
- ClusterrelImplementor
- ImplementorlcsTable
- table filtered by the index access pathindex
- the index to search onkeyInput
- input rel containing index key values to search on.inputKeyProj
- key locations from the input.inputDirectiveProj
- key directives for each key valuestartRidParamId
- rowLimitParamId
- requireMerge
- indexSelectivity
- the selectivity of the index scan; null if
unknown
private static LcsIndexIntersectRel addIntersect(RelNode oldIndexAccessRel, RelOptRuleCall call, int rowScanRelPosInCall, FemLocalIndex index, RelNode keyInput, Integer[] inputKeyProj, Integer[] inputDirectiveProj, FennelRelParamId startRidParamId, FennelRelParamId rowLimitParamId, boolean requireMerge, Double indexSelectivity)
oldIndexAccessRel
- existing index access relcall
- call matched by a rulerowScanRelPosInCall
- position of LcsRowScanRel in the sequence of
rels matched by the ruleindex
- index to add to the access pathkeyInput
- input rel to the index searchinputKeyProj
- key projection from index search inputinputDirectiveProj
- directive projection from index search inputstartRidParamId
- parameter ID for RID skipping optimizationrowLimitParamId
- parameter ID forrequireMerge
- whether a LcsIndexMergeRel should be added on top of
the newly created LcsIndexSearchRel. If the input to LcsIndexSearchRel is
known to search to just one bitmap, then no merge is required. All other
cases, for example, when the input comes from a sort, a merge is
required.indexSelectivity
- the selectivity of the index being added; null if
unknown
public static RelNode addNewIndexAccessRel(RelNode oldIndexAccessRel, RelOptRuleCall call, int rowScanRelPosInCall, FemLocalIndex index, RelNode keyInput, Integer[] inputKeyProj, Integer[] inputDirectiveProj, boolean requireMerge, Double indexSelectivity)
oldIndexAccessRel
- existing index access relcall
- call matched by a rulerowScanRelPosInCall
- position of LcsRowScanRel in the sequence of
rels matched by the ruleindex
- index to add to the access pathkeyInput
- input rel to the index searchinputKeyProj
- key projection from index search inputinputDirectiveProj
- directive projection from index search inputrequireMerge
- whether a LcsIndexMergeRel should be added on top of
the newly created LcsIndexSearchRel. If the input to LcsIndexSearchRel is
known to search to just one bitmap, then no merge is required. All other
cases, for example, when the input comes from a sort, a merge is
required.indexSelectivity
- selectivity of the new index being added; null if
unknown
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |