Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #47975 to 23.2: Skip materialized view checking if source table does not exist #48164

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Interpreters/InterpreterCreateQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
TableProperties properties = getTablePropertiesAndNormalizeCreateQuery(create);

/// Check type compatible for materialized dest table and select columns
if (create.select && create.is_materialized_view && create.to_table_id)
if (create.select && create.is_materialized_view && create.to_table_id && !create.attach)
{
if (StoragePtr to_table = DatabaseCatalog::instance().tryGetTable(
{create.to_table_id.database_name, create.to_table_id.table_name, create.to_table_id.uuid},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3 some_val
3 9
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SET send_logs_level = 'fatal';

CREATE TABLE test_table (n Int32, s String) ENGINE MergeTree PARTITION BY n ORDER BY n;

CREATE TABLE mview_backend (n Int32, n2 Int64) ENGINE MergeTree PARTITION BY n ORDER BY n;

CREATE MATERIALIZED VIEW mview TO mview_backend AS SELECT n, n * n AS "n2" FROM test_table;

DROP TABLE test_table;

DETACH TABLE mview;

/* Check that we don't get an exception with the option. */
ATTACH TABLE mview;

/* Check if the data in the materialized view is updated after the restore.*/
CREATE TABLE test_table (n Int32, s String) ENGINE MergeTree PARTITION BY n ORDER BY n;

INSERT INTO test_table VALUES (3,'some_val');

SELECT n,s FROM test_table ORDER BY n;
SELECT n,n2 FROM mview ORDER by n;