[Bug](materialized-view) fix isDisableTuplesMVRewriter rreturn true when expr is literal (#18246)

fix isDisableTuplesMVRewriter rreturn true when expr is literal
This commit is contained in:
Pxl
2023-03-31 11:30:47 +08:00
committed by GitHub
parent 8e15388074
commit e7bcd970f5
5 changed files with 51 additions and 1 deletions

View File

@ -2201,6 +2201,12 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
public boolean matchExprs(List<Expr> exprs, SelectStmt stmt, boolean ignoreAlias, String tableName)
throws AnalysisException {
List<SlotRef> slots = new ArrayList<>();
collect(SlotRef.class, slots);
if (slots.size() == 0) {
return true;
}
String name = MaterializedIndexMeta.normalizeName(toSqlWithoutTbl());
for (Expr expr : exprs) {
if (CreateMaterializedViewStmt.isMVColumnNormal(name)

View File

@ -272,6 +272,9 @@ public abstract class QueryStmt extends StatementBase implements Queriable {
}
public boolean isDisableTuplesMVRewriter(Expr expr) {
if (disableTuplesMVRewriter.isEmpty()) {
return false;
}
return expr.isBoundByTupleIds(disableTuplesMVRewriter.stream().collect(Collectors.toList()));
}

View File

@ -1327,6 +1327,7 @@ public class SingleNodePlanner {
String errorMsg = "select fail reason: ";
if (queryStmt instanceof SelectStmt) {
SelectStmt selectStmt = (SelectStmt) queryStmt;
Set<TupleId> disableTuplesMVRewriter = Sets.newHashSet();
for (TableRef tableRef : selectStmt.getTableRefs()) {
if (tableRef instanceof InlineViewRef) {
selectFailed |= selectMaterializedView(((InlineViewRef) tableRef).getViewStmt(),
@ -1386,9 +1387,10 @@ public class SingleNodePlanner {
}
if (tupleSelectFailed) {
selectFailed = true;
selectStmt.updateDisableTuplesMVRewriter(olapScanNode.getTupleId());
disableTuplesMVRewriter.add(olapScanNode.getTupleId());
}
}
selectStmt.updateDisableTuplesMVRewriter(disableTuplesMVRewriter);
} else {
Preconditions.checkState(queryStmt instanceof SetOperationStmt);
SetOperationStmt unionStmt = (SetOperationStmt) queryStmt;

View File

@ -24,3 +24,29 @@
3 \N
3 \N
-- !select_mv --
-4 -4
-4 -4
-4 -4
-4 -4
1 1
2 2
3 -3
3 -3
3 -3
3 -3
3 -3
3 -3
3 -3
3 -3
3 -3
-- !select_mv --
-4 5.7.99
-4 5.7.99
1 5.7.99
2 5.7.99
3 5.7.99
3 5.7.99
3 5.7.99

View File

@ -56,4 +56,17 @@ suite ("multi_slot_k123p") {
contains "(k123p)"
}
qt_select_mv "select k1,k2+k3 from d_table order by k1;"
explain {
sql("select lhs.k1,rhs.k2 from d_table as lhs right join d_table as rhs on lhs.k1=rhs.k1;")
notContains "(k123p)"
notContains "`mv_"
}
qt_select_mv "select lhs.k1,rhs.k2 from d_table as lhs right join d_table as rhs on lhs.k1=rhs.k1 order by lhs.k1;"
explain {
sql("select k1,version() from d_table;")
contains "(k123p)"
}
qt_select_mv "select k1,version() from d_table order by k1;"
}