diff --git a/pkg/cnservice/upgrader/new_add_table.go b/pkg/cnservice/upgrader/new_add_table.go index 1d45b889bfe1..dd84fbb5d7f3 100644 --- a/pkg/cnservice/upgrader/new_add_table.go +++ b/pkg/cnservice/upgrader/new_add_table.go @@ -615,8 +615,43 @@ var InformationSchemaPARTITIONS = &table.Table{ "WHERE `tbl`.`partitioned` = 1;"), } +var InformationSchemaTABLES = &table.Table{ + Account: table.AccountAll, + Database: sysview.InformationDBConst, + Table: "TABLES", + CreateViewSql: fmt.Sprintf("CREATE VIEW IF NOT EXISTS information_schema.TABLES AS "+ + "SELECT 'def' AS TABLE_CATALOG,"+ + "reldatabase AS TABLE_SCHEMA,"+ + "relname AS TABLE_NAME,"+ + "(case when relkind = 'v' and (reldatabase='mo_catalog' or reldatabase='information_schema') then 'SYSTEM VIEW' "+ + "when relkind = 'v' then 'VIEW' "+ + "when relkind = 'e' then 'EXTERNAL TABLE' "+ + "when relkind = 'r' then 'BASE TABLE' "+ + "else 'INTERNAL TABLE' end) AS TABLE_TYPE,"+ + "if(relkind = 'r','Tae',NULL) AS ENGINE,"+ + "if(relkind = 'v',NULL,10) AS VERSION,"+ + "'Compressed' AS ROW_FORMAT,"+ + "if(relkind = 'v', NULL, 0) AS TABLE_ROWS,"+ + "if(relkind = 'v', NULL, 0) AS AVG_ROW_LENGTH,"+ + "if(relkind = 'v', NULL, 0) AS DATA_LENGTH,"+ + "if(relkind = 'v', NULL, 0) AS MAX_DATA_LENGTH,"+ + "if(relkind = 'v', NULL, 0) AS INDEX_LENGTH,"+ + "if(relkind = 'v', NULL, 0) AS DATA_FREE,"+ + "if(relkind = 'v', NULL, internal_auto_increment(reldatabase, relname)) AS `AUTO_INCREMENT`,"+ + "created_time AS CREATE_TIME,"+ + "if(relkind = 'v', NULL, created_time) AS UPDATE_TIME,"+ + "if(relkind = 'v', NULL, created_time) AS CHECK_TIME,"+ + "'utf8mb4_0900_ai_ci' AS TABLE_COLLATION,"+ + "if(relkind = 'v', NULL, 0) AS CHECKSUM,"+ + "if(relkind = 'v', NULL, if(partitioned = 0, '', cast('partitioned' as varchar(256)))) AS CREATE_OPTIONS,"+ + "cast(rel_comment as text) AS TABLE_COMMENT "+ + "FROM mo_catalog.mo_tables tbl "+ + "WHERE tbl.account_id = current_account_id() and tbl.relname not like '%s' and tbl.relkind != '%s';", catalog.IndexTableNamePrefix+"%", catalog.SystemPartitionRel), +} + var needUpgradeExistingView = []*table.Table{ InformationSchemaSCHEMATA, InformationSchemaCOLUMNS, InformationSchemaPARTITIONS, + InformationSchemaTABLES, } diff --git a/pkg/util/sysview/sysview.go b/pkg/util/sysview/sysview.go index 3f7712209057..6b0f08549c1a 100644 --- a/pkg/util/sysview/sysview.go +++ b/pkg/util/sysview/sysview.go @@ -264,7 +264,7 @@ var ( "DATABASE_COLLATION varchar(64)" + ");", - fmt.Sprintf("CREATE VIEW IF NOT EXISTS TABLES AS "+ + fmt.Sprintf("CREATE VIEW IF NOT EXISTS information_schema.TABLES AS "+ "SELECT 'def' AS TABLE_CATALOG,"+ "reldatabase AS TABLE_SCHEMA,"+ "relname AS TABLE_NAME,"+ @@ -291,7 +291,7 @@ var ( "if(relkind = 'v', NULL, if(partitioned = 0, '', cast('partitioned' as varchar(256)))) AS CREATE_OPTIONS,"+ "cast(rel_comment as text) AS TABLE_COMMENT "+ "FROM mo_catalog.mo_tables tbl "+ - "WHERE tbl.relname not like '%s' and tbl.relkind != '%s';", catalog.IndexTableNamePrefix+"%", catalog.SystemPartitionRel), + "WHERE tbl.account_id = current_account_id() and tbl.relname not like '%s' and tbl.relkind != '%s';", catalog.IndexTableNamePrefix+"%", catalog.SystemPartitionRel), "CREATE VIEW IF NOT EXISTS `PARTITIONS` AS " + "SELECT " +