-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature](mtmv) Support querying rewrite by materialized view when in…
…sert and insert overwrite dml (#38115) Support querying rewrite by materialized view when DML such as insert and insert overwrite , into outfile etc. this is default enable, you can disable it by `set enable_dml_materialized_view_rewrite = false` and the `enable_materialized_view_rewrite` is only control DQL. It would not rewrite by materialized view when query sql use external table. If you want rewrite by materialized view when use external table in DML, you should `set enable_dml_materialized_view_rewrite_when_base_table_unawareness = true;` this is default false.
- Loading branch information
Showing
33 changed files
with
1,008 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...ore/src/main/java/org/apache/doris/nereids/rules/analysis/AddInitMaterializationHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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. | ||
|
||
package org.apache.doris.nereids.rules.analysis; | ||
|
||
import org.apache.doris.nereids.rules.Rule; | ||
import org.apache.doris.nereids.rules.RuleType; | ||
import org.apache.doris.nereids.rules.exploration.mv.InitConsistentMaterializationContextHook; | ||
import org.apache.doris.nereids.trees.plans.logical.LogicalTableSink; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Add init materialization hook for table sink and file sink | ||
* */ | ||
public class AddInitMaterializationHook implements AnalysisRuleFactory { | ||
|
||
@Override | ||
public List<Rule> buildRules() { | ||
return ImmutableList.of( | ||
RuleType.INIT_MATERIALIZATION_HOOK_FOR_FILE_SINK.build(logicalFileSink() | ||
.thenApply(ctx -> { | ||
if (ctx.connectContext.getSessionVariable().isEnableDmlMaterializedViewRewrite()) { | ||
ctx.statementContext.addPlannerHook(InitConsistentMaterializationContextHook.INSTANCE); | ||
} | ||
return ctx.root; | ||
})), | ||
RuleType.INIT_MATERIALIZATION_HOOK_FOR_TABLE_SINK.build( | ||
any().when(LogicalTableSink.class::isInstance) | ||
.thenApply(ctx -> { | ||
if (ctx.connectContext.getSessionVariable().isEnableDmlMaterializedViewRewrite()) { | ||
ctx.statementContext.addPlannerHook(InitConsistentMaterializationContextHook.INSTANCE); | ||
} | ||
return ctx.root; | ||
})) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...g/apache/doris/nereids/rules/exploration/mv/InitConsistentMaterializationContextHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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. | ||
|
||
package org.apache.doris.nereids.rules.exploration.mv; | ||
|
||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.catalog.MTMV; | ||
import org.apache.doris.catalog.TableIf; | ||
import org.apache.doris.mtmv.BaseTableInfo; | ||
import org.apache.doris.mtmv.MTMVUtil; | ||
import org.apache.doris.nereids.CascadesContext; | ||
import org.apache.doris.nereids.PlannerHook; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* If enable query rewrite with mv in dml, should init consistent materialization context after analyze | ||
*/ | ||
public class InitConsistentMaterializationContextHook extends InitMaterializationContextHook implements PlannerHook { | ||
|
||
public static final InitConsistentMaterializationContextHook INSTANCE = | ||
new InitConsistentMaterializationContextHook(); | ||
|
||
@VisibleForTesting | ||
@Override | ||
public void initMaterializationContext(CascadesContext cascadesContext) { | ||
if (!cascadesContext.getConnectContext().getSessionVariable().isEnableDmlMaterializedViewRewrite()) { | ||
return; | ||
} | ||
super.doInitMaterializationContext(cascadesContext); | ||
} | ||
|
||
protected Set<MTMV> getAvailableMTMVs(Set<TableIf> usedTables, CascadesContext cascadesContext) { | ||
List<BaseTableInfo> usedBaseTables = | ||
usedTables.stream().map(BaseTableInfo::new).collect(Collectors.toList()); | ||
return Env.getCurrentEnv().getMtmvService().getRelationManager() | ||
.getAvailableMTMVs(usedBaseTables, cascadesContext.getConnectContext(), | ||
true, ((connectContext, mtmv) -> { | ||
return MTMVUtil.mtmvContainsExternalTable(mtmv) && (!connectContext.getSessionVariable() | ||
.isEnableDmlMaterializedViewRewriteWhenBaseTableUnawareness()); | ||
})); | ||
} | ||
} |
Oops, something went wrong.