-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improvement](mtmv) Support to partition prune when query rewrite by sync materialized view #38527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import org.apache.doris.nereids.CascadesContext; | ||
import org.apache.doris.nereids.trees.plans.ObjectId; | ||
import org.apache.doris.nereids.trees.plans.Plan; | ||
import org.apache.doris.nereids.trees.plans.PreAggStatus; | ||
import org.apache.doris.nereids.trees.plans.RelationId; | ||
import org.apache.doris.nereids.trees.plans.algebra.Relation; | ||
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan; | ||
|
@@ -54,7 +55,8 @@ public class SyncMaterializationContext extends MaterializationContext { | |
public SyncMaterializationContext(Plan mvPlan, Plan mvOriginalPlan, OlapTable olapTable, | ||
long indexId, String indexName, CascadesContext cascadesContext, Statistics statistics) { | ||
super(mvPlan, mvOriginalPlan, | ||
MaterializedViewUtils.generateMvScanPlan(olapTable, indexId, cascadesContext), cascadesContext, null); | ||
MaterializedViewUtils.generateMvScanPlan(olapTable, indexId, olapTable.getPartitionIds(), | ||
PreAggStatus.unset(), cascadesContext), cascadesContext, null); | ||
this.olapTable = olapTable; | ||
this.indexId = indexId; | ||
this.indexName = indexName; | ||
|
@@ -63,7 +65,8 @@ public SyncMaterializationContext(Plan mvPlan, Plan mvOriginalPlan, OlapTable ol | |
|
||
@Override | ||
Plan doGenerateScanPlan(CascadesContext cascadesContext) { | ||
return MaterializedViewUtils.generateMvScanPlan(olapTable, indexId, cascadesContext); | ||
return MaterializedViewUtils.generateMvScanPlan(olapTable, indexId, olapTable.getPartitionIds(), | ||
PreAggStatus.unset(), cascadesContext); | ||
} | ||
|
||
@Override | ||
|
@@ -96,13 +99,29 @@ String getStringInfo() { | |
@Override | ||
Optional<Pair<Id, Statistics>> getPlanStatistics(CascadesContext cascadesContext) { | ||
RelationId relationId = null; | ||
Optional<LogicalOlapScan> scanObj = this.getScanPlan().collectFirst(LogicalOlapScan.class::isInstance); | ||
Optional<LogicalOlapScan> scanObj = this.getScanPlan(null) | ||
.collectFirst(LogicalOlapScan.class::isInstance); | ||
if (scanObj.isPresent()) { | ||
relationId = scanObj.get().getRelationId(); | ||
} | ||
return Optional.of(Pair.of(relationId, normalizeStatisticsColumnExpression(statistics))); | ||
} | ||
|
||
@Override | ||
public Plan getScanPlan(StructInfo queryStructInfo) { | ||
if (queryStructInfo == null) { | ||
return scanPlan; | ||
} | ||
if (queryStructInfo.getRelations().size() == 1 | ||
&& queryStructInfo.getRelations().get(0) instanceof LogicalOlapScan | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refer to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we can collect the private static class RelationCollector extends DefaultPlanVisitor<Void, List<CatalogRelation>> {
@Override
public Void visit(Plan plan, List<CatalogRelation> collectedRelations) {
if (plan instanceof CatalogRelation) {
collectedRelations.add((CatalogRelation) plan);
}
return super.visit(plan, collectedRelations);
}
} |
||
&& !((LogicalOlapScan) queryStructInfo.getRelations().get(0)).getSelectedPartitionIds().isEmpty() | ||
&& scanPlan instanceof LogicalOlapScan) { | ||
return ((LogicalOlapScan) scanPlan).withSelectedPartitionIds( | ||
((LogicalOlapScan) queryStructInfo.getRelations().get(0)).getSelectedPartitionIds()); | ||
} | ||
return scanPlan; | ||
} | ||
|
||
/** | ||
* Calc the relation is chosen finally or not | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !query1_before -- | ||
aa bc 2024-07-03T01:15:30 1 | ||
ad be 2024-07-03T07:06:30 1 | ||
af bf 2024-07-04T10:01:30 1 | ||
ag bc 2024-07-04T10:01:35 1 | ||
as bd 2024-07-03T01:15:30 1 | ||
|
||
-- !query1_after -- | ||
aa bc 2024-07-03T01:15:30 1 | ||
ad be 2024-07-03T07:06:30 1 | ||
af bf 2024-07-04T10:01:30 1 | ||
ag bc 2024-07-04T10:01:35 1 | ||
as bd 2024-07-03T01:15:30 1 | ||
|
||
-- !query2_before -- | ||
2024-07-03T01:00 aa bc | ||
2024-07-03T06:00 as bd | ||
2024-07-03T07:00 ad be | ||
2024-07-04T10:00 af bf | ||
2024-07-04T12:00 ag bc | ||
|
||
-- !query2_after -- | ||
2024-07-03T01:00 aa bc | ||
2024-07-03T06:00 as bd | ||
2024-07-03T07:00 ad be | ||
2024-07-04T10:00 af bf | ||
2024-07-04T12:00 ag bc | ||
|
||
-- !query3_before -- | ||
aa bc 2024-07-03T01:00 2.1 | ||
ad be 2024-07-03T07:00 3.1 | ||
af bf 2024-07-04T10:00 4.1 | ||
ag bc 2024-07-04T12:00 5.1 | ||
as bd 2024-07-03T06:00 1.1 | ||
|
||
-- !query3_after -- | ||
aa bc 2024-07-03T01:00 2.1 | ||
ad be 2024-07-03T07:00 3.1 | ||
af bf 2024-07-04T10:00 4.1 | ||
ag bc 2024-07-04T12:00 5.1 | ||
as bd 2024-07-03T06:00 1.1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be unset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the preAggStatus is variable.
it's is
unset
when sync materialization context and ison
when async materialization context