Skip to content

Use an inverted text index for TimeSeries tags - #120083

Merged
nikitamikhaylov merged 3 commits into
masterfrom
timeseries-tags-text-index
Sep 17, 2026
Merged

nikitamikhaylov merged 3 commits into
masterfrom
timeseries-tags-text-index

Conversation

@nikitamikhaylov

@nikitamikhaylov nikitamikhaylov commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Add a keyValuePairs text index to newly created TimeSeries tags tables (schema version 4), preserving older schemas and custom indexes.

Validated with 5 functional tests, 20 normalization tests, and all 15 style checks.

Related: #115579

Changelog category (leave one):

  • Performance Improvement

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

Accelerate exact PromQL label matching on new TimeSeries tables using a text index on the tags map.


Workflow [PR]
Sync PR [sync-upstream/pr/120083]

Version info

  • Merged into: 26.10.1.29 (included in 26.10 and later)

@nikitamikhaylov nikitamikhaylov added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Sep 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4960f3f]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR bumps TimeSeries schema version to 5 and adds a default keyValuePairs text index to new inner tags tables, together with CREATE TABLE ... AS ..., docs, and test updates. The default-index change itself looks reasonable, but the current implementation still breaks the versioning contract for explicitly older schemas, can silently discard user-declared indexes during CREATE TABLE ... AS ..., and still lacks focused before/after evidence for the claimed Performance Improvement.

Findings
❌ Blockers
  • src/Parsers/ParserViewTargets.cpp:52, normalizeTimeSeriesDefinitionImpl.cpp:2091 INNER COLUMNS now accepts INDEX for every explicit TimeSeries version, but normalization only gates auto-generated indexes on version >= 5. CREATE TABLE ... ENGINE = TimeSeries SETTINGS version = 4 TAGS INNER COLUMNS (INDEX ...) therefore succeeds and stores metadata that a pre-v5 server cannot parse on ATTACH or replicated DDL replay, violating the contract that an explicit older version remains readable by servers supporting that version.
    Suggested fix: reject inner indexes when version < 5, or treat the presence of any inner index as opting the table into version = 5.
⚠️ Majors
  • src/Parsers/ParserViewTargets.cpp:52, ParserCreateQuery.cpp:513 ParserTablePropertiesDeclarationList drops ASTForeignKeyDeclaration on the floor, and INNER COLUMNS only rejects constraints, projections, and primary keys after parsing. ... INNER COLUMNS (FOREIGN KEY ...) therefore succeeds but the clause disappears from the stored definition instead of being rejected. That turns unsupported DDL into a silent no-op.
    Suggested fix: reject FOREIGN KEY at this boundary too, or stop using the generic table-properties parser unless every unsupported property is surfaced as an error.
  • normalizeTimeSeriesDefinitionImpl.cpp:739 removeGeneratedInnerIndices identifies the generated tags_idx by formatting the AST and comparing strings. A user-declared INDEX tags_idx tags TYPE text(tokenizer = 'keyValuePairs') is indistinguishable from the generated one, so CREATE TABLE ... AS ... can silently drop an explicit index when the destination will not re-generate it, or when another custom index keeps normalizeInnerIndices from re-adding the default. That violates the documented contract that explicit indexes are preserved.
    Suggested fix: track whether the index was generated instead of inferring it from formatted text, or fail the ambiguous case instead of silently stripping it.
Tests
  • ⚠️ tests/queries/0_stateless/05217_timeseries_tags_text_index.sql:43 The new functional test proves that the planner can use the text index, but it still does not supply the before/after evidence required by the PR's Performance Improvement category and changelog text. A small focused measurement on representative exact-label selectors (elapsed, read_rows, or read_bytes with and without the index) would close this gap.
Final Verdict
  • Status: ⚠️ Request changes
  • Reject or version-gate explicit inner indexes for pre-5 tables, reject FOREIGN KEY instead of silently dropping it, preserve or explicitly reject ambiguous copied tags_idx declarations, and add a focused before/after measurement for the claimed performance improvement.

LLVM Coverage Report

Measured on commit 4960f3f.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.60% +0.00%

Changed lines: Changed C/C++ lines covered: 151/152 (99.34%) · Uncovered code

Full report · Diff report

