Repository navigation
Fix default expression evaluation when referencing other columns with defaults - #94615
Merged
alexey-milovidov merged 3 commits intoJan 26, 2026
Merged
Conversation
… defaults
When inserting partial rows where one column's default expression
references another column that also has a default, the default
expression was incorrectly using the literal default value instead
of the provided value.
For example, with table:
n UInt8 DEFAULT 42
s String DEFAULT concat('test', CAST(n, 'String'))
Inserting {"n": 2} would produce s='test42' instead of s='test2'.
The issue was that `AddingDefaultsTransform` erased ALL columns with
defaults from the evaluation block, so when evaluating s's default
expression, column n wasn't available and the code fell back to n's
literal default value (42).
The fix processes default expressions in dependency order using
topological sort: first compute defaults for columns with no
dependencies, mix them into the result block, then compute defaults
for dependent columns which can now see the correct values.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
|
Workflow [PR], commit [2a03f0a] Summary: ❌
|
Member
Author
alexey-milovidov
deleted the
fix-default-expression-dependency-evaluation
branch
January 26, 2026 13:11
vdimir
reviewed
Mar 19, 2026
| /// and column `n` has DEFAULT 42, when inserting {"n": 2} we need to first compute | ||
| /// n's defaults (for rows where n is missing), mix them into the block, and only | ||
| /// then compute s's defaults so that s can see the correct values of n. | ||
| std::unordered_map<String, NameSet> dependencies; |
Member
There was a problem hiding this comment.
Matching by name does not always work, sometimes we can depend on subcolumn:
DROP TABLE IF EXISTS test_defaults_tuple;
CREATE TABLE test_defaults_tuple (
a Tuple(x Int32, y Int32) DEFAULT (b.x * 10, b.y * 10),
b Tuple(x Int32, y Int32) DEFAULT (1, 2)
) ENGINE = Memory;
INSERT INTO test_defaults_tuple FORMAT JSONEachRow
{"b": {"x": 5, "y": 6}}
{};
SELECT * FROM test_defaults_tuple;
-- Returns:
-- (10,20) (5,6)
-- (10,20) (1,2)
-- Expected:
-- (50,60) (5,6)
-- (10,20) (1,2)
Contributor
|
@alexey-milovidov can this fix be backported to LTS versions? At least the previous one to this fix, CH 25.8 |
This was referenced Nov 5, 2026
zvonand
added a commit
to Altinity/ClickHouse
that referenced
this pull request
Nov 10, 2026
Antalya 25.8 Backport of ClickHouse#94615 - Fix default expression evaluation when referencing other columns with defaults
zvonand
added a commit
to Altinity/ClickHouse
that referenced
this pull request
Nov 10, 2026
Stable 25.8 Backport of ClickHouse#94615 - Fix default expression evaluation when referencing other columns with defaults
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When inserting partial rows where one column's default expression references another column that also has a default, the default expression was incorrectly using the literal default value instead of the provided value.
For example, with table:
n UInt8 DEFAULT 42
s String DEFAULT concat('test', CAST(n, 'String'))
Inserting {"n": 2} would produce s='test42' instead of s='test2'.
The issue was that
AddingDefaultsTransformerased ALL columns with defaults from the evaluation block, so when evaluating s's default expression, column n wasn't available and the code fell back to n's literal default value (42).The fix processes default expressions in dependency order using topological sort: first compute defaults for columns with no dependencies, mix them into the result block, then compute defaults for dependent columns which can now see the correct values.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix default expression evaluation when referencing other columns with computed defaults.
Version info
26.1.1.880