*/
protected static AbstractPlanNode getIndexAccessPlanForTable(StmtTableScan tableScan, AccessPath path)
{
// now assume this will be an index scan and get the relevant index
Index index = path.index;
IndexScanPlanNode scanNode = new IndexScanPlanNode(tableScan, index);
AbstractPlanNode resultNode = scanNode;
// set sortDirection here becase it might be used for IN list
scanNode.setSortDirection(path.sortDirection);
// Build the list of search-keys for the index in question
// They are the rhs expressions of the normalized indexExpr comparisons.
for (AbstractExpression expr : path.indexExprs) {
AbstractExpression expr2 = expr.getRight();
assert(expr2 != null);
if (expr.getExpressionType() == ExpressionType.COMPARE_IN) {
// Replace this method's result with an injected NLIJ.
resultNode = injectIndexedJoinWithMaterializedScan(expr2, scanNode);
// Extract a TVE from the LHS MaterializedScan for use by the IndexScan in its new role.
MaterializedScanPlanNode matscan = (MaterializedScanPlanNode)resultNode.getChild(0);
AbstractExpression elemExpr = matscan.getOutputExpression();
assert(elemExpr != null);
// Replace the IN LIST condition in the end expression referencing all the list elements
// with a more efficient equality filter referencing the TVE for each element in turn.
replaceInListFilterWithEqualityFilter(path.endExprs, expr2, elemExpr);
// Set up the similar VectorValue --> TVE replacement of the search key expression.
expr2 = elemExpr;
}
scanNode.addSearchKeyExpression(expr2);
}
// create the IndexScanNode with all its metadata
scanNode.setLookupType(path.lookupType);
scanNode.setBindings(path.bindings);
scanNode.setEndExpression(ExpressionUtil.combine(path.endExprs));
scanNode.setPredicate(ExpressionUtil.combine(path.otherExprs));
// The initial expression is needed to control a (short?) forward scan to adjust the start of a reverse
// iteration after it had to initially settle for starting at "greater than a prefix key".
scanNode.setInitialExpression(ExpressionUtil.combine(path.initialExpr));
scanNode.setSkipNullPredicate();
return resultNode;
}