Skip to content

Revert "Fix NO_SUCH_COLUMN_IN_TABLE naming a column absent from the table when a part's columns were all renamed or all dropped" - #119429

Merged
Algunenano merged 1 commit into
masterfrom
revert-114562-fix-inject-required-columns-renamed
Sep 11, 2026
Merged

Algunenano merged 1 commit into
masterfrom
revert-114562-fix-inject-required-columns-renamed

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Reverts #114562

Broke CI and multiple bugs reported


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

Version info

  • Merged into: 26.9.1.1193 (included in 26.9 and later)

…able when a part's columns were all renamed or all dropped"
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d9bf6a0]


AI Review

Summary

This PR reverts the MergeTree read-path changes from #114562. The revert does remove the regressions that motivated it, but it also reinstates two older correctness bugs: stale attached parts can again be read as rows of defaults, and merged parts with a still-pending RENAME COLUMN can return synthesized values instead of the data written on disk.

Findings

❌ Blockers

  • [src/Storages/MergeTree/MergeTreeBlockReadUtils.cpp:217] Restoring the minimum-size-column injection when no requested column exists in the part reopens the stale-part path that the removed 04870_inject_column_no_common_column_with_metadata.sh was covering. Because getRowCount() / fixFromRowsCount() already make zero-physical-column reads exact, this fallback is no longer needed for row counting; on a stale attached part that still shares one column with metadata, it now injects that survivor and fills the requested columns from defaults, silently hiding unexplained on-disk data. If the part shares no column with metadata, the available_columns = part_columns fallback injects a raw part name and legitimate reads/merges fail with NO_SUCH_COLUMN_IN_TABLE.
    Suggested fix: keep the post-#114562 behavior here: do not inject any column just for row counting, and reject only parts whose physical columns are not accounted for by current metadata or pending drop/rename conversions.
  • [src/Storages/MergeTree/IMergeTreeReader.cpp:399] The unconditional new_name -> old_name rewrite makes merged parts produced while a RENAME COLUMN mutation is still pending return defaults instead of the data stored on disk. A merge writes the new column name into the part, but the part still inherits the old data_version from its sources, so alter_conversions still says the rename is pending. Rewriting c back to a on that merged part makes getColumnInPart() miss the physical column and fillMissingColumns() synthesize the value.
    Suggested fix: restore the part-aware rename test from #114562 (or equivalent logic) so the back-mapping is applied only when the part still has the old physical name, with the same-statement name-reuse case preserved.
Final Verdict

❌ Changes requested. As written, the revert trades one set of regressions for two older MergeTree read-path correctness bugs, including silent wrong results.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 11, 2026
@Algunenano
Algunenano added this pull request to the merge queue Sep 11, 2026
* Used in case when no column is needed or files are missing, but at least you need to know number of rows.
* Adds to the columns.
*/
if (!have_at_least_one_physical_column)

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 brings back the old "inject one physical column just to learn the row count" fallback, but the surrounding read path no longer needs it. loadColumnsChecksumsIndexes now fixes constant granularity from rows_count, MergeTreeReaderIndex::readRows clamps by getRowCount(), and ReadResult::adjustLastGranule() explicitly treats num_read_rows == 0 as already accurate.

With that in place, reintroducing the injection reopens the stale-part bug the deleted 04870_inject_column_no_common_column_with_metadata.sh was covering. A part re-attached after ADD COLUMN b, DROP COLUMN a that still holds a,k now injects k from the metadata intersection and returns rows of default b, silently hiding the on-disk a values; if the part shares no column with metadata, the available_columns = part_columns fallback injects a raw part name and later throws NO_SUCH_COLUMN_IN_TABLE on a legitimate read/merge.

auto subcolumn_name = required_column.getSubcolumnName();

if (alter_conversions->isColumnRenamed(name_in_storage, [&](const auto & name) { return part_columns.has(name); }))
if (alter_conversions->isColumnRenamed(name_in_storage))

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 unconditional back-mapping reintroduces the pending-rename read bug for merged parts. OPTIMIZE ... FINAL writes the merged part under the current column names, but the part keeps the source data_version, so alter_conversions still reports the rename as pending. After this change a request for c is always rewritten to a; on the merged part part_columns only has c, so getColumnInPart() treats the column as missing and fillMissingColumns() synthesizes defaults instead of reading the intact data.

The previous isColumnRenamed(new_name, part_has_column) helper was doing the needed distinction here: only map through the old name when the part actually still stores the old file name, while still handling same-statement name reuse like RENAME A TO C, RENAME B TO A.

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 11, 2026
Merged via the queue into master with commit c5c3c4d Sep 11, 2026
19 of 31 checks passed
@Algunenano
Algunenano deleted the revert-114562-fix-inject-required-columns-renamed branch September 11, 2026 11:29
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 11, 2026
ei-grad added a commit to ei-grad/ClickHouse that referenced this pull request Sep 14, 2026
Include the upstream row-count repairs needed by the completed CI runs.
Resolve the connection conflict by retaining profile-setting preparation
and using the shared network compression codec selector from master.

Preserve the trace subscription lifecycle, distributed forwarding and
protocol negotiation while retaining the upstream shutdown, leaf-timeout
and preauthentication changes.

Related: ClickHouse#119429
Related: ClickHouse#119400
Related: ClickHouse#117830 (comment)

Co-Authored-By: Codex CLI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. pr-not-for-changelog This PR should not be mentioned in the changelog 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.

2 participants