gpt4 book ai didi

mysql - 拆分数据库表为经常查询的数据+其他数据

转载 作者:搜寻专家 更新时间:2023-10-30 23:39:22 25 4
gpt4 key购买 nike

将数据库表拆分为请求最多的数据其余数据 是否会显着提高性能?我花了大约一周的时间观看了非常技术性的教程和 session ,但我仍然不清楚列数、列位置和行数在性能中的作用有多大(如果整个表适合内存/RAM ).

我选择了 4 个不同的选项。每种方法的优缺点是什么?


一些细节:

  • 主要阅读:至少 80% - 重点是表现
  • 10 个不同的类别 - 每个都有大约 10 万个条目/行
  • 每个类别 30 个总值
  • 5 个经常查询的值(用于列表和单个帖 subview )
  • 25 个查询频率较低的值(仅在单个帖 subview 中)
  • 要指定:如果我说,我指的是实体/数据库列

enter image description here

最佳答案

这是一个测试用例:

创建 100 万行的测试数据:

drop table if exists posts;
create table posts (
id int not null primary key,
summary varchar(255),
post text
) as
select seq as id
, repeat(rand(1), 10) as summary
, repeat(rand(1), 100) as post
from seq_1_to_1000000
;

drop table if exists small_data;
create table small_data (
id int not null primary key,
summary varchar(255)
) as select p.id, p.summary from posts p
;
drop table if exists big_data;
create table big_data (
id int not null primary key,
post text
) as select p.id, p.post from posts p;

show table status where Name in('posts', 'small_data', 'big_data');

Name | Engine | Row_format | Rows | Avg_row_length | Data_length
big_data | InnoDB | Compact | 870341 | 2361 | 2055208960
posts | InnoDB | Compact | 838832 | 2627 | 2204106752
small_data | InnoDB | Compact | 985832 | 229 | 226197504

所以一共有三个表。

  • posts ~ 2.1 GB。包含所有数据(id、summary ~ 200 Bytes、post ~ 2000 Bytes)。
  • small_data ~ 215 MB。包含(id,摘要)
  • 大数据 ~ 1.9 GB。包含(id,帖子)
select p.id, p.summary
from posts p
order by id asc
limit 10
offset 500000

第一次运行:16.552 秒。第二次运行:16.723 秒。

select p.id, p.summary
from small_data p
order by id asc
limit 10
offset 500000

第一次运行:0.702 秒。第二次运行:0.093 秒。

你可以看到,可能会有很大的不同。但这取决于您的数据和查询。所以你应该做自己的基准测试。

注意事项:

  • 在 10.0.19-MariaDB 上测试。
  • seq_1_to_1000000 是一个1M序号的表。您需要先创建它或使用 MariaDBs Sequence 插件。

关于mysql - 拆分数据库表为经常查询的数据+其他数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36971969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com