kadirozde commented on code in PR #1701:
URL: https://github.com/apache/phoenix/pull/1701#discussion_r1375086255
##########
phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java:
##########
@@ -197,17 +199,41 @@ private List<QueryPlan> getApplicablePlans(QueryPlan
dataPlan, PhoenixStatement
return Collections.singletonList(compiler.compile());
}
+ private static boolean isPartialIndexUsable(SelectStatement select,
QueryPlan dataPlan,
+ PTable index) throws SQLException {
+
+ StatementContext context = new StatementContext(dataPlan.getContext());
+ context.setResolver(FromCompiler.getResolver(dataPlan.getTableRef()));
+ return WhereCompiler.contains(
+
index.getIndexWhereExpression(dataPlan.getContext().getConnection()),
+ WhereCompiler.transformDNF(select.getWhere(), context));
+ }
+
private List<QueryPlan> getApplicablePlansForSingleFlatQuery(QueryPlan
dataPlan, PhoenixStatement statement, List<? extends PDatum> targetColumns,
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws
SQLException {
SelectStatement select = (SelectStatement)dataPlan.getStatement();
// Exit early if we have a point lookup as we can't get better than
that
if (dataPlan.getContext().getScanRanges().isPointLookup() &&
stopAtBestPlan && dataPlan.isApplicable()) {
return Collections.<QueryPlan> singletonList(dataPlan);
}
-
- List<PTable>indexes =
Lists.newArrayList(dataPlan.getTableRef().getTable().getIndexes());
- if (dataPlan.isApplicable() && (indexes.isEmpty() ||
dataPlan.isDegenerate() || dataPlan.getTableRef().hasDynamicCols() ||
select.getHint().hasHint(Hint.NO_INDEX))) {
+ List<PTable> indexList =
dataPlan.getTableRef().getTable().getIndexes();
+ if (dataPlan.isApplicable() &&
+ (indexList.isEmpty() ||
+ dataPlan.isDegenerate() ||
+ dataPlan.getTableRef().hasDynamicCols() ||
+ select.getHint().hasHint(Hint.NO_INDEX))) {
return Collections.<QueryPlan> singletonList(dataPlan);
}
+ // Include full indexes, and usable partial indexes
+ List<PTable> indexes = new ArrayList<>(indexList.size());
+ for (PTable index : indexList) {
+ if (index.getIndexWhere() != null) {
+ if (isPartialIndexUsable(select, dataPlan, index)) {
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]