Skip to content

Commit dc528e2

Browse files
authored
Merge pull request ClickHouse#86457 from ClickHouse/backport/25.8/86413
Backport ClickHouse#86413 to 25.8: Fix MV dependencies double removal
2 parents f54ab70 + 145f00d commit dc528e2

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/Storages/LiveView/StorageLiveView.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@ void StorageLiveView::checkTableCanBeDropped([[ maybe_unused ]] ContextPtr query
267267

268268
void StorageLiveView::drop()
269269
{
270-
auto table_id = getStorageID();
271-
DatabaseCatalog::instance().removeViewDependency(select_query_description.select_table_id, table_id);
272-
273270
std::lock_guard lock(mutex);
274271
condition.notify_all();
275272
}

src/Storages/StorageMaterializedView.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,6 @@ SinkToStoragePtr StorageMaterializedView::write(const ASTPtr & query, const Stor
444444
void StorageMaterializedView::drop()
445445
{
446446
auto table_id = getStorageID();
447-
const auto & select_query = getInMemoryMetadataPtr()->getSelectQuery();
448-
if (!select_query.select_table_id.empty())
449-
DatabaseCatalog::instance().removeViewDependency(select_query.select_table_id, table_id);
450447

451448
if (getInMemoryMetadataPtr()->sql_security_type == SQLSecurityType::DEFINER)
452449
ViewDefinerDependencies::instance().removeViewDependencies(table_id);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
2
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
# shellcheck source=../shell_config.sh
5+
. "$CURDIR"/../shell_config.sh
6+
7+
$CLICKHOUSE_CLIENT --query "create table src (n int) engine=MergeTree order by n"
8+
$CLICKHOUSE_CLIENT --query "create table dst (n int) engine=MergeTree order by n"
9+
$CLICKHOUSE_CLIENT --query "create materialized view mv to dst (n int) as select * from src"
10+
$CLICKHOUSE_CLIENT --query "insert into src select 1"
11+
$CLICKHOUSE_CLIENT --query "select sleep(2) from mv format Null" 2> /dev/null &
12+
sleep 0.$RANDOM
13+
14+
$CLICKHOUSE_CLIENT --database_atomic_wait_for_drop_and_detach_synchronously=0 --query "drop table mv"
15+
$CLICKHOUSE_CLIENT --query "create materialized view mv to dst (n int) as select * from src"
16+
17+
wait
18+
sleep 1 # increase chance of reproducing the issue
19+
$CLICKHOUSE_CLIENT --query "insert into src select 2"
20+
21+
$CLICKHOUSE_CLIENT --query "select * from dst order by n"
22+
23+
$CLICKHOUSE_CLIENT --query "drop table mv"
24+
$CLICKHOUSE_CLIENT --query "drop table src"
25+
$CLICKHOUSE_CLIENT --query "drop table dst"

0 commit comments

Comments
 (0)