use of io.crate.analyze.where.EqualityExtractor in project crate by crate.
the class WhereClauseOptimizer method optimize.
public static DetailedQuery optimize(EvaluatingNormalizer normalizer, Symbol query, DocTableInfo table, TransactionContext txnCtx, NodeContext nodeCtx) {
Symbol queryGenColsProcessed = GeneratedColumnExpander.maybeExpand(query, table.generatedColumns(), Lists2.concat(table.partitionedByColumns(), Lists2.map(table.primaryKey(), table::getReference)), nodeCtx);
if (!query.equals(queryGenColsProcessed)) {
query = normalizer.normalize(queryGenColsProcessed, txnCtx);
}
WhereClause.validateVersioningColumnsUsage(query);
boolean versionInQuery = Symbols.containsColumn(query, DocSysColumns.VERSION);
boolean sequenceVersioningInQuery = Symbols.containsColumn(query, DocSysColumns.SEQ_NO) && Symbols.containsColumn(query, DocSysColumns.PRIMARY_TERM);
List<ColumnIdent> pkCols = pkColsInclVersioning(table, versionInQuery, sequenceVersioningInQuery);
EqualityExtractor eqExtractor = new EqualityExtractor(normalizer);
List<List<Symbol>> pkValues = eqExtractor.extractExactMatches(pkCols, query, txnCtx);
int clusterIdxWithinPK = table.primaryKey().indexOf(table.clusteredBy());
final DocKeys docKeys;
if (pkValues == null) {
docKeys = null;
} else {
List<Integer> partitionIndicesWithinPks = null;
if (table.isPartitioned()) {
partitionIndicesWithinPks = getPartitionIndices(table.primaryKey(), table.partitionedBy());
}
docKeys = new DocKeys(pkValues, versionInQuery, sequenceVersioningInQuery, clusterIdxWithinPK, partitionIndicesWithinPks);
}
List<List<Symbol>> partitionValues = null;
if (table.isPartitioned()) {
partitionValues = eqExtractor.extractExactMatches(table.partitionedBy(), query, txnCtx);
}
Set<Symbol> clusteredBy = Collections.emptySet();
if (table.clusteredBy() != null) {
List<List<Symbol>> clusteredByValues = eqExtractor.extractParentMatches(Collections.singletonList(table.clusteredBy()), query, txnCtx);
if (clusteredByValues != null) {
clusteredBy = new HashSet<>(clusteredByValues.size());
for (List<Symbol> s : clusteredByValues) {
clusteredBy.add(s.get(0));
}
}
}
WhereClauseValidator.validate(query);
return new DetailedQuery(query, docKeys, partitionValues, clusteredBy);
}
Aggregations