Skip to content
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

[fix](colocate) fix colocate join while multi tables #37729

Merged
merged 1 commit into from
Jul 15, 2024
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 @@ -325,12 +325,9 @@ public static boolean couldColocateJoin(DistributionSpecHash leftHashSpec, Distr

SlotReference leftSlot = (SlotReference) leftChild;
SlotReference rightSlot = (SlotReference) rightChild;
Integer leftIndex = null;
Integer rightIndex = null;
if (leftSlot.getTable().isPresent() && leftSlot.getTable().get().getId() == leftHashSpec.getTableId()) {
leftIndex = leftHashSpec.getExprIdToEquivalenceSet().get(leftSlot.getExprId());
rightIndex = rightHashSpec.getExprIdToEquivalenceSet().get(rightSlot.getExprId());
} else {
Integer leftIndex = leftHashSpec.getExprIdToEquivalenceSet().get(leftSlot.getExprId());
Integer rightIndex = rightHashSpec.getExprIdToEquivalenceSet().get(rightSlot.getExprId());
if (leftIndex == null) {
leftIndex = rightHashSpec.getExprIdToEquivalenceSet().get(leftSlot.getExprId());
rightIndex = leftHashSpec.getExprIdToEquivalenceSet().get(rightSlot.getExprId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,33 @@ suite("test_colocate_join_of_column_order") {

sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_t1`; """
sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_t2`; """

// multi tables
sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_ta`; """
sql """
CREATE TABLE IF NOT EXISTS `test_colocate_join_of_column_order_ta` ( `c1` bigint NULL, `c2` bigint NULL)
DISTRIBUTED BY HASH(c1) PROPERTIES ( "replication_num" = "1", "colocate_with" = "group_column_order3");
"""
sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_tb`; """
sql """
CREATE TABLE IF NOT EXISTS `test_colocate_join_of_column_order_tb` ( `c1` bigint NULL, `c2` bigint NULL)
DISTRIBUTED BY HASH(c1) PROPERTIES ( "replication_num" = "1", "colocate_with" = "group_column_order3");
"""
sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_tc`; """
sql """
CREATE TABLE IF NOT EXISTS `test_colocate_join_of_column_order_tc` ( `c1` bigint NULL, `c2` bigint NULL)
DISTRIBUTED BY HASH(c1) PROPERTIES ( "replication_num" = "1", "colocate_with" = "group_column_order3");
"""
sql """insert into test_colocate_join_of_column_order_ta values(1,1);"""
sql """insert into test_colocate_join_of_column_order_tb values(1,1);"""
sql """insert into test_colocate_join_of_column_order_tc values(1,1);"""

explain {
sql("""select /*+ set_var(disable_join_reorder=true) */ * from test_colocate_join_of_column_order_ta join [shuffle] (select cast((c2 + 1) as bigint) c2 from test_colocate_join_of_column_order_tb) test_colocate_join_of_column_order_tb on test_colocate_join_of_column_order_ta.c1 = test_colocate_join_of_column_order_tb.c2 join [shuffle] test_colocate_join_of_column_order_tc on test_colocate_join_of_column_order_tb.c2 = test_colocate_join_of_column_order_tc.c1;""");
contains "COLOCATE"
}

sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_ta`; """
sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_tb`; """
sql """ DROP TABLE IF EXISTS `test_colocate_join_of_column_order_tc`; """
}
Loading