Skip to content

fix: enrichQueryWithOnCluster misses ON CLUSTER for views with UUID/column-defs#1422

Open
wangyelei wants to merge 1 commit into
Altinity:masterfrom
wangyelei:fix/live-view-on-cluster-enrich
Open

fix: enrichQueryWithOnCluster misses ON CLUSTER for views with UUID/column-defs#1422
wangyelei wants to merge 1 commit into
Altinity:masterfrom
wangyelei:fix/live-view-on-cluster-enrich

Conversation

@wangyelei

Copy link
Copy Markdown

Problem

When restore_schema_on_cluster is configured and restoring views that have UUID and/or explicit column definitions (e.g. LIVE VIEW, WINDOW VIEW), the enrichQueryWithOnCluster() function fails to inject ON CLUSTER into the restored DDL.

Root cause

The regex patterns createViewRe and attachViewRe used [^(]+ in the first capture group. This stops at the first ( character, which in queries like:

ATTACH LIVE VIEW db.lv UUID 'xxx' (`event_date` UInt32, ...) AS SELECT ...
ATTACH WINDOW VIEW db.wv UUID 'xxx' (`total` Decimal(38, 2), ...) ENGINE = MergeTree ... AS SELECT ...

prevents the regex from ever reaching the AS SELECT clause, so ON CLUSTER is never injected.

Fix

Changed createViewRe and attachViewRe first capture group from [^(]+ to .+? (lazy match), which skips past UUID and parenthesized column definitions to correctly locate AS SELECT for ON CLUSTER insertion.

Reproduce

  • ClickHouse: 25.4.4
  • clickhouse-backup: 2.7.0
  • Config: restore_schema_on_cluster: 'default'

Two queries restored without ON CLUSTER:

ATTACH LIVE VIEW test.daily_sales_live UUID '8190d585-...' (`event_date` UInt32, ...) AS SELECT ...
ATTACH WINDOW VIEW test.wv UUID '6b87827c-...' (`total` Decimal(38, 2), ...) ENGINE = MergeTree ... AS SELECT ...

This results in the views only being created on the current node, causing subsequent data restore to fail:

FTL RestoreData: 'test.daily_sales_live', 'test.wv' is not created. Restore schema first or create missing tables manually

Other view types (MATERIALIZED VIEW ... TO, CREATE VIEW, CREATE DICTIONARY, CREATE TABLE) were unaffected because they matched different regex patterns.

…olumn-defs

The existing regex patterns used [^(]+ in the first capture group, which
stops at '(' from column definitions or UUID, preventing AS SELECT/AS WITH
matching.  Changed createViewRe and attachViewRe to use .+? so that UUID
and parenthesized column definitions between the view name and the AS clause
are skipped during match, allowing ON CLUSTER injection to succeed.

Fixes ATTACH LIVE VIEW, ATTACH WINDOW VIEW, and any other view types whose
SHOW CREATE output includes UUID and/or explicit column definitions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant