Skip to content

Exists with mutations execute on initator#97347

Merged
Fgrtue merged 6 commits intomasterfrom
exists-with-mutations-execute-on-initator
Feb 20, 2026
Merged

Exists with mutations execute on initator#97347
Fgrtue merged 6 commits intomasterfrom
exists-with-mutations-execute-on-initator

Conversation

@Fgrtue
Copy link
Contributor

@Fgrtue Fgrtue commented Feb 19, 2026

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The problem appears when we set a setting:

SET mutations_execute_subqueries_on_initiator = 1;

And run an ALTER query with a function exists with a scalar subquery inside. This causes the scalar subquery in exsits being evaluated to a number. Then, after the mutation is applied, we get either an error, or we get OK with mutation stored with a corrupt command, which makes table unloadable on the next server restart. The response of the server depends of the query. Test in the pull request shows two queries, that cause different errors, but a rooted in the same problem.

AST fuzzer report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96790&sha=cbdee8ffcd02bf966e588b7d06f2e39718da5486&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29

Continuation of #96985

@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Feb 19, 2026

Workflow [PR], commit [e168e9e]

Summary:

job_name test_name status info comment
BuzzHouse (arm_asan) failure
Logical error: Digest does not match (STID: 5007-4bc5) FAIL cidb, issue ISSUE EXISTS

@clickhouse-gh clickhouse-gh bot added the pr-bugfix Pull request with bugfix, not backported by default label Feb 19, 2026
@Fgrtue
Copy link
Contributor Author

Fgrtue commented Feb 19, 2026

This bug can also crash the server in some cases such as the following:

https://fiddle.clickhouse.com/99e7405f-a80c-48b3-919e-b514f2a86ec9

@yakov-olkhovskiy yakov-olkhovskiy self-assigned this Feb 19, 2026
Comment on lines +12 to +17
ALTER TABLE t_mutations_nondeterministic
(UPDATE v = exists((
SELECT count()
FROM system.numbers
WHERE number < 25
)) WHERE 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange thing is that I'm getting "Unknown function exists" in the fiddle:
https://fiddle.clickhouse.com/1178e949-a3ae-43e8-ae0c-181e57014589
maybe it's a manifestation of this bug in release build?

Copy link
Contributor Author

@Fgrtue Fgrtue Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I suppose something changed which made us skip the bug. I don't know what exactly though. But with the fix it should work normally, since it is a perfectly valid query, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, test is passing in CI and I downloaded both debug and release and it definitely works... but still strange...
this is a stacktrace from current head:
https://pastila.clickhouse.com/?0079b799/083dd9d85a2482d60a23bbbba7b2958c#hkwvO75/IPLUivGwi2T+5Q==GCM

@yakov-olkhovskiy
Copy link
Member

This bug can also crash the server in some cases such as the following:

I see you test it on 25.6 and it doesn't reproduce since 25.7 - was there some fix addressing this issue?

@Fgrtue
Copy link
Contributor Author

Fgrtue commented Feb 19, 2026

@yakov-olkhovskiy I am not sure what made the server not to crash in the later versions, but in the latest version, we can still notice an erroneous behavior with these types of queries:

ALTER TABLE t_mutations_nondeterministic (UPDATE v = now((exists((SELECT 1023)))) WHERE NULL);

To see this behavior we have to run the test first, and then restart the server, connect with the client again, and the error should be shown automatically. It should also be shown if you try to DROP the table, and, probably, do anything else with it. This happens because the server tries to apply the latest mutation, which contains _CAST(1023, 'Nullable(UInt16)') (or something similar).

@Fgrtue
Copy link
Contributor Author

Fgrtue commented Feb 19, 2026

Also, in debug build the server should still crash AFAIK

@Fgrtue Fgrtue added this pull request to the merge queue Feb 20, 2026
Merged via the queue into master with commit 1c6abed Feb 20, 2026
145 of 147 checks passed
@Fgrtue Fgrtue deleted the exists-with-mutations-execute-on-initator branch February 20, 2026 13:27
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-critical-bugfix pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants