Skip to content

Wrong name qualification for the left table in GLOBAL JOIN #4879

Closed

Description

@dfulachier

CH version: 19.4.1.1

Using a cluster with a single node, one distributed table and one non-distributed, and a vstest database:

CREATE TABLE vstest.local_table(id Int32, name String, ts DateTime, oth_id Int32) ENGINE = MergeTree() PARTITION BY toMonday(ts) ORDER BY (ts, id);
CREATE TABLE vstest.dist_table(id Int32, name String, ts DateTime, oth_id Int32) ENGINE = Distributed(vscluster, vstest, local_table);
CREATE TABLE vstest.other_table(id Int32, name String, ts DateTime, trd_id Int32) ENGINE = MergeTree() PARTITION BY toMonday(ts) ORDER BY (ts, id);
INSERT INTO vstest.local_table VALUES(1, 'One', now(), 100);
INSERT INTO vstest.local_table VALUES(2, 'Two', now(), 200);
INSERT INTO vstest.other_table VALUES(100, 'One Hundred', now(), 1000);
INSERT INTO vstest.other_table VALUES(200, 'Two Hundred', now(), 2000);

The "local" join works fine:
select t2.name from dist_table as t1 left join other_table as t2 on t1.oth_id = t2.id

┌─t2.name─────┐
│ One Hundred │
│ Two Hundred │
└─────────────┘

But it is not the case when using the GLOBAL join:
select t2.name from dist_table as t1 GLOBAL left join other_table as t2 on t1.oth_id = t2.id

Getting an error:
Received exception from server (version 19.4.1):
Code: 47. DB::Exception: Received from localhost:19000, ::1. DB::Exception: Unknown identifier: t1.id, context: query: 'SELECT t1.name FROM dist_table AS t1 GLOBAL ALL LEFT JOIN _data1 ON oth_id = t1.id' required_names: 't1.id''t1.name''oth_id' source_tables: 't1'/'dist_table' '_data1' table_aliases: 't1' complex_aliases: masked_columns: array_join_columns: source_columns: 'oth_id' .

Activity

  1. added
    bug
    on Apr 2, 2019
  2. self-assigned this
    on Apr 2, 2019
  3. 4ertus2 commented on Apr 2, 2019

    @4ertus2
    Contributor

    We need some time to investigate the issue. As workaround you may try to set alias to the column or try to JOIN with USING instead of ON. It may help.

  4. 4ertus2 commented on Apr 10, 2019

    @4ertus2
    Contributor

    It looks like wrong name qualification. t2.id and t2.name unexpectedly became t1.id and t1.name.

    select t2.name from remote('127.0.0.2', 'test.local_table') as t1 global left join test.other_table as t2 on t1.oth_id = t2.id;
    
    Code: 47. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: Missing columns: 't1.id' 't1.name' while processing query: 'SELECT t1.name AS name FROM remote('127.0.0.2', 'test.local_table') AS t1  GLOBAL ALL LEFT JOIN _data1 ON oth_id = t1.id', required columns: 't1.name' 'oth_id' 't1.id', source columns: 'oth_id' 'ts' 'name' 'id', joined columns: '_data1.id' '_data1.name' '_data1.ts' 'trd_id'.
    
  5. 4ertus2 commented on Apr 10, 2019

    @4ertus2
    Contributor

    As workaround you may change the tables order in query:

    select t2.name from test.other_table as t2 global right join remote('127.0.0.2', 'test.local_table') as t1 on t1.oth_id = t2.id;
    
    Two Hundred
    One Hundred
    
  6. changed the title [-]"Unknown identifier" error when using GLOBAL join on distributed table[/-] [+]Wrong name qualification for the left table in GLOBAL JOIN[/+] on Apr 10, 2019
  7. dfulachier commented on Apr 10, 2019

    @dfulachier
    Author

    Thank you Artem for studying this bug, and for all your workaround proposals.
    None can be systematically applied. By instance, I am not sure the latest is transparent in term of performances (should we not always keep the large table on the left of join, and the small one on the right...?).
    This regression is quite annoying, I hope it may be fixed quickly.

  8. 4ertus2 commented on Apr 10, 2019

    @4ertus2
    Contributor

    should we not always keep the large table on the left of join, and the small one on the right...?

    You are right. It's not possible to save performance with the last workaround.

  9. 4ertus2 commented on Apr 10, 2019

    @4ertus2
    Contributor
  10. 4ertus2 commented on Apr 11, 2019

    @4ertus2
    Contributor

    fixed in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions