Skip to content

Commit

Permalink
sync to 1.1: adjust the db, table visibility in show accounts (#14924)
Browse files Browse the repository at this point in the history
1. index table(__index_xxx): do not counting it into the table_count, but need its size.
2. mo_increment_columns: do not counting it into the table_count, but need its size.
3. subscription db: do not count it into the db_count, and its size
4. sys table(mo_database, mo_tables, mo_column): count them into the table_count, and need their sizes

Approved by: @qingxinhome, @heni02, @sukki37
  • Loading branch information
gouhongshen committed Mar 13, 2024
1 parent efe2037 commit cfdc043
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions pkg/frontend/show_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ const (
idxOfComment = 5

// left the `size` as a placeholder, the value will be embedding later
// index table(__index_xxx): do not counting it into the `table_count`, but need its size.
// mo_increment_columns: do not counting it into the `table_count`, but need its size.
// subscription db: do not counting it into the `db_count`, and its size
// sys table(mo_database, mo_tables, mo_column): counting them into the `table_count`, and need their sizes
getTableStatsFormatV2 = "select " +
"( select " +
" mu2.user_name as `admin_name` " +
Expand All @@ -88,7 +92,9 @@ const (
"cast(0 as double) as `size` " +
"from " +
"mo_catalog.mo_tables as mt, mo_catalog.mo_database as md " +
"where mt.relkind != '%s' and mt.account_id = %d;"
"where md.dat_type != 'subscription' " +
"and mt.relkind in ('v','r','e','cluster') " +
"and mt.account_id in (%d, %d);"

// column index in the result set generated by
// the sql getTableStatsFormatV2
Expand Down Expand Up @@ -130,7 +136,8 @@ func getSqlForAccountInfo(accountId uint64) string {
}

func getSqlForTableStats(accountId int32) string {
return fmt.Sprintf(getTableStatsFormatV2, catalog.SystemPartitionRel, accountId)
//return fmt.Sprintf(getTableStatsFormatV2, catalog.SystemPartitionRel, accountId)
return fmt.Sprintf(getTableStatsFormatV2, accountId, sysAccountID)
}

func requestStorageUsage(ses *Session, accIds [][]int32) (resp any, tried bool, err error) {
Expand Down
4 changes: 2 additions & 2 deletions test/distributed/cases/tenant/tenant.result
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ create account tenant_test admin_name = 'root' open comment 'tenant_test';
SQL parser error: You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. syntax error at line 1 column 51 near " open comment 'tenant_test';";
show accounts;
account_name admin_name created status suspended_time db_count table_count size comment
tenant_test root 2023-11-12 12:43:41 open null 5 56 0.0 tenant_test
sys root 2023-11-12 03:33:41 open null 7 84 13.256612 system account
tenant_test root 2023-11-12 12:43:41 open null 5 50 0.0 tenant_test
sys root 2023-11-12 03:33:41 open null 7 72 13.256612 system account
drop account if exists tenant_test;
select account_id,relname,relkind from mo_catalog.mo_tables where reldatabase = 'mo_catalog' and relname not like '__mo_index_unique__%' order by relname;
account_id relname relkind
Expand Down

0 comments on commit cfdc043

Please sign in to comment.