学习目标
学习openGauss存储模型-行存和列存
行存储是指将表按行存储到硬盘分区上,列存储是指将表按列存储到硬盘分区上。默认情况下,创建的表为行存储。
行、列存储模型各有优劣,通常用于TP场景的数据库,默认使用行存储,仅对执行复杂查询且数据量大的AP场景时,才使用列存储
1.创建行存表
CREATE TABLE test_t1
(
col1 CHAR(2),
col2 VARCHAR2(40),
col3 NUMBER
);
复制
–压缩属性为no
\d+ test_t1
insert into test_t1 select col1, col2, col3 from (select generate_series(1, 100000) as key, repeat(chr(int4(random() * 26) + 65), 2) as col1, repeat(chr(int4(random() * 26) + 65), 30) as col2, (random() * (10^4))::integer as col3);
复制
2.创建列存表
CREATE TABLE test_t2
(
col1 CHAR(2),
col2 VARCHAR2(40),
col3 NUMBER
)
WITH (ORIENTATION = COLUMN);
复制
–压缩属性为low
\d+ test_t2;
复制
–插入和行存表相同的数据
insert into test_t2 select * from test_t1;
复制
3.占用空间对比
\d+
复制
4.对比读取一列的速度
analyze VERBOSE test_t1;
analyze VERBOSE test_t2;
复制
–列存表时间少于行存表
explain analyze select distinct col1 from test_t1;
explain analyze select distinct col1 from test_t2;
复制
5.对比插入一行的速度
–行存表时间少于列存表
explain analyze insert into test_t1 values('x', 'xxxx', '123');
复制
explain analyze insert into test_t2 values('x', 'xxxx', '123');
复制
6.清理数据
drop table test_t1;
复制
drop table test_t2;
复制
课程作业
1. 创建行存表和列存表,并批量插入10万条数据(行存表和列存表数据相同)
创建行存表
Create table test1(t_id int,t_name);
Insert into test1 values(generate_series(1, 10000);
Create table test2(t_id int ,t_name) WITH (ORIENTATION = COLUMN);
Insert into test1 values(generate_series(1, 10000);
复制
2. 对比行存表和列存表空间大小
\d+
omm=# \d+
List of relations
Schema | Name | Type | Owner | Size | Storage | Description
--------±-----------±------±------±-----------±-------------------------------------±------------
public | customer_t | table | omm | 8192 bytes | {orientation=row,compression=no} |
public | t1 | table | omm | 3568 kB | {orientation=row,compression=no} |
public | t2 | table | omm | 328 kB | {orientation=column,compression=low} |
(3 rows)
复制
3. 对比查询一列和插入一行的速
analyze VERBOSE test1;
analyze VERBOSE test2;
explain analyze insert into test1 values(10001,'a');
explain analyze insert into test2 values(10001,'a');
复制
4.清理数据
Drop table test1;
Drop table test2;
复制
最后修改时间:2022-09-08 10:08:58
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
文章被以下合辑收录
评论
相关阅读
openGauss荣获中国软件行业协会多奖项,技术升级再创行业新高度
openGauss
462次阅读
2025-04-30 14:30:58
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
MogDB
302次阅读
2025-04-17 10:41:41
MogDB 发布更新,解决 openGauss 数据库在长事务情况下Ustore表膨胀问题
云和恩墨
198次阅读
2025-04-16 09:52:02
GitCode 成 openGauss 新归宿,国产开源数据库里程碑事件
严少安
157次阅读
2025-04-27 11:37:53
荣誉时刻!openGauss认证证书快递已发,快来看看谁榜上有名!
墨天轮小教习
150次阅读
2025-04-23 17:39:13
单个执行机并行执行MySQL到openGauss数据迁移子任务
Clipnosis
131次阅读
2025-04-30 16:39:58
openGauss6.0.0适配操作系统自带的软件,不依赖三方库
来杯拿铁
91次阅读
2025-04-18 10:49:53
opengauss使用gs_probackup进行增量备份恢复
进击的CJR
85次阅读
2025-04-09 16:11:58
Postgresql数据库单个Page最多存储多少行数据
maozicb
79次阅读
2025-04-23 16:02:19
openGauss新特性 | openGauss-DataVec向量数据库特性介绍
openGauss
49次阅读
2025-04-17 10:41:47