当前位置:网站首页>聊一聊数据库的行存与列存
聊一聊数据库的行存与列存
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 资源。
注意事项
边栏推荐
- The cornerstone of EMC - complete knowledge of electromagnetic compatibility filtering!
- @Documented 的作用
- Information system project manager must recite the core examination site (41) risk management plan
- Flowable workflow all business concepts
- The first common node of two linked lists -- two questions per day
- 2022年湖南工学院ACM集训第五次周测AD题题解
- 微信小程序隐藏滚动条的方法
- “蔚来杯“2022牛客暑期多校训练营2补题记录(DGHJKL)
- ArcGIS JS customizes the accessor and uses the watchutils related method to view the attribute
- Don't be afraid of ESD static electricity. This article tells you some solutions
猜你喜欢

EMC设计攻略 —时钟

【解决方案】可视化全链路日志追踪-日志追踪系统

干货|分享一个EMC实际案例及整改过程

CLion调试redis6源码

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

EMC rectification ideas

Rk3568 development board installation system startup

DNA cuinseqds near infrared CuInSe quantum dots wrapped deoxyribonucleic acid DNA

Elaborate on common mode interference and differential mode interference

EMC整改思路
随机推荐
[JVM optimization ultra detailed] common JVM tuning scenarios
谈谈DOM0,DOM1,DOM2,DOM3
EMC设计攻略 —时钟
【jvm优化超详细】常见的JVM调优场景
The underlying principles of RDB persistence and AOF persistence of redis
2022年湖南工学院ACM集训第五次周测AD题题解
【青鸟学员故事】追风少年“李晓亮”
Elaborate on common mode interference and differential mode interference
Cdn.jsdelivr.net is not available, what should I do
And is two numbers of S - two questions per day
EMC中的基石-电磁兼容滤波知识大全!
@Documented 的作用
What is the root cause of EMC's problems?
Introduction to magnetic ring selection and EMC rectification skills
Retryer of guava
CAS vs Database optimistic lock
干货|分享一个EMC实际案例及整改过程
Rk3568 development board installation system startup
EMC整改思路
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 supplementary question record (dghjkl)