Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -502,7 +503,8 @@ AGGREGATE KEY (siteid,citycode,username)
if (getTable() instanceof MTMV) {
MTMV mtmv = (MTMV) getTable();
MTMVCache cache = mtmv.getCache();
if (cache == null) {
// Maybe query specified index, should not calc, such as select count(*) from t1 index col_index
if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) {
return;
}
Plan originalPlan = cache.getOriginalPlan();
Expand All @@ -528,7 +530,8 @@ public void computeUniform(DataTrait.Builder builder) {
if (getTable() instanceof MTMV) {
MTMV mtmv = (MTMV) getTable();
MTMVCache cache = mtmv.getCache();
if (cache == null) {
// Maybe query specified index, should not calc, such as select count(*) from t1 index col_index
if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) {
return;
}
Plan originalPlan = cache.getOriginalPlan();
Expand All @@ -542,7 +545,8 @@ public void computeEqualSet(DataTrait.Builder builder) {
if (getTable() instanceof MTMV) {
MTMV mtmv = (MTMV) getTable();
MTMVCache cache = mtmv.getCache();
if (cache == null) {
// Maybe query specified index, should not calc, such as select count(*) from t1 index col_index
if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) {
return;
}
Plan originalPlan = cache.getOriginalPlan();
Expand All @@ -556,7 +560,8 @@ public void computeFd(DataTrait.Builder builder) {
if (getTable() instanceof MTMV) {
MTMV mtmv = (MTMV) getTable();
MTMVCache cache = mtmv.getCache();
if (cache == null) {
// Maybe query specified index, should not calc, such as select count(*) from t1 index col_index
if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) {
return;
}
Plan originalPlan = cache.getOriginalPlan();
Expand All @@ -567,9 +572,23 @@ public void computeFd(DataTrait.Builder builder) {

Map<Slot, Slot> constructReplaceMap(MTMV mtmv) {
Map<Slot, Slot> replaceMap = new HashMap<>();
List<Slot> originOutputs = mtmv.getCache().getOriginalPlan().getOutput();
for (int i = 0; i < getOutput().size(); i++) {
replaceMap.put(originOutputs.get(i), getOutput().get(i));
// Need remove invisible column, and then mapping them
List<Slot> originOutputs = new ArrayList<>();
for (Slot originSlot : mtmv.getCache().getOriginalPlan().getOutput()) {
if (!(originSlot instanceof SlotReference) || (((SlotReference) originSlot).isVisible())) {
originOutputs.add(originSlot);
}
}
List<Slot> targetOutputs = new ArrayList<>();
for (Slot targeSlot : getOutput()) {
if (!(targeSlot instanceof SlotReference) || (((SlotReference) targeSlot).isVisible())) {
targetOutputs.add(targeSlot);
}
}
Preconditions.checkArgument(originOutputs.size() == targetOutputs.size(),
"constructReplaceMap, the size of originOutputs and targetOutputs should be same");
for (int i = 0; i < targetOutputs.size(); i++) {
replaceMap.put(originOutputs.get(i), targetOutputs.get(i));
}
return replaceMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ PhysicalResultSink
--hashAgg[GLOBAL]
----hashAgg[LOCAL]
------hashJoin[INNER_JOIN] hashCondition=((t1.l_orderkey = orders.o_orderkey) and (t1.l_shipdate = orders.o_orderdate)) otherCondition=()
--------filter((t1.l_shipdate = '2023-12-09'))
----------PhysicalOlapScan[lineitem]
--------filter((orders.o_orderdate = '2023-12-09') and (orders.o_shippriority = 1) and (orders.o_totalprice = 11.50))
----------PhysicalOlapScan[orders]
--------filter((t1.l_shipdate = '2023-12-09'))
----------PhysicalOlapScan[lineitem]

-- !query7_1_after --
yy 4 11.50 11.50 11.50 1
Expand Down
6 changes: 5 additions & 1 deletion regression-test/data/nereids_syntax_p0/mv/ut/MVWithAs.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
-- !select_star --
2020-01-01 1 a 1
2020-01-01 1 a 1
2020-01-01 1 a 1
2020-01-01 1 a 1
2020-01-02 2 b 2
2020-01-02 2 b 2
2020-01-02 2 b 2

-- !select_mv --
3
7

Loading