当前位置:网站首页>聊一聊数据库的行存与列存
聊一聊数据库的行存与列存
2022-07-28 06:14:00 【架构师社区】
原文:my.oschina.net/gaussdb/blog/5544252
存储方式比较

优缺点比较
行存 | 列存 | |
优点 | 数据被保存在一起。INSERT/UPDATE 容易。 |
|
缺点 | 选择 (Selection) 时即使只涉及某几列,所有数据也都会被读取。 |
|
适用场景 |
|
|
行存与列存实验
创建行存表 custom1 和列存表 custom2 ,插入 50 万条记录。
openGauss=# create table custom1 (id integer,name varchar2(20));CREATE TABLEopenGauss=# create table custom2 (id integer,name varchar2(20)) with (orientation = column);CREATE TABLEopenGauss=# insert into custom1 select n,'testtt'||n from generate_series(1,500000) n;INSERT 0 500000openGauss=# insert into custom2 select * from custom1;INSERT 0 500000
openGauss=# \d+List of relationsSchema | Name | Type | Owner | Size | Storage | Description--------+------------+-------+-------+------------+--------------------------------------+-------------public | custom1 | table | omm | 24 MB | {orientation=row,compression=no} |public | custom2 | table | omm | 3104 kB | {orientation=column,compression=low} |
openGauss=# explain analyze insert into custom1 values(1,'zhang3');QUERY PLAN-----------------------------------------------------------------------------------------------[Bypass]Insert on custom1 (cost=0.00..0.01 rows=1 width=0) (actual time=0.059..0.060 rows=1 loops=1)-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=1)Total runtime: 0.135 ms(4 rows)openGauss=# explain analyze insert into custom2 values(1,'zhang3');QUERY PLAN-----------------------------------------------------------------------------------------------Insert on custom2 (cost=0.00..0.01 rows=1 width=0) (actual time=0.119..0.120 rows=1 loops=1)-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.002 rows=1 loops=1)Total runtime: 0.207 ms(3 rows)
最后删除测试表。
openGauss=# drop table custom1;DROP TABLEopenGauss=#drop table custom2;DROP TABLE
选择建议
更新频繁程度:数据如果频繁更新,选择行存表。
插入频繁程度:频繁的少量插入,选择行存表。一次插入大批量数据,选择列存表。
表的列数:一般情况下,如果表的字段比较多即列数多(大宽表),查询中涉及到的列不多的情况下,适合列存储。如果表的字段个数比较少,查询大部分字段,那么选择行存储比较好。
查询的列数:如果每次查询时,只涉及了表的少数(<50% 总列数)几个列,选择列存表。(不要问剩下的列干啥用,甲方说有用就是有用。)
压缩率:列存表比行存表压缩率高。但高压缩率会消耗更多的 CPU 资源。
注意事项
边栏推荐
- Qt多线程中槽函数在哪个线程里执行分析
- 指针进阶练习
- Opencv's practical learning of credit card recognition (4)
- EMC's "don't come back until you rectify"
- 细说共模干扰和差模干扰
- The cornerstone of EMC - complete knowledge of electromagnetic compatibility filtering!
- YOLO系列损失函数详解
- Elaborate on common mode interference and differential mode interference
- EMC整改思路
- It has been rectified seven times and took half a month. Painful EMC summary
猜你喜欢
C language explanation series - array explanation, one-dimensional array, two-dimensional array

Retryer of guava

【着色器实现Negative反色效果_Shader效果第十一篇】

【jvm优化超详细】常见的JVM调优场景

解析树形结构 js

指针进阶练习

Near infrared two region agzs quantum dots wrapped deoxyribonucleic acid dna|dna agzsqds (Qiyue)
![[JVM optimization ultra detailed] common JVM tuning scenarios](/img/dd/3fed0b2bb6f00e5719982e38495e5c.jpg)
[JVM optimization ultra detailed] common JVM tuning scenarios

常用电子产品行业标准及认证

铜铟硫CuInSe2量子点修饰DNA(脱氧核糖核酸)DNA-CuInSe2QDs(齐岳)
随机推荐
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary question record (dghjkl)
DNA modified noble metal nanoparticles | DNA deoxyribonucleic acid modified metal palladium Pd nanoparticles pdnps DNA
【着色器实现Negative反色效果_Shader效果第十一篇】
整改了七次,花了半个月时间,惨痛的EMC总结
2022/7/27 考试总结
RFID辐射测试小结
Which of class A and class B is more stringent in EMC?
Collector原理解析
动态内存管理知识点
ESD静电不用怕,本文告诉你一些解决方法
Digital management insight into retail and e-commerce operations -- Introduction to digital management
How to analyze the taxi business problem of didi SQL interview question
xmpp 服务研究(二) prosody 创建账户
These mobile security browsers are more than a little easy to use
How to understand the adjective prefix of socket: "connection oriented" and "connectionless"
指针进阶练习
DNA-Ag2SQDs脱氧核糖核酸DNA修饰硫化银Ag2S量子点的合成方法
Why is ESD protection so important for integrated circuits? How to protect?
Forward propagation of deep learning neural networks (1)
谈谈DOM0,DOM1,DOM2,DOM3