Skip to content

CH has to throw errors about ambiguous columns. #4567

Closed

Description

@den-crane

create table t(a Int64, b Int64) engine = TinyLog;
create table s(a Int64, b Int64) engine = TinyLog;

select a from t left outer join s on (t.b=s.b);

CH: 0 rows in set. Elapsed: 0.001 sec.
PG: ERROR: column reference "a" is ambiguous
mysql: ERROR 1052 (23000): Column 'a' in field list is ambiguous

select t.a from t left outer join s on (t.b=s.b) where a=1;

CH: 0 rows in set. Elapsed: 0.002 sec.
PG: ERROR: column reference "a" is ambiguous
mysql: ERROR 1052 (23000): Column 'a' in where clause is ambiguous

Activity

  1. added
    bug
    on Mar 3, 2019
  2. changed the title [-]CH have to through errors about ambiguous columns.[/-] [+]CH has to throw errors about ambiguous columns.[/+] on Mar 3, 2019
  3. self-assigned this
    on Mar 5, 2019
  4. den-crane commented on Mar 6, 2019

    @den-crane
    ContributorAuthor

    случайно сам наступил :) (забыв дописать **с.**color_key) и долго не мог понять в чем проблема с результатом (в большом тестовом примере (другом)) :)

    drop table fact;
    drop table animals;
    drop table colors;
    
    create table fact(id Int64, animal_key Int64, color_key Int64) Engine = MergeTree order by tuple();
    insert into fact values (1,1,1),(2,2,2);
    
    create table animals(animal_key UInt64, animal_name String) Engine = MergeTree order by tuple();
    insert into animals values (0, 'unknown');
    
    create table colors(color_key UInt64, color_name String) Engine = MergeTree order by tuple();
    insert into colors values (0, 'unknown');
    
    
    select  id, animal_name, a.animal_key, color_name, color_key
    from fact a
            left join (select toInt64(animal_key) animal_key, animal_name from animals) b on (a.animal_key = b.animal_key)
            left join (select toInt64(color_key) color_key, color_name from colors) c on (a.color_key = c.color_key)
    
    
    ┌─id─┬─animal_name─┬─a.animal_key─┬─color_name─┬─color_key─┐
    │  1 │ ᴺᵁᴸᴸ        │            1 │ ᴺᵁᴸᴸ       │         0 │
    │  2 │ ᴺᵁᴸᴸ        │            2 │ ᴺᵁᴸᴸ       │         0 │
    └────┴─────────────┴──────────────┴────────────┴───────────┘
    

    color_key внезапно вернулся для второй правой таблицы

    при этом для первой правой таблицы с animal_key такое не проходит.

    select  id, animal_name, animal_key, color_name, color_key
    from fact a
            left join (select toInt64(animal_key) animal_key, animal_name from animals) b on (a.animal_key = b.animal_key)
            left join (select toInt64(color_key) color_key, color_name from colors) c on (a.color_key = c.color_key)
    
    Code: 47. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Unknown identifier: animal_key,
    
  5. added
    comp-joins
    on May 11, 2019
  6. added and removed
    bug
    on Dec 24, 2019
  7. filimonov commented on Mar 5, 2020

    @filimonov
    Contributor

    Любопытно что MySQL / Postgres при использовании USING успешно разрешают конфликт про "двузначность" колонок самостоятельно, а если заменить на ON - нет.
    http://sqlfiddle.com/#!17/3d069/4

  8. den-crane commented on Mar 6, 2020

    @den-crane
    ContributorAuthor

    USING -- select * выбирает поля (по которым join) только из левой таблицы и поэтому в where как бы ссылаемся на левую таблицу, ровно так как это было в изначальном КХ.

    ON -- select * выбирает из обеих таблиц

  9. 4ertus2 commented on Mar 25, 2020

    @4ertus2
    Contributor

    related #5046 #10276

  10. 4ertus2 commented on Mar 25, 2020

    @4ertus2
    Contributor

    related but not fixed by #9739

  11. 4ertus2 commented on Jul 10, 2020

    @4ertus2
    Contributor

    One more case we should throw an error

    mysql> select k from (select 1 as k union all select 2 as k) s1 right join (select 1 as k union all
    select 0 as k) s2 on s1.k = s2.k;
    ERROR 1052 (23000): Column 'k' in field list is ambiguous
    
  12. removed their assignment
    on Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-joinsfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions