Skip to content

Backport #117314 to 26.7: Strip FixedString padding before extracting text-index search terms - #123522

Merged
clickhouse-gh[bot] merged 3 commits into
26.7from
backport/26.7/117314
Oct 4, 2026
Merged

clickhouse-gh[bot] merged 3 commits into
26.7from
backport/26.7/117314

Conversation

@robot-clickhouse

@robot-clickhouse robot-clickhouse commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Original pull-request #117314
Cherry-pick pull-request #123480

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.7.21.4

@robot-clickhouse robot-clickhouse added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Oct 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [73ed98b]

Summary: ✅

alexey-milovidov and others added 2 commits October 4, 2026 12:31
# Conflicts:
#	src/Storages/MergeTree/MergeTreeIndexConditionText.cpp
…stant` on 26.7

On 26.7 the statistics part pruning (`use_statistics_for_part_pruning`) drops the whole part
for `s IN (SELECT toFixedString('hello', 10))` on a `FixedString(6)` column when statistics are
materialized on insert, even on a table without any skip index and with `use_skip_indexes = 0`.
`materialize_statistics_on_insert` is randomized in CI, so the test failed. This is a separate
pre-existing bug of 26.7, already absent on master, and not related to the text index change
being backported, so the test disables statistics pruning to check only the index behavior.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=123522&sha=a8511444a682e24870d741f5bd52fcbf17911760&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29
PR: #123522

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged 26.7 and resolved the conflict in MergeTreeIndexConditionText.cpp: the lossless-conversion helpers moved to RPNBuilder in the backport of #123239, so only the FixedString padding helpers from this PR are kept there.

The failure of 05081_text_index_fixed_string_constant (report) is a separate, pre-existing bug on 26.7. It is not caused by the text-index change. With materialize_statistics_on_insert = 1 (randomized in CI), the statistics part pruning drops the whole part, even on a table with no skip index:

CREATE TABLE t (id UInt32, s FixedString(6)) ENGINE = MergeTree ORDER BY id;
INSERT INTO t VALUES (1, 'hello'), (2, 'world'), (3, 'hello'), (4, 'foobar');
SELECT count() FROM t WHERE s IN (SELECT toFixedString('hello', 10));  -- 0 on 26.7.20.1 with materialize_statistics_on_insert = 1, 2 on master (26.10)
-- EXPLAIN indexes = 1 shows: Statistics ... Parts: 0/1

The test now sets use_statistics_for_part_pruning = 0, so it checks only the index behavior. I verified it locally with the 26.7 CI binary, using the exact randomized settings from the failed run, with defaults, and with statistics forced on.

@groeneai, please investigate the 26.7 statistics part pruning bug above and find which master change fixed it, so it can be backported in a separate PR. If a fix is already in progress, link it here.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

The master change is #109977 (merged 2026-07-29, first in 26.8.1.390). I bisected master from the 26.7 branch point with the CI release binaries: its merge commit b0daddf19db2 returns 2, and its first parent 51a4cd573d3b returns 0 (EXPLAIN there shows Statistics, Keys: s, Parts: 0/1). Official images: 26.6.8.7 returns 2 (its auto_statistics_types is minmax, uniq, and minmax does not cover FixedString), 26.7.17.7 returns 0, 26.8.10.6 returns 2.

#109977 fixes it by taking s out of statistics pruning, not by fixing the set. On 26.7, StatisticsPartPruner::checkPartCanMatch admits every Basic estimate, so s (no min/max) enters the key condition with a whole-universe range. The set then goes through tryPrepareSetColumnsForIndex, where accurateCastOrNull of the FixedString(10) element to FixedString(6) is NULL, so the element is dropped and the empty set excludes the part. #109977 admits only estimates that carry estimated_min (plus statisticsHasMinMax in the constructor); the rest of it is the NullCount to DefaultCount rework.

The set conversion is still wrong on master through the primary key:

CREATE TABLE tp (id UInt32, s FixedString(6)) ENGINE = MergeTree ORDER BY s;
INSERT INTO tp VALUES (1, 'hello'), (2, 'world'), (3, 'hello'), (4, 'foobar');
SELECT count() FROM tp WHERE s IN (SELECT toFixedString('hello', 10)); -- 0 (PrimaryKey Parts: 0/1), 2 with use_primary_key = 0

It returns 0 on master 2493c465d931, 25.3.14.14, 26.3.33.24 and 26.7.17.7. Your open #118957 fixes it: with its diff applied to that master commit, the query returns 2 (Parts: 1/1). The 26.7 statistics path goes through the same tryPrepareSetColumnsForIndex, but I have not built #118957 on 26.7.

@clickhouse-gh
clickhouse-gh Bot merged commit 66f1aaa into 26.7 Oct 4, 2026
40 of 41 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.7/117314 branch October 4, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants