Skip to content

Commit

Permalink
fix: duplicate information_schema (#2979)
Browse files Browse the repository at this point in the history
* fix: duplicate information_schema

* chore: style

* fix: comment in sqlness
  • Loading branch information
killme2008 committed Dec 22, 2023
1 parent 7d509e9 commit d7b2e79
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/catalog/src/kvbackend/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,11 @@ impl CatalogManager for KvBackendCatalogManager {
.try_collect::<BTreeSet<_>>()
.await
.map_err(BoxedError::new)
.context(ListSchemasSnafu { catalog })?
.into_iter()
.collect::<Vec<_>>();
.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<Vec<String>> {
Expand Down
7 changes: 7 additions & 0 deletions src/catalog/src/memory/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -256,6 +262,7 @@ impl MemoryCatalogManager {
Arc::downgrade(self) as Weak<dyn CatalogManager>,
);
let information_schema = information_schema_provider.tables().clone();

let mut catalog = HashMap::new();
catalog.insert(INFORMATION_SCHEMA_NAME.to_string(), information_schema);
catalog
Expand Down
23 changes: 13 additions & 10 deletions src/common/meta/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}
Expand Down
15 changes: 10 additions & 5 deletions tests/cases/standalone/common/system/information_schema.result
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 |
+---------------+--------------------+-------------------+------------------+-----------+---------------+

Expand Down Expand Up @@ -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 |
Expand Down
5 changes: 4 additions & 1 deletion tests/cases/standalone/common/system/information_schema.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit d7b2e79

Please sign in to comment.