[fix](planner) fix unrequired slot bug when join node introduced by #25204 (#34923)

before fix, join node will retain some slots, which are not materialized and unrequired.
join node need remove these slots and not make them be output slots.

Signed-off-by: nextdreamblue <zxw520blue1@163.com>
This commit is contained in:
xueweizhang
2024-05-17 18:07:31 +08:00
committed by yiguolei
parent 435147d449
commit a59f9c3fa1
3 changed files with 96 additions and 3 deletions

View File

@ -171,6 +171,9 @@ public abstract class JoinNodeBase extends PlanNode {
boolean needSetToNullable =
getChild(0) instanceof JoinNodeBase && analyzer.isOuterJoined(leftTupleDesc.getId());
for (SlotDescriptor leftSlotDesc : leftTupleDesc.getSlots()) {
if (!isMaterializedByChild(leftSlotDesc, getChild(0).getOutputSmap())) {
continue;
}
SlotDescriptor outputSlotDesc =
analyzer.getDescTbl().copySlotDescriptor(outputTupleDesc, leftSlotDesc);
if (leftNullable) {
@ -191,6 +194,9 @@ public abstract class JoinNodeBase extends PlanNode {
boolean needSetToNullable =
getChild(1) instanceof JoinNodeBase && analyzer.isOuterJoined(rightTupleDesc.getId());
for (SlotDescriptor rightSlotDesc : rightTupleDesc.getSlots()) {
if (!isMaterializedByChild(rightSlotDesc, getChild(1).getOutputSmap())) {
continue;
}
SlotDescriptor outputSlotDesc =
analyzer.getDescTbl().copySlotDescriptor(outputTupleDesc, rightSlotDesc);
if (rightNullable) {

View File

@ -14,9 +14,9 @@
3
-- !select5 --
1
2
3
1.0
2.0
3.0
-- !select5 --
1
@ -29,3 +29,6 @@
-- !select5 --
3
-- !select6 --
2020-01-01

View File

@ -665,4 +665,88 @@ suite("test_inlineview_with_project") {
sql """DROP TABLE IF EXISTS `dr_user_test_t1`;"""
sql """DROP TABLE IF EXISTS `dr_user_test_t2`;"""
sql """
drop table if exists dws_mf_wms_join_t1;
"""
sql """
drop table if exists dws_mf_wms_join_t2;
"""
sql """CREATE TABLE `dws_mf_wms_join_t1` (
`ddate` DATE NULL COMMENT '日期字段',
`game_id` VARCHAR(65533) NULL,
`main_currency_stock` BIGINT NULL
) ENGINE=OLAP
DUPLICATE KEY(`ddate`)
DISTRIBUTED BY HASH(`ddate`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);"""
sql """CREATE TABLE `dws_mf_wms_join_t2` (
`game_id` VARCHAR(65533) NULL,
) ENGINE=OLAP
DUPLICATE KEY(`game_id`)
DISTRIBUTED BY HASH(`game_id`) BUCKETS 10
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
);"""
sql """insert into dws_mf_wms_join_t1 values('2020-01-01','12345',100);"""
sql """insert into dws_mf_wms_join_t2 values('12345');"""
qt_select6 """SELECT
a1.ddate
FROM
(
SELECT
aaa.ddate
FROM
(
SELECT
aa.ddate,
CONCAT('main', aa.main_currency_stock) AS arr,
ROW_NUMBER() OVER (
PARTITION BY aa.ddate
) AS rn
FROM
(
SELECT
ddate,
main_currency_stock,
game_id
FROM
dws_mf_wms_join_t1 a
) aa
LEFT JOIN (
SELECT
game_id
FROM
dws_mf_wms_join_t2
) b ON aa.game_id = b.game_id
) aaa
CROSS JOIN (
select
1 as newarr
) b
WHERE
rn = 1
) a1
GROUP BY
GROUPING SETS (
(
a1.ddate
)
);"""
sql """
drop table if exists dws_mf_wms_join_join_t1;
"""
sql """
drop table if exists dws_mf_wms_join_join_t2;
"""
}