ASTPtr inner_columns;
if (ParserToken(TokenType::OpeningRoundBracket).ignore(pos, expected)
&& ParserColumnDeclarationList{}.parse(pos, col_list, expected)
&& ParserTablePropertiesDeclarationList{}.parse(pos, inner_columns, expected)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Allowing ParserTablePropertiesDeclarationList here makes INDEX ... legal in INNER COLUMNS for every TimeSeries schema version. The only later gate is around the auto-generated tags_idx, so CREATE TABLE ... ENGINE = TimeSeries SETTINGS version = 3 TAGS INNER COLUMNS (INDEX custom_tags tags TYPE text(tokenizer = 'keyValuePairs')) is now accepted and stored as a version = 3 table. A pre-v4 server that still supports version 3 cannot parse that metadata on ATTACH / DDL replay because its ParserViewTargets only accepted column declarations. That breaks the versioning contract that an explicit older version keeps the definition readable/replayable by servers supporting that version. Please reject inner indexes when version < 4 or bump the table version when one is present.

auto & indices = inner_columns.indices->children;
auto is_generated = [&](const ASTPtr & index)
{
return index->formatWithSecretsOneLine() == default_index;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Matching on formatWithSecretsOneLine() makes every INDEX tags_idx tags TYPE text(tokenizer = 'keyValuePairs') look generated, even when the user spelled it explicitly. In CREATE TABLE ... AS ... that silently drops such an index whenever the destination will not regenerate it, for example TAGS INNER ENGINE = Memory. The PR body/docs promise that custom indexes are preserved, but this path turns an explicit schema choice into a no-op. We need a way to distinguish the auto-generated tags_idx from a user-declared one, or at least fail instead of stripping the ambiguous case.

@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 4960f3f616c8d7ecb0c337e5a243d26455914038 with master failed: RuntimeError: CI logs cluster query failed: SELECT file, library, argMax(dur, time) AS ….

See the job log for details.

@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 1e108391-bb8b-48a6-b7fd-502c370c5c5f
  • MIRAI run: 5d834383-7bcc-4e23-8206-51145cef404c
  • PR check IDs:
    • clickbench_356702_1789508295
    • clickbench_356708_1789508295
    • clickbench_356714_1789508295
    • tpch_adapted_1_official_356720_1789508295
    • tpch_adapted_1_official_356737_1789508295
    • tpch_adapted_1_official_356748_1789508295

nikitamikhaylov added a commit that referenced this pull request Sep 15, 2026
Include the merged upstream revert for the `NOT_FOUND_COLUMN_IN_BLOCK`
exception in `03710_analyzer_limit_by_aggregate_validation` when
`optimize_injective_functions_in_group_by` is disabled. Preserve the
complete `TimeSeries` tags-index diff and all existing PR commits.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120083&sha=26c00521dd478c40580fdc59b77ddf46d937d8e6&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
Related: #120118
Related: #120083
auto inner_columns = make_intrusive<ASTColumns>();
inner_columns->set(inner_columns->columns, col_list);
const auto & columns = inner_columns->as<ASTColumns &>();
if (columns.constraints || columns.projections || columns.primary_key || columns.primary_key_from_columns)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ParserTablePropertiesDeclarationList does not just add INDEX support here: it also parses FOREIGN KEY ... and then drops ASTForeignKeyDeclaration on the floor in ParserTablePropertiesDeclarationList. Because this check only rejects constraints / projections / primary keys, ... INNER COLUMNS (FOREIGN KEY (...) REFERENCES ...) now succeeds and the foreign-key clause disappears from the stored definition instead of being rejected.

INNER COLUMNS should reject every non-column / non-index table property at this boundary, not silently turn unsupported syntax into a no-op.

SELECT value FROM prometheusQuery(ts_text, 'test_metric{job="worker"}', 1000)
SETTINGS log_comment = 'timeseries_tags_text_index_promql';
SYSTEM FLUSH LOGS query_log;
SELECT count() = 2 AND min(ProfileEvents['TextIndexUsedEmbeddedPostings'] + ProfileEvents['TextIndexReadPostings'] > 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This proves that the planner can hit the text index, but it still does not establish the contract claimed by the PR metadata/docs (Performance Improvement, "It accelerates ...").

Because this change also bumps the stored TimeSeries schema version for every new table, we still need a small before/after measurement on representative exact-label selectors, for example elapsed, read_rows, or read_bytes with and without the index, to show that the new default index is worth the version bump.

@vitlibar vitlibar self-assigned this Sep 15, 2026
return false;

auto indices = make_intrusive<ASTExpressionList>();
indices->children.push_back(makeDefaultTagsIndex());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No TimeSeries setting is used, so we won't be able to turn it off

Use `keyValuePairs` to index label pairs in the `tags` map for new schema
version 4 tables. Preserve explicit indexes and earlier schema versions,
and carry index declarations through inner-table creation and attachment.

Related: #115579
@vitlibar
vitlibar force-pushed the timeseries-tags-text-index branch from 3181c8d to 9747926 Compare September 15, 2026 18:32
/// every version in [MIN_SUPPORTED, LATEST] must stay supported, so either make the schema generation
/// version-aware or bump MIN_SUPPORTED too.
constexpr UInt64 LATEST = 4;
constexpr UInt64 LATEST = 5;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I rebased this PR to fix conflict, so version is 5 now

… `TimeSeries` version

The tests `05213_timeseries_metric_families_target` and `05214_timeseries_backup_restore` printed
the version pinned into a new table, which is now 5 because of the default text index on `tags`.
The latest version is covered by `04612_timeseries_version_setting`, so these tests check only
the keyword, the inner table names, and that the restored definition keeps the version.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120083&sha=9747926c14e6d3f65bb0369fa2496c2b6e56fc9a&name_0=PR&name_1=Fast%20test
PR: #120083
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

PromQL Compliance Report

Baseline: S3 master 1e93c0a25

Metric Baseline Current Δ
Score 84.23% 84.23% +0.00%
Passed 454 454 +0
Failed 3 3 +0
Unsupported 82 82 +0

Note: score is unchanged vs baseline.

Uploaded compliance JSON for this PR commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-performance Pull request with some performance improvements 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