Skip to content

Incorrect join with Merge engine #29838

Closed

Description

@orloffv

How to reproduce:

// first table with distributed
CREATE TABLE first_table_lr on cluster '{cluster}'
(
    id String,
    id2 String
) ENGINE = ReplicatedMergeTree()
ORDER BY id;


CREATE TABLE first_table on cluster '{cluster}'
(
    id String,
    id2 String
)
ENGINE = Distributed('{cluster}', 'default', 'first_table_lr');

// second table with distributed
CREATE TABLE second_table_lr on cluster '{cluster}'
(
    id String,
    id2 String
) ENGINE = MergeTree()
ORDER BY id;

CREATE TABLE second_table on cluster '{cluster}'
(
    id String,
    id2 String
)
ENGINE = Distributed('{cluster}', 'default', 'second_table_lr');

INSERT INTO first_table VALUES ('1', '2'), ('3', '4');
INSERT INTO second_table VALUES ('1', '2'), ('3', '4');

// Add merge engine table
CREATE TABLE two_tables
(
    id String,
    id2 String
)
ENGINE = Merge('default', '^(first_table)$')

Correct result
count() 2

SELECT 
    count()
FROM first_table as s
GLOBAL ANY JOIN second_table as f USING (id)
WHERE 
    f.id2 GLOBAL IN (
        SELECT
            id2
        FROM second_table
        GROUP BY id2
    );  

But if i use merge engine table(two_tables)
Result is not correct
count() 0

SELECT 
    count()
FROM two_tables as s
GLOBAL ANY JOIN second_table as f USING (id)
WHERE 
    f.id2 GLOBAL IN (
        SELECT
            id2
        FROM second_table
        GROUP BY id2
    ); 

I reproduce it on 21.9.4.35, 21.8.7.22 and 21.3.17.2 versions
On version 19.13.1.11 everything works correctly

Activity

  1. added
    potential bug
    on Oct 7, 2021
  2. self-assigned this
    on Oct 7, 2021
  3. added a commit that references this issue on Apr 3, 2024
  4. added
    bug
    and removed
    potential bug
    on Apr 3, 2024
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions