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

Solve cross tenant system view query error #15264

Merged
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
35 changes: 35 additions & 0 deletions pkg/cnservice/upgrader/new_add_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
4 changes: 2 additions & 2 deletions pkg/util/sysview/sysview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,"+
Expand All @@ -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 " +
Expand Down