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

Remove the redundant copy of join key column #9057

Closed
gengliqi opened this issue May 16, 2024 · 0 comments · Fixed by #9058
Closed

Remove the redundant copy of join key column #9057

gengliqi opened this issue May 16, 2024 · 0 comments · Fixed by #9058
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@gengliqi
Copy link
Contributor

Enhancement

if (!has_actions && (!left || is_right_out_join))
{
/// if the join key is a columnRef, then add a new column as the join key if needed.
/// In ClickHouse, the columns returned by join are: join_keys, left_columns and right_columns
/// where left_columns and right_columns don't include the join keys if they are ColumnRef
/// In TiDB, the columns returned by join are left_columns, right_columns, if the join keys
/// are ColumnRef, they will be included in both left_columns and right_columns
/// E.g, for table t1(id, value), t2(id, value) and query select * from t1 join t2 on t1.id = t2.id
/// In ClickHouse, it returns id,t1_value,t2_value
/// In TiDB, it returns t1_id,t1_value,t2_id,t2_value
/// So in order to make the join compatible with TiDB, if the join key is a columnRef, for inner/left
/// join, add a new key for right join key, for right join, add new key for both left and right join key
String updated_key_name = unique_name_generator.toUniqueName((left ? "_l_k_" : "_r_k_") + key_name);

As the comments above said, the schema returned by join in ClickHouse is different from TiDB. To make them consistent, TiFlash copied the join key column for the left side(if it's right outer join) and right side.
Although this copy is a shadow copy, it introduced unnecessary logic and made the code complex.
We can change the schema of join and remove the redundant copy of join key column because it's not difficult.

@gengliqi gengliqi added the type/enhancement The issue or PR belongs to an enhancement. label May 16, 2024
ti-chi-bot bot added a commit that referenced this issue May 27, 2024
close #9057

Signed-off-by: gengliqi <gengliqiii@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant