[Bug](Materialized-View) forbiden mv rewrite on create view and remove duplicate method getIsM… (#17194)

1. forbiden mv rewrite on create view to avoid select fail
2. remove duplicate method getIsMaterialized
This commit is contained in:
Pxl
2023-03-01 13:46:56 +08:00
committed by GitHub
parent ff8902370c
commit 62440f3140
7 changed files with 81 additions and 7 deletions

View File

@ -78,6 +78,7 @@ public class CreateViewStmt extends BaseViewStmt {
// Analyze view define statement
Analyzer viewAnalyzer = new Analyzer(analyzer);
viewDefStmt.forbiddenMVRewrite();
viewDefStmt.analyze(viewAnalyzer);
createColumnAndViewDefs(analyzer);

View File

@ -189,7 +189,7 @@ public class DescriptorTable {
for (TupleDescriptor tupleD : tupleDescs.values()) {
// inline view of a non-constant select has a non-materialized tuple descriptor
// in the descriptor table just for type checking, which we need to skip
if (tupleD.getIsMaterialized()) {
if (tupleD.isMaterialized()) {
result.addToTupleDescriptors(tupleD.toThrift());
// an inline view of a constant select has a materialized tuple
// but its table has no id

View File

@ -169,10 +169,6 @@ public class TupleDescriptor {
return byteSize;
}
public boolean getIsMaterialized() {
return isMaterialized;
}
public void setIsMaterialized(boolean value) {
isMaterialized = value;
}

View File

@ -134,7 +134,7 @@ public class TupleIsNullPredicate extends Predicate {
// Assert that all tids are materialized.
for (TupleId tid : tids) {
TupleDescriptor tupleDesc = analyzer.getTupleDesc(tid);
Preconditions.checkState(tupleDesc.getIsMaterialized());
Preconditions.checkState(tupleDesc.isMaterialized());
}
// Perform the wrapping.
List<Expr> result = Lists.newArrayListWithCapacity(inputExprs.size());

View File

@ -787,7 +787,7 @@ public class AnalyticPlanner {
for (WindowGroup g : windowGroups) {
TupleDescriptor outputTuple = g.physicalOutputTuple;
Preconditions.checkState(outputTuple.getIsMaterialized());
Preconditions.checkState(outputTuple.isMaterialized());
Preconditions.checkState(outputTuple.getByteSize() != -1);
totalOutputTupleSize += outputTuple.getByteSize();
}

View File

@ -0,0 +1,12 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select_star --
1 1 1 a
2 2 2 b
3 -3 \N c
-- !select_mv --
1 1 1
-- !select_mv --
1 1 a

View File

@ -0,0 +1,65 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import org.codehaus.groovy.runtime.IOGroovyMethods
suite ("mv_with_view") {
sql """ DROP TABLE IF EXISTS d_table; """
sql """
create table d_table (
k1 int null,
k2 int not null,
k3 bigint null,
k4 varchar(100) null
)
duplicate key (k1,k2,k3)
distributed BY hash(k1) buckets 3
properties("replication_num" = "1");
"""
sql """insert into d_table select 1,1,1,'a';"""
sql """insert into d_table select 2,2,2,'b';"""
createMV("create materialized view k132 as select k1,k3,k2 from d_table;")
sql """insert into d_table select 3,-3,null,'c';"""
explain {
sql("select * from d_table order by k1;")
contains "(d_table)"
}
qt_select_star "select * from d_table order by k1;"
sql """
create view v_k132 as select k1,k3,k2 from d_table where k1 = 1;
"""
explain {
sql("select * from v_k132 order by k1;")
contains "(k132)"
}
qt_select_mv "select * from v_k132 order by k1;"
sql """
create view v_k124 as select k1,k2,k4 from d_table where k1 = 1;
"""
explain {
sql("select * from v_k124 order by k1;")
contains "(d_table)"
}
qt_select_mv "select * from v_k124 order by k1;"
}