return queryGoal.getCostEstimator().conditionsSelectivity(selectivityConditions(index.getConditions(), index.getTables()));
}
// Conditions that might have a recognizable selectivity.
protected SelectivityConditions selectivityConditions(Collection<ConditionExpression> conditions, Collection<TableSource> requiredTables) {
SelectivityConditions result = new SelectivityConditions();
if (conditions == null) {
return result;
}
for (ConditionExpression condition : conditions) {
if (condition instanceof ComparisonCondition) {
ComparisonCondition ccond = (ComparisonCondition)condition;
if (ccond.getLeft() instanceof ColumnExpression) {
ColumnExpression column = (ColumnExpression)ccond.getLeft();
if ((column.getColumn() != null) &&
requiredTables.contains(column.getTable()) &&
constantOrBound(ccond.getRight())) {
result.addCondition(column, condition);
}
}
}
else if (condition instanceof InListCondition) {
InListCondition incond = (InListCondition)condition;
if (incond.getOperand() instanceof ColumnExpression) {
ColumnExpression column = (ColumnExpression)incond.getOperand();
if ((column.getColumn() != null) &&
requiredTables.contains(column.getTable())) {
boolean allConstant = true;
for (ExpressionNode expr : incond.getExpressions()) {
if (!constantOrBound(expr)) {
allConstant = false;
break;
}
}
if (allConstant) {
result.addCondition(column, condition);
}
}
}
}
}