mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Merge pull request #62319 from mxwell/materialized_prim_key
Fix primary key in materialized view
This commit is contained in:
commit
b6cfba33f1
@ -91,6 +91,12 @@ StorageMaterializedView::StorageMaterializedView(
|
||||
{
|
||||
StorageInMemoryMetadata storage_metadata;
|
||||
storage_metadata.setColumns(columns_);
|
||||
auto * storage_def = query.storage;
|
||||
if (storage_def && storage_def->primary_key)
|
||||
storage_metadata.primary_key = KeyDescription::getKeyFromAST(storage_def->primary_key->ptr(),
|
||||
storage_metadata.columns,
|
||||
local_context->getGlobalContext());
|
||||
|
||||
if (query.sql_security)
|
||||
storage_metadata.setSQLSecurity(query.sql_security->as<ASTSQLSecurity &>());
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
test id
|
||||
test_mv
|
||||
test_mv_pk value
|
28
tests/queries/0_stateless/03035_materialized_primary_key.sql
Normal file
28
tests/queries/0_stateless/03035_materialized_primary_key.sql
Normal file
@ -0,0 +1,28 @@
|
||||
DROP TABLE IF EXISTS test;
|
||||
CREATE TABLE test
|
||||
(
|
||||
id UInt64,
|
||||
value String
|
||||
) ENGINE=MergeTree ORDER BY id;
|
||||
|
||||
INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob');
|
||||
|
||||
DROP VIEW IF EXISTS test_mv;
|
||||
CREATE MATERIALIZED VIEW test_mv
|
||||
(
|
||||
id UInt64,
|
||||
value String
|
||||
) ENGINE=MergeTree
|
||||
ORDER BY id AS SELECT id, value FROM test;
|
||||
|
||||
DROP VIEW IF EXISTS test_mv_pk;
|
||||
CREATE MATERIALIZED VIEW test_mv_pk
|
||||
(
|
||||
value String,
|
||||
id UInt64
|
||||
) ENGINE=MergeTree PRIMARY KEY value
|
||||
POPULATE AS SELECT value, id FROM test;
|
||||
|
||||
SELECT name, primary_key
|
||||
FROM system.tables
|
||||
WHERE database = currentDatabase() AND name LIKE 'test%';
|
Loading…
Reference in New Issue
Block a user