Skip to content

Select from Merge table (over MergeTree and Buffer) with two or more clauses in the Where throws exception #36963

Closed

Description

@SergeyKotyushkin

Describe what's wrong

Select from Merge table, which works with MergeTree table and Buffer table above MergeTree table, with two or more clauses in the Where, throws exception.

Does it reproduce on recent release?

v22.3.2.2-lts
v22.3.3.44-lts
v22.3.4.20-lts
v22.3.5.5-lts

(every 22.3 lts version)

How to reproduce

Use ClickHouse server 22.3.5.5 version.

-- create tables
create table mt1 (f1 Int32, f2 Int32) engine = MergeTree() order by f1;

create table mt2 as mt1 engine = MergeTree() order by f1;
create table b as mt1 engine = Buffer(currentDatabase(), mt2, 16, 1, 1, 10000, 1000000, 10000000, 100000000);

create table m as mt1 engine = Merge(currentDatabase(), '^(mt1|b)$');

-- insert some data
insert into mt1 values(1, 1), (2, 2);
insert into b   values(3, 3), (4, 4);

-- do select
select f1, f2
from m
where f1 = 1 and f2 = 1

Select throws exception:

Code: 44. DB::Exception: Cannot convert column `equals(f1, 1)` because it is non constant in source stream but must be constant in result. (ILLEGAL_COLUMN) (version 22.3.5.5 (official build))

The interesting part that no exceptions are thrown if the Where has only one clause:

select f1, f2
from m
where f1 = 1

-- f1|f2|
-- --+--+
--  1| 1|

select f1, f2
from m
where toUInt8(f1 = 1 and f2 = 1)

-- f1|f2|
-- --+--+
--  1| 1|

It's tested that type of column and function in the Where do not matter.

Expected behavior

Select completes without exceptions.

Error message and/or stacktrace

Code: 44. DB::Exception: Cannot convert column equals(f1, 1) because it is non constant in source stream but must be constant in result. (ILLEGAL_COLUMN)

Additional context

There is no such problem in v21.8.15.7-lts.

Activity

  1. added
    potential bug
    on May 6, 2022
  2. SaltTan commented on May 6, 2022

    @SaltTan
    Contributor

    Maybe related #36300?

  3. alexey-milovidov commented on Jul 2, 2022

    @alexey-milovidov
    Member

    Reproduced on version 22.7.

  4. SergeyKotyushkin commented on Feb 13, 2023

    @SergeyKotyushkin
    Author

    @KochetovNicolai, hello, do you have any updates on this issue?

    In addition I figured out few things:

    1. To 100% reproduce this problem you should add sleep after adding data to buffer and before select. Data must be flushed to buffer target. I've added a sample in clickhouse-fiddle.
    2. The usage of optimize_move_to_prewhere=0 solves problem but I think it may have some performance impact.

    The issue is still actual.

  5. added
    bug
    and removed
    potential bug
    on Apr 9, 2024
  6. nikitamikhaylov commented on Apr 9, 2024

    @nikitamikhaylov
    Member
  7. added a commit that references this issue on Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions