Skip to content

Multi-JOIN allows to use a column with a wrong table specifier. #23162

Closed

Description

@den-crane

21.5.1.6434

CREATE TABLE t1 ( k Int64, x Int64) ENGINE = Memory;

CREATE TABLE t2( x Int64 ) ENGINE = Memory;

create table s (k Int64, d DateTime)  Engine=Memory;

SELECT * FROM t1
INNER JOIN s ON t1.k = s.k
INNER JOIN t2 ON t2.x = t1.x
WHERE (t1.d >= now());

Ok.

But t1 does not have d column.
Expected behavior : DB::Exception: There's no column 't1.d' in table 't1'

Lets join only 2 tables:

SELECT * FROM t1
INNER JOIN s ON t1.k = s.k
WHERE (t1.d >= now());

DB::Exception: There's no column 't1.d' in table 't1'

Activity

  1. added
    bug
    on Apr 15, 2021
  2. changed the title [-]JOIN allows to use a column with a wrong table specifier.[/-] [+]Multi-JOIN allows to use a column with a wrong table specifier.[/+] on Apr 15, 2021
  3. hexiaoting commented on Apr 16, 2021

    @hexiaoting
    Contributor

    I will try to fix this.

  4. alexey-milovidov commented on Jun 17, 2021

    @alexey-milovidov
    Member
  5. added
    comp-joins
    on Oct 4, 2021
  6. beijishiqidu commented on Sep 13, 2022

    @beijishiqidu

    Is this problem fixed now? What's the PR? Thank you very much.

  7. vdimir commented on Sep 14, 2022

    @vdimir
    Member

    Is this problem fixed now? What's the PR? Thank you very much.

    Would be fixed in #31796

    :) SET use_analyzer = 1;
    
    :) SELECT * FROM t1 INNER JOIN s ON t1.k = s.k WHERE (t1.d >= now());
    
    0 rows in set. Elapsed: 0.015 sec. 
    
    Received exception from server (version 22.9.1):
    Code: 36. DB::Exception: Received from localhost:9000. DB::Exception: Identifier t1.d cannot be resolved from table with name default.t1. In scope SELECT * FROM t1 INNER JOIN s ON t1.k = s.k WHERE t1.d >= now(). (BAD_ARGUMENTS)
    
    :) SELECT * FROM t1 INNER JOIN s ON t1.k = s.k INNER JOIN t2 ON t2.x = t1.x WHERE (t1.d >= now());
    
    0 rows in set. Elapsed: 0.015 sec. 
    
    Received exception from server (version 22.9.1):
    Code: 36. DB::Exception: Received from localhost:9000. DB::Exception: Identifier t1.d cannot be resolved from table with name default.t1. In scope SELECT * FROM t1 INNER JOIN s ON t1.k = s.k INNER JOIN t2 ON t2.x = t1.x WHERE t1.d >= now(). (BAD_ARGUMENTS)
    
  8. beijishiqidu commented on Sep 22, 2022

    @beijishiqidu

    @vdimir

    Thank you, my friend. But I see that this is not merged, Can we use it directly? Because he changed too many files.

  9. vdimir commented on Sep 22, 2022

    @vdimir
    Member

    @beijishiqidu This is design related issue. That's why it's fixed in PR with so many changes. Merging and integrating the new query analyzing approach would take some time (it would be disabled by default first). You can experiment with the build from the PR, but we do not recommend using it in the production (I suppose because this problem is about not throwing an exception in the case where it should, it shouldn't be so critical, or not?)

  10. beijishiqidu commented on Sep 22, 2022

    @beijishiqidu

    @vdimir I think I understand what you're saying. This is a new query capability, and it may have fixed the problem I had. But I actually found the answer in another issue, and I'm ready to try it. Thank you, my friend;

    #26899

  11. beijishiqidu commented on Sep 26, 2022

    @beijishiqidu

    @vdimir I found that this PR only fixed their problem, not the current one. #26899, have you any idea for current issue?

  12. vdimir commented on Sep 26, 2022

    @vdimir
    Member

    @beijishiqidu

    Could you give reproducible example for your issue?

    I've tested query

    SELECT * FROM t1
    INNER JOIN s ON t1.k = s.k
    INNER JOIN t2 ON t2.x = t1.x
    WHERE (t1.d >= now());

    from the original comment in this issue #23162 (comment)

    Probably your case is a bit different?

  13. beijishiqidu commented on Sep 26, 2022

    @beijishiqidu

    @vdimir yes, but in this demo, you can see the table 't1' does not have column 'd', but this sql also can be executed successful, I think this is abnormal, am I right?

    The following SQL statement is used to reproduce the problem.

    CREATE DATABASE TEST_DATABASE;
    
    CREATE TABLE TEST_DATABASE.SDR_TEST (
     `COM_FAIL_CAUSE` Nullable(String), 
     `SIP_RELEASE_CODE` Nullable(String), 
     `VONR_MO_CALL_CONN_FAIL_TIMES` Nullable(Int64)
    ) ENGINE=MergeTree ORDER BY tuple() SETTINGS index_granularity = 8192
    
    CREATE TABLE TEST_DATABASE.DIM_TEST (
     `FAILCAUSE` Nullable(String), 
     `PROTOCOL_ID` Nullable(String), 
     `PROTOCOL_TYPE` Nullable(String), 
     `PD_ID` Nullable(String), 
     `PD` Nullable(String), 
     `FIRFAILMSG_ID` Nullable(String), 
     `CAUSE_ID` Nullable(String), 
     `CAUSE` Nullable(String), 
     `CLASS_ID` Nullable(String), 
     `SCENE_ID` Nullable(String), 
     `SCENE_NAME` Nullable(String), 
     `UNIFIED_CAUSE_ID` Nullable(String)
    ) ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 8192
    
    SELECT * FROM (
       SELECT (
         SUM(
           COALESCE(
             SEQ_VONR_MO_CALL_CONN_FAIL_TIMES_C, 
             0 
          ) 
        ) 
      ) AS VONR_MO_CALL_CONN_FAIL_TIMES, 
       MT."102520001" AS "102520001", 
       MT."181361814368" AS "181361814368", 
       MT."102520102" AS "102520102", 
       MT."102520101" AS "102520101", 
       MT."102520104" AS "102520104", 
       MT."183111861371" AS "183111861371", 
       MT."102530101" AS "102530101", 
       MT."102540101" AS "102540101", 
       MT."102520103" AS "102520103", 
       MT."102510101" AS "102510101"  FROM  (
         SELECT COALESCE(
           SUM("VONR_MO_CALL_CONN_FAIL_TIMES"), 
           0 
        ) AS SEQ_VONR_MO_CALL_CONN_FAIL_TIMES_C, 
         "COM_FAIL_CAUSE" AS "102520001", 
         NULL AS "102520102", 
         "COM_FAIL_CAUSE" AS "102510101", 
         NULL AS "102520101", 
         D183111570684_H101."183111861371" AS "183111861371", 
         NULL AS "102520104", 
         NULL AS "102520103", 
         H_COMPREHENSIVE_FAILURE_CAUSE."102540101" AS "102540101", 
         H_COMPREHENSIVE_FAILURE_CAUSE."102530101" AS "102530101", 
         '14' || '-' || '255' || '-' || '255' || '-' || "SIP_RELEASE_CODE" AS "181361814368"  FROM TEST_DATABASE."SDR_TEST"  
        LEFT JOIN (
           SELECT "PROTOCOL_ID" || '-' || "FIRFAILMSG_ID" || '-' || "PD_ID" || '-' || "CAUSE_ID" AS "102510101", 
           "UNIFIED_CAUSE_ID" AS "183111861371", 
           "FAILCAUSE" || '(' || "PD" || ')' AS NAME_102510101 FROM TEST_DATABASE."DIM_TEST"  GROUP BY "PROTOCOL_ID" || '-' || "FIRFAILMSG_ID" || '-' || "PD_ID" || '-' || "CAUSE_ID", 
           "UNIFIED_CAUSE_ID",  "FAILCAUSE" || '(' || "PD" || ')' 
        ) D183111570684_H101 ON "COM_FAIL_CAUSE" = D183111570684_H101."102510101"  
        LEFT JOIN (
           SELECT "PROTOCOL_ID" || '-' || "FIRFAILMSG_ID" || '-' || "PD_ID" || '-' || "CAUSE_ID" AS "102520001", 
           "SCENE_ID" AS "102540101",  "CLASS_ID" AS "102530101", 
           "SCENE_NAME" AS NAME_102540101 FROM TEST_DATABASE."DIM_TEST"  GROUP BY "PROTOCOL_ID" || '-' || "FIRFAILMSG_ID" || '-' || "PD_ID" || '-' || "CAUSE_ID", 
           "SCENE_ID",  "CLASS_ID",  "SCENE_NAME" 
        ) H_COMPREHENSIVE_FAILURE_CAUSE ON "COM_FAIL_CAUSE" = H_COMPREHENSIVE_FAILURE_CAUSE."102520001"  
        LEFT JOIN (
           SELECT "PROTOCOL_ID" || '-' || "FIRFAILMSG_ID" || '-' || "PD_ID" || '-' || "CAUSE_ID" AS "181361814368", 
           "CAUSE" AS NAME_181361814368 FROM TEST_DATABASE."DIM_TEST"  GROUP BY "PROTOCOL_ID" || '-' || "FIRFAILMSG_ID" || '-' || "PD_ID" || '-' || "CAUSE_ID", 
           "CAUSE" 
        ) DIM_FAILCAUSE_ALL_181361814368 ON '14' || '-' || '255' || '-' || '255' || '-' || "SIP_RELEASE_CODE" = DIM_FAILCAUSE_ALL_181361814368."181361814368"  WHERE (
           H_COMPREHENSIVE_FAILURE_CAUSE.NAME_102540101 IS NOT NULL 
          AND D183111570684_H101.NAME_102510101 IS NOT NULL  
          AND DIM_FAILCAUSE_ALL_181361814368.NAME_181361814368 IS NOT NULL 
        )  GROUP BY "102520001", 
         "102520102", 
         "102510101", 
         "102520101", 
         D183111570684_H101."183111861371", 
         "102520104", 
         "102520103", 
         H_COMPREHENSIVE_FAILURE_CAUSE."102540101", 
         H_COMPREHENSIVE_FAILURE_CAUSE."102530101", 
         "181361814368" 
      ) MT GROUP BY MT."102520001", 
       MT."181361814368", 
       MT."102520102", 
       MT."102520101", 
       MT."102520104", 
       MT."183111861371", 
       MT."102530101", 
       MT."102540101", 
       MT."102520103", 
       MT."102510101" 
    ) ST WHERE ST.VONR_MO_CALL_CONN_FAIL_TIMES > 0 ORDER BY VONR_MO_CALL_CONN_FAIL_TIMES DESC limit 5000 offset 0

    The command output is as follows:

    Code: 47. DB::Exception: Received from 127.0.0.1:9120. DB::Exception: Missing columns: '102510101' while processing query: 'SELECT COM_FAIL_CAUSE, SIP_RELEASE_CODE, VONR_MO_CALL_CONN_FAIL_TIMES, NAME_102510101, `102510101`, D183111570684_H101.`102510101` AS `--D183111570684_H101.102510101`, D183111570684_H101.`183111861371` AS `--D183111570684_H101.183111861371` FROM SEC_SDR_CS.SDR_VONR_IMS_TER_FAIL_15MIN_CB14_19257 ALL LEFT JOIN (SELECT concat(PROTOCOL_ID, '-', FIRFAILMSG_ID, '-', PD_ID, '-', CAUSE_ID) AS `102510101`, UNIFIED_CAUSE_ID AS `183111861371`, concat(FAILCAUSE, '(', PD, ')') AS NAME_102510101 FROM TEST_DATABASE.DIM_TEST GROUP BY concat(PROTOCOL_ID, '-', FIRFAILMSG_ID, '-', PD_ID, '-', CAUSE_ID), UNIFIED_CAUSE_ID, concat(FAILCAUSE, '(', PD, ')')) AS D183111570684_H101 ON COM_FAIL_CAUSE = `--D183111570684_H101.102510101`', required columns: 'SIP_RELEASE_CODE' 'VONR_MO_CALL_CONN_FAIL_TIMES' 'COM_FAIL_CAUSE' 'NAME_102510101' '102510101' 'D183111570684_H101.102510101' 'D183111570684_H101.183111861371', maybe you meant: ['SIP_RELEASE_CODE','VONR_MO_CALL_CONN_FAIL_TIMES','COM_FAIL_CAUSE'], joined columns: 'D183111570684_H101.102510101' 'D183111570684_H101.183111861371' 'NAME_102510101'.

    but this sql can be execute successful in version of 20.3.2.1, but when I upgrade to 21.8.8.29, I faced this issue;

    at the beginning, I think #26899 have fixed this issue, and I upgrade the patch, I found the patch has fixed the issue in 26899, but still not fixed my issue;

  14. alexey-milovidov commented on Mar 20, 2023

    @alexey-milovidov
    Member

    @beijishiqidu this large query is fixed by SET allow_experimental_analyzer = 1
    We will close this issue after enabling the Analyzer by default.

  15. added a commit that references this issue on Mar 20, 2023
  16. added a commit that references this issue on Mar 21, 2023
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

    bugcomp-joins

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions