[英]Mysql analyze table content
I forgotten the name of the SQL command to analyse the content of a table.我忘记了分析表格内容的SQL命令的名称。 The command I'm looking for shows me for each colum the min/max/avg length of the content.
我正在寻找的命令向我显示每列内容的最小/最大/平均长度。 If I remember correctly it starts with a normal select
如果我没记错的话,它以普通的 select 开头
SELECT * FROM table foo bar
All google searches shows me aggregate functions or "analyse table".所有谷歌搜索都向我显示聚合函数或“分析表”。 But that's not what I'm looking for.
但这不是我要找的。
https://dev.mysql.com/doc/refman/5.7/en/procedure-analyse.html https://dev.mysql.com/doc/refman/5.7/en/procedure-analysis.html
SELECT * FROM mytable PROCEDURE ANALYSE()
Note this is deprecated in MySQL 5.7 and removed in MySQL 8.0.请注意,这在 MySQL 5.7 中已弃用,并在 MySQL 8.0 中删除。
Hopefully someday there will be some other implementation (perhaps a MySQL Shell plugin) for users of 8.0.希望有一天会有一些其他的实现(可能是 MySQL Shell 插件)供 8.0 的用户使用。
Another way of doing this is to get the histogram of the table.另一种方法是获取表格的直方图。 It's more work, though.
不过,这是更多的工作。 For example:
例如:
create table customer (
name varchar(20),
salary int
);
Then insert 1000 random rows in the table:然后在表中插入 1000 个随机行:
insert into customer (name, salary)
with recursive
c (it, name, salary) as (
select 1, substring(md5(rand()) from 1 for 10), 50000
union all
select
it + 1,
substring(md5(rand()) from 1 for 10),
floor(rand() * (120000 - 22000 + 1)) + 22000
from c
where it < 1000
)
select name, salary from c;
Now that you have a table with data you can compute a histogram (with a single bucket) and get the value ranges for each column:现在您有了一个包含数据的表,您可以计算直方图(使用单个存储桶)并获取每列的值范围:
analyze table customer
update histogram on name, salary with 1 buckets;
select column_name,
histogram->>'$."buckets"[0][0]' as min_value,
histogram->>'$."buckets"[0][1]' as max_value
from information_schema.column_statistics
where table_name = 'customer'
Result:结果:
COLUMN_NAME min_value max_value
----------- ------------------------------- -------------------------------
name base64:type254:MDA2NzM2YmUwYQ== base64:type254:ZmZjNjJlYWNmMg==
salary 22089 119840
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.