当前位置:网站首页>聊一聊数据库的行存与列存
聊一聊数据库的行存与列存
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 资源。
注意事项
边栏推荐
- EMC整改思路
- Cdn.jsdelivr.net is not available, what should I do
- RFID辐射测试小结
- DNA modified osmium OS nanoparticles osnps DNA modified iridium nanoparticles irnps DNA
- .NET 6.0中使用Identity框架实现JWT身份认证与授权
- Pytorch的冻结以及解冻
- ASP.NET Core 技术内幕与项目实战读后感
- Dynamic memory management knowledge points
- leetcode 字符串类
- Awk from introduction to earth (16) discussion on the types of awk variables -- about the two types of numbers and strings
猜你喜欢

Flowable workflow all business concepts

What is the root cause of EMC's problems?

protobuf 基本语法总结

Opencv's practical learning of credit card recognition (4)

ArcGIS JS customizes the accessor and uses the watchutils related method to view the attribute

【google】解决google浏览器不弹出账号密码保存框且无法保存登录信息问题
![[solution] visual full link log tracking - log tracking system](/img/0c/f93c7d31e01257c5dee7d292ac7d84.jpg)
[solution] visual full link log tracking - log tracking system

EMC design strategy - clock

EMC中的基石-电磁兼容滤波知识大全!

EMC之 “不整改好别回来了”
随机推荐
Pytorch的冻结以及解冻
数据化管理洞悉零售及电子商务运营——数据化管理介绍
mysql,我们如何得到受查询影响的行数?
干货|分享一个EMC实际案例及整改过程
Chapter 01 introduction of [notes of Huashu]
解析树形结构 js
非关系型数据库之Redis【redis安装】
我们如何在mysql中运行批处理模式?
DNA修饰金属锇Os纳米颗粒OsNPS-DNA|DNA修饰金属铱纳米颗粒IrNPS-DNA
【干货】32个EMC标准电路分享!
The net loss of users occurred again, and China Mobile, which lost face, launched ultra-low price packages to win users
DNA修饰贵金属纳米颗粒|DNA修饰纳米铜颗粒CuNPS-DNA|研究要点
CLion调试redis6源码
Learn software testing in two weeks? I was shocked!
JUC原子类: CAS, Unsafe、CAS缺点、ABA问题如何解决详解
YOLO系列损失函数详解
How to understand the adjective prefix of socket: "connection oriented" and "connectionless"
【着色器实现Negative反色效果_Shader效果第十一篇】
【google】解决google浏览器不弹出账号密码保存框且无法保存登录信息问题
After being accidentally dragged into QQ fraud group