ClickHouse / ClickHouse/ClickHouse

Dropping column not allowed because it is referenced in a materialized view, which isn't true (although a CTE with the same column name exists)

Open
#78,060 0 comments 0 reactions 0 assignees View on GitHub
comp-materialized-view external potential bug
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

### Company or project name

_No response_

### Describe what's wrong

I'm trying to drop a column `val` from a source table that has an MV attached.
The MV uses a CTE that selects a _constant value_ as `val`, but doesn't read the `val` in the source table.

I think this should allow me to drop `val` from the source table, but this results in a `Trying to ALTER DROP column val which is referenced by materialized view ['dest_mv']` error.

Without the CTE it works correctly.

I know the example looks quite pointless. The actual case where I encountered this behaviour is in the down script for a migration that added the `val` column to the source table, while the previous version of the code was using `now()` as a default.

### Does it reproduce on the most recent release?

Yes

### How to reproduce

See [fiddle](https://fiddle.clickhouse.com/5a00a98a-2a24-41a8-9888-ff791a673bf4)

### Expected behavior

The `val` column should be dropped since the MV doesn't use it.

### Error message and/or stacktrace

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.