diff --git a/src/catalog/src/kvbackend/manager.rs b/src/catalog/src/kvbackend/manager.rs index 93536ab73f4..5e7de6fe31c 100644 --- a/src/catalog/src/kvbackend/manager.rs +++ b/src/catalog/src/kvbackend/manager.rs @@ -127,13 +127,11 @@ impl CatalogManager for KvBackendCatalogManager { .try_collect::>() .await .map_err(BoxedError::new) - .context(ListSchemasSnafu { catalog })? - .into_iter() - .collect::>(); + .context(ListSchemasSnafu { catalog })?; - keys.extend_from_slice(&self.system_catalog.schema_names()); + keys.extend(self.system_catalog.schema_names()); - Ok(keys) + Ok(keys.into_iter().collect()) } async fn table_names(&self, catalog: &str, schema: &str) -> CatalogResult> { diff --git a/src/catalog/src/memory/manager.rs b/src/catalog/src/memory/manager.rs index 008a1886d75..dea21bb7ac0 100644 --- a/src/catalog/src/memory/manager.rs +++ b/src/catalog/src/memory/manager.rs @@ -143,6 +143,12 @@ impl MemoryCatalogManager { schema: DEFAULT_PRIVATE_SCHEMA_NAME.to_string(), }) .unwrap(); + manager + .register_schema_sync(RegisterSchemaRequest { + catalog: DEFAULT_CATALOG_NAME.to_string(), + schema: INFORMATION_SCHEMA_NAME.to_string(), + }) + .unwrap(); manager } @@ -256,6 +262,7 @@ impl MemoryCatalogManager { Arc::downgrade(self) as Weak, ); let information_schema = information_schema_provider.tables().clone(); + let mut catalog = HashMap::new(); catalog.insert(INFORMATION_SCHEMA_NAME.to_string(), information_schema); catalog diff --git a/src/common/meta/src/key.rs b/src/common/meta/src/key.rs index fc15932103f..d0e24c309b2 100644 --- a/src/common/meta/src/key.rs +++ b/src/common/meta/src/key.rs @@ -64,7 +64,7 @@ use std::sync::Arc; use bytes::Bytes; use common_catalog::consts::{ - DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME, DEFAULT_SCHEMA_NAME, + DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME, DEFAULT_SCHEMA_NAME, INFORMATION_SCHEMA_NAME, }; use common_telemetry::warn; use datanode_table::{DatanodeTableKey, DatanodeTableManager, DatanodeTableValue}; @@ -297,17 +297,20 @@ impl TableMetadataManager { pub async fn init(&self) -> Result<()> { let catalog_name = CatalogNameKey::new(DEFAULT_CATALOG_NAME); - let public_schema_name = SchemaNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME); - let private_schema_name = - SchemaNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME); self.catalog_manager().create(catalog_name, true).await?; - self.schema_manager() - .create(public_schema_name, None, true) - .await?; - self.schema_manager() - .create(private_schema_name, None, true) - .await?; + + let internal_schemas = [ + DEFAULT_SCHEMA_NAME, + INFORMATION_SCHEMA_NAME, + DEFAULT_PRIVATE_SCHEMA_NAME, + ]; + + for schema_name in internal_schemas { + let schema_key = SchemaNameKey::new(DEFAULT_CATALOG_NAME, schema_name); + + self.schema_manager().create(schema_key, None, true).await?; + } Ok(()) } diff --git a/tests/cases/standalone/common/system/information_schema.result b/tests/cases/standalone/common/system/information_schema.result index 5fe65d13aa3..e05ec496d1a 100644 --- a/tests/cases/standalone/common/system/information_schema.result +++ b/tests/cases/standalone/common/system/information_schema.result @@ -1,3 +1,8 @@ +-- should not able to create information_schema +create database information_schema; + +Error: 1004(InvalidArguments), Schema information_schema already exists + -- scripts table has different table ids in different modes select * from information_schema.tables @@ -37,24 +42,24 @@ select * from information_schema.columns order by table_schema, table_name; | greptime | information_schema | column_statistics | column_name | String | FIELD | | greptime | information_schema | column_statistics | table_name | String | FIELD | | greptime | information_schema | column_statistics | schema_name | String | FIELD | -| greptime | information_schema | columns | table_schema | String | FIELD | +| greptime | information_schema | columns | table_name | String | FIELD | | greptime | information_schema | columns | semantic_type | String | FIELD | | greptime | information_schema | columns | data_type | String | FIELD | | greptime | information_schema | columns | column_name | String | FIELD | -| greptime | information_schema | columns | table_name | String | FIELD | +| greptime | information_schema | columns | table_schema | String | FIELD | | greptime | information_schema | columns | table_catalog | String | FIELD | -| greptime | information_schema | engines | xa | String | FIELD | | greptime | information_schema | engines | savepoints | String | FIELD | +| greptime | information_schema | engines | xa | String | FIELD | | greptime | information_schema | engines | transactions | String | FIELD | | greptime | information_schema | engines | comment | String | FIELD | | greptime | information_schema | engines | support | String | FIELD | | greptime | information_schema | engines | engine | String | FIELD | +| greptime | information_schema | tables | table_schema | String | FIELD | | greptime | information_schema | tables | table_catalog | String | FIELD | | greptime | information_schema | tables | engine | String | FIELD | | greptime | information_schema | tables | table_id | UInt32 | FIELD | | greptime | information_schema | tables | table_type | String | FIELD | | greptime | information_schema | tables | table_name | String | FIELD | -| greptime | information_schema | tables | table_schema | String | FIELD | | greptime | public | numbers | number | UInt32 | TAG | +---------------+--------------------+-------------------+------------------+-----------+---------------+ @@ -103,7 +108,7 @@ from information_schema.columns where table_catalog = 'greptime' and table_schema != 'public' and table_schema != 'information_schema' -order by table_schema, table_name; +order by table_schema, table_name, column_name; +---------------+--------------+------------+-------------+----------------------+---------------+ | table_catalog | table_schema | table_name | column_name | data_type | semantic_type | diff --git a/tests/cases/standalone/common/system/information_schema.sql b/tests/cases/standalone/common/system/information_schema.sql index aa269d01252..8916842af42 100644 --- a/tests/cases/standalone/common/system/information_schema.sql +++ b/tests/cases/standalone/common/system/information_schema.sql @@ -1,3 +1,6 @@ +-- should not able to create information_schema +create database information_schema; + -- scripts table has different table ids in different modes select * from information_schema.tables @@ -33,7 +36,7 @@ from information_schema.columns where table_catalog = 'greptime' and table_schema != 'public' and table_schema != 'information_schema' -order by table_schema, table_name; +order by table_schema, table_name, column_name; use public;