Skip to content

Commit

Permalink
[fix](Nereids) mv in select materialized_view should disable show tab…
Browse files Browse the repository at this point in the history
…le (#24104)

mv in select materialized_view should disable show table,
because Nereids planner can output the string such as
slot#[0] in toSql() of SlotRef. Note this is only a
temporary solution, will use an expression translator later
  • Loading branch information
keanji-x authored and morrySnow committed Sep 11, 2023
1 parent 2bede8d commit 3624057
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.WhenClause;
import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
import org.apache.doris.nereids.trees.expressions.functions.agg.Ndv;
Expand Down Expand Up @@ -98,10 +99,16 @@ protected boolean containAllRequiredColumns(MaterializedIndex index, LogicalOlap
OlapTable table = scan.getTable();
MaterializedIndexMeta meta = table.getIndexMetaByIndexId(index.getId());

Set<String> predicateExprSql = predicateExpr.stream().map(e -> e.toSql()).collect(Collectors.toSet());
Set<String> predicateExprSql = predicateExpr.stream().map(ExpressionTrait::toSql).collect(Collectors.toSet());

// Here we use toSqlWithoutTbl because the output of toSql() is slot#[0] in Nereids
Set<String> indexConjuncts = PlanNode.splitAndCompoundPredicateToConjuncts(meta.getWhereClause()).stream()
.map(e -> {
e.setDisableTableName(true);
return e;
})
.map(e -> new NereidsParser().parseExpression(e.toSql()).toSql()).collect(Collectors.toSet());
Set<String> commonConjuncts = indexConjuncts.stream().filter(e -> predicateExprSql.contains(e))
Set<String> commonConjuncts = indexConjuncts.stream().filter(predicateExprSql::contains)
.collect(Collectors.toSet());
if (commonConjuncts.size() != indexConjuncts.size()) {
return false;
Expand Down Expand Up @@ -425,7 +432,12 @@ protected SlotContext generateBaseScanExprToMvExpr(LogicalOlapScan mvPlan) {

return new SlotContext(baseSlotToMvSlot, mvNameToMvSlot,
PlanNode.splitAndCompoundPredicateToConjuncts(meta.getWhereClause()).stream()
.map(e -> new NereidsParser().parseExpression(e.toSql())).collect(Collectors.toSet()));
.map(e -> {
e.setDisableTableName(true);
return e;
})
.map(e -> new NereidsParser().parseExpression(e.toSql()))
.collect(Collectors.toSet()));
}

/** SlotContext */
Expand Down
Loading

0 comments on commit 3624057

Please sign in to comment.