Skip to content

MergeTree, filter: regexp with '?', negation with 'not' produce wrong results #92492

Closed

Description

@ikfid

Company or project name

No response

Describe what's wrong

Expecting these queries produce the same results, but they don't:

  1. using MergeTree as a source:
create or replace table in1 engine = MergeTree() order by url as
select 'http://example1.com/' as url;

-- expected: 1; returned: 0 - WRONG
select count(*) from in1
where not match(url, '^https?://clickhouse[.]com/');

  1. using CTE as a source:
-- same inputs, same regexp, same query, but without MergeTree
-- expected: 1 row; returned: 1 row - CORRECT
with 
in1 as (
select 'http://example1.com/' as url
)
select count(*) 
from in1
where not match(url, '^https?://clickhouse[.]com/');

More tests are here: https://fiddle.clickhouse.com/380c4fee-d7e4-4857-8eef-2b6b373a55b0

It seems that the presence of '?' inside regexp impacts the results.
Or negation using 'not', because where match() = false works fine.

Does it reproduce on the most recent release?

Yes

How to reproduce

https://fiddle.clickhouse.com/380c4fee-d7e4-4857-8eef-2b6b373a55b0

Expected behavior

No response

Error message and/or stacktrace

No response

Additional context

No response

Activity

  1. added
    potential bugTo be reviewed by developers and confirmed/rejected.
    on Dec 18, 2025
  2. KochetovNicolai commented on Dec 19, 2025

    @KochetovNicolai
    Member

    It's a bug with KeyCondition.
    If I replace create or replace table in1 engine = MergeTree() order by url to create or replace table in1 engine = MergeTree() order by tuple() it works fine

  3. added
    bugConfirmed user-visible misbehaviour in official release
    and removed
    potential bugTo be reviewed by developers and confirmed/rejected.
    on Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugConfirmed user-visible misbehaviour in official release

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions