MatrixOne 数据库统计信息
MatrixOne 数据库统计信息是指数据库通过采样、统计出来的表、列的相关信息,例如,表的个数、表的列数、表所占的存储空间等。MatrixOne 数据库在生成执行计划时,需要根据统计信息进行估算,计算出最优的执行计划。
MatrixOne 数据库的统计信息维度如下:
查看数据库下表的个数
通过该命令,可以查看指定数据库下表的总数。
语法结构:
1. SHOW TABLE_NUMBER FROM {DATABASE_NAME}
示例
- 示例 1:查看系统数据库 mo_catalog 下的表的总数:
1. mysql> show table_number from mo_catalog;
2. +--------------------------------+
3. | Number of tables in mo_catalog |
4. +--------------------------------+
5. | 11 |
6. +--------------------------------+
8. -- 验证一下是哪些表
9. mysql> use mo_catalog;
10. mysql> show tables;
11. +----------------------------+
12. | Tables_in_mo_catalog |
13. +----------------------------+
14. | mo_user |
15. | mo_account |
16. | mo_role |
17. | mo_user_grant |
18. | mo_role_grant |
19. | mo_role_privs |
20. | mo_user_defined_function |
21. | mo_columns |
22. | mo_mysql_compatbility_mode |
23. | mo_tables |
24. | mo_database |
25. +----------------------------+
26. 11 rows in set (0.01 sec)
- 示例 2:创建数据库,并创建了新的表,查询指定数据库下表的总数:
1. create database demo_1;
2. use demo_1;
3. -- 创建三个新的表
4. CREATE TABLE t1(a bigint, b varchar(10), c varchar(10));
5. CREATE TABLE t2(a bigint, b int);
6. CREATE TABLE t3(a int, b varchar(10), c varchar(10));
8. -- 查询出数据库 demo_1 中有三个表
9. mysql> show table_number from demo_1;
10. +----------------------------+
11. | Number of tables in demo_1 |
12. +----------------------------+
13. | 3 |
14. +----------------------------+
15. 1 row in set (0.01 sec)
查看表拥有的列数
通过该命令,可以查看指定表的总列数。
语法结构:
1. SHOW COLUMN_NUMBER FROM {[DATABASE_NAME.]TABLE_NAME}
示例
1. use mo_catalog;
2. use mo_user;
3. mysql> show column_number from mo_user;
4. +------------------------------+
5. | Number of columns in mo_user |
6. +------------------------------+
7. | 11 |
8. +------------------------------+
10. -- 或者使用下面的命令
11. mysql> show column_number from mo_catalog.mo_user;
12. +------------------------------+
13. | Number of columns in mo_user |
14. +------------------------------+
15. | 11 |
16. +------------------------------+
18. -- 查看验证有哪些列
19. mysql> desc mo_catalog.mo_user;
20. +-----------------------+--------------+------+------+---------+-------+---------+
21. | Field | Type | Null | Key | Default | Extra | Comment |
22. +-----------------------+--------------+------+------+---------+-------+---------+
23. | user_id | INT | YES | | NULL | | |
24. | user_host | VARCHAR(100) | YES | | NULL | | |
25. | user_name | VARCHAR(300) | YES | | NULL | | |
26. | authentication_string | VARCHAR(100) | YES | | NULL | | |
27. | status | VARCHAR(8) | YES | | NULL | | |
28. | created_time | TIMESTAMP | YES | | NULL | | |
29. | expired_time | TIMESTAMP | YES | | NULL | | |
30. | login_type | VARCHAR(16) | YES | | NULL | | |
31. | creator | INT | YES | | NULL | | |
32. | owner | INT | YES | | NULL | | |
33. | default_role | INT | YES | | NULL | | |
34. +-----------------------+--------------+------+------+---------+-------+---------+
35. 11 rows in set (0.01 sec)
查看表中所有列包含的最大与最小值
通过该命令,可以查看指定表中的每一列的最大值与最小值。
Note: 如果指定表中各列值的数据类型不一致,则排序规则为:按照数字的大小排序;日期按照时间先后排序;字符类按照 ASCII 码排序;当几种数据类型混合排序时,非字符类型的则先转换为字符类型,然后按 ASCII 码排序。
语法结构:
1. SHOW TABLE_VALUES FROM {[DATABASE_NAME.]TABLE_NAME}
示例
1. create table t1(
2. col1 int,
3. col2 float,
4. col3 varchar
5. );
6. insert into t1 values(1,1.11,'1.111'),(2,2.22,'1.222'),(3,0,'abc');
8. mysql> show table_values from t1;
9. +-----------+-----------+-----------+-----------+-----------+-----------+
10. | max(col1) | min(col1) | max(col2) | min(col2) | max(col3) | min(col3) |
11. +-----------+-----------+-----------+-----------+-----------+-----------+
12. | 3 | 1 | 2.22 | 0 | abc | 1.111 |
13. +-----------+-----------+-----------+-----------+-----------+-----------+
查看表中的数据总行数
通过调用该函数,即可获得数据库中某张表的数据总行数。
语法结构:
1. MO_TABLE_ROWS({DATABASE_NAME},{TABLE_NAME})
示例
1. -- 查询数据库 mo_catalog 下表 mo_tables 的总行数
2. mysql> select mo_table_rows('mo_catalog','mo_tables');
3. +--------------------------------------+
4. | mo_table_rows(mo_catalog, mo_tables) |
5. +--------------------------------------+
6. | 64 |
7. +--------------------------------------+
查看表在存储中占用的空间
通过调用该函数,即可获得数据库中某张表占用的存储空间,单位是字节数。
语法结构:
1. MO_TABLE_SIZE({DATABASE_NAME},{TABLE_NAME})
示例
1. -- 查询数据库 mo_catalog 下表 mo_tables 占用的存储空间
2. mysql> select mo_table_size('mo_catalog','mo_tables');
3. +--------------------------------------+
4. | mo_table_size(mo_catalog, mo_tables) |
5. +--------------------------------------+
6. | 16128 |
7. +--------------------------------------+
