作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
将数据库表拆分为请求最多的数据 和其余数据 是否会显着提高性能?我花了大约一周的时间观看了非常技术性的教程和 session ,但我仍然不清楚列数、列位置和行数在性能中的作用有多大(如果整个表适合内存/RAM ).
我选择了 4 个不同的选项。每种方法的优缺点是什么?
一些细节:
最佳答案
这是一个测试用例:
创建 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 秒。
你可以看到,可能会有很大的不同。但这取决于您的数据和查询。所以你应该做自己的基准测试。
注意事项:
seq_1_to_1000000
是一个1M序号的表。您需要先创建它或使用 MariaDBs Sequence 插件。关于mysql - 拆分数据库表为经常查询的数据+其他数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36971969/
当运行 scala.util.Random().nextInt(3) 81 次时,我看到如下结果(Java 开发人员,请参阅 edit 了解这之间的关系): 200010202002112102222
在使用 native 应用程序在混合模式 C++/CLI 中调试时,我遇到了进程挂起问题。这是无法忍受的,我的调试几乎 70% 都会发生这种情况,我需要一次又一次地重新启动该过程。 是否有任何修补程序
我不知道这是一个错误还是某种误用/错误配置。希望有人能帮忙。谢谢! 如果我更改模块或 list 目录中的文件,通常会导致错误,大部分是以下类型 无法找到节点上的类 在节点上找不到定义类 当 Puppe
我是一名优秀的程序员,十分优秀!