PostgreSQL 字段使用pglz压缩测试

PostgreSQL 字段使用pglz压缩测试

测试一:

创建测试表 yewu1.test1,并插入1000w行数据
创建测试表 yewu1.test2,使用 pglz压缩字段,并插入1000w行数据

–创建测试表1,并插入1000w行数据

white=# create table yewu1.test1 (name varchar(20));
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test1'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | name     | 
(7 rows)
white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test1 VALUES ('white ' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test1')) AS table_size;table_size 
------------422 MB
(1 row)

–创建测试表2,使用 pglz压缩字段,并插入1000w行数据

white=# 
white=# create table yewu1.test2 (name varchar(20) COMPRESSION pglz);
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test2'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | name     | p
(7 rows)
white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test2 VALUES ('white ' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test2')) AS table_size;table_size 
------------422 MB
(1 row)

对比表yewu1.test1和yewu1.test2的大小,没体现出压缩了。

测试二:

创建测试表 yewu1.test3,text数据类型,并插入1000w行数据
创建测试表 yewu1.test4,text数据类型,使用 pglz压缩字段,并插入1000w行数据

–创建测试表3,并插入1000w行数据

white=# create table yewu1.test3 (name text);
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test3'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | name     | 
(7 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test3 VALUES ('white ' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test3')) AS table_size;table_size 
------------422 MB
(1 row)

–创建测试表4,使用 pglz压缩字段,并插入1000w行数据

white=# create table yewu1.test4 (name text COMPRESSION pglz);
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test4'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | name     | p
(7 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test4 VALUES ('white ' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test4')) AS table_size;table_size 
------------422 MB
(1 row)

对比表yewu1.test3和yewu1.test4的大小,没体现出压缩了。

测试三:

创建测试表 yewu1.test5,text数据类型,并插入1000w行重复的数据
创建测试表 yewu1.test6,text数据类型,使用 pglz压缩字段,并插入1000w行重复的数据

–创建测试表5,并插入1000w行重复的数据

white=# create table yewu1.test5 (name text);
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test5'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | name     | 
(7 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test5 VALUES ('white12345678');
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test5')) AS table_size;table_size 
------------422 MB
(1 row)

–创建测试表6,使用 pglz压缩字段,并插入1000w行重复的数据

white=# create table yewu1.test6 (name text COMPRESSION pglz);
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test6'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | name     | p
(7 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test6 VALUES ('white12345678');
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test6')) AS table_size;table_size 
------------422 MB
(1 row)

对比表yewu1.test5和yewu1.test6的大小,没体现出压缩了。

测试四:

创建测试表 yewu1.test7,带有主键,text数据类型,并插入1000w行重复的数据
创建测试表 yewu1.test8,带有主键,text数据类型,使用 pglz压缩字段,并插入1000w行重复的数据

–创建测试表7,带有主键,并插入1000w行重复的数据

white=# create table yewu1.test7 (
white(#     id serial primary key,
white(#     name text
white(# );
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test7'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | id       | name     | 
(8 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test7 VALUES (aa,'white' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test7')) AS table_size;table_size 
------------490 MB
(1 row)

–创建测试表8,带有主键,使用 pglz压缩字段,并插入1000w行重复的数据

white=# create table yewu1.test8 (
white(#     id serial primary key,
white(#     name text COMPRESSION pglz
white(# );
CREATE TABLE
white=# 
white=# SELECT attname, attcompression
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test8'::regclass;attname  | attcompression 
----------+----------------tableoid | cmax     | xmax     | cmin     | xmin     | ctid     | id       | name     | p
(8 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test8 VALUES (aa,'white' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test8')) AS table_size;table_size 
------------490 MB
(1 row)

对比表yewu1.test7和yewu1.test8的大小,没体现出压缩了。

测试五:

清空测试表 yewu1.test8,并修改字段存储类型为MAIN,再插入1000w行重复的数据

–清空测试表8,并修改字段存储类型为MAIN,再插入1000w行重复的数据

white=# truncate table yewu1.test8;
TRUNCATE TABLE
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test8')) AS table_size;table_size 
------------8192 bytes
(1 row)white=# 
white=# SELECT attname, attcompression,attstorage
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test8'::regclass;attname  | attcompression | attstorage 
----------+----------------+------------tableoid |                | pcmax     |                | pxmax     |                | pcmin     |                | pxmin     |                | pctid     |                | pid       |                | pname     | p              | x
(8 rows)white=# 
white=# ALTER TABLE yewu1.test8 ALTER COLUMN name SET STORAGE MAIN;
ALTER TABLE
white=# SELECT attname, attcompression,attstorage
white-# FROM pg_attribute
white-# WHERE attrelid = 'yewu1.test8'::regclass;attname  | attcompression | attstorage 
----------+----------------+------------tableoid |                | pcmax     |                | pxmax     |                | pcmin     |                | pxmin     |                | pctid     |                | pid       |                | pname     | p              | m
(8 rows)white=# 
white=# DO $$
white$# DECLARE aa INTEGER;
white$# BEGIN
white$#     FOR aa IN 1..10000000 LOOP
white$#         INSERT INTO yewu1.test8 VALUES (aa,'white' || aa);
white$# END LOOP;
white$# COMMIT;
white$# END $$;
DO
white=# 
white=# SELECT pg_size_pretty(pg_table_size('yewu1.test8')) AS table_size;table_size 
------------490 MB
(1 row)

–未完待续。思路错了,pg的压缩表有限制

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/881255.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Word办公自动化的一些方法

1.Word部分内容介绍 word本身是带有格式的一种文档,有人说它本质是XML,所以一定要充分利用标记了【样式】的特性来迅速调整【格式】,从而专心编辑文档内容本身。 样式(集) 编号(多级关联样式编号&#xff…

操作系统 | 学习笔记 | 王道 | 3.1 内存管理概念

3 内存管理 3.1 内存管理概念 3.1.1 内存管理的基本原理和要求 内存可以存放数据,程序执行前需要先放到内存中才能被CPU处理—缓和cpu和磁盘之间的速度矛盾 内存管理的概念 虽然计算机技术飞速发展,内存容量也在不断扩大,但仍然不可能将所有…

Kubernetes-环境篇-02-ubuntu开发环境搭建

1、ubuntu基础环境 # 更新apt软件源 sudo apt update# 安装git sudo apt install git# 安装python3 sudo apt install -y python3 python3-pip# 安装vim sudo apt install vim2、安装go 2.1 下载go安装包 wget https://golang.google.cn/dl/go1.23.2.linux-amd64.tar.gz2.2 …

【Qt】控件概述(7)—— 布局管理器

布局管理器 1. 布局管理器2. QVBoxLayout——垂直布局3. QHBoxLayout——水平布局4. QGridLayout——网格布局5. QFormLayout——表单布局6. QSpacer 1. 布局管理器 在我们之前值ui界面进行拖拽设置控件时,都是通过手动的控制控件的位置的。同时每个控件的位置都是…

OpenGL ES 纹理(7)

OpenGL ES 纹理(7) 简述 通过前面几章的学习,我们已经可以绘制渲染我们想要的逻辑图形了,但是如果我们想要渲染一张本地图片,这就需要纹理了。 纹理其实是一个可以用于采样的数据集,比较典型的就是图片了,我们知道我…

【STM32开发之寄存器版】(六)-通用定时器中断

一、前言 STM32定时器分类 STM32103ZET6具备8个定时器TIMx(x 1,2,...,8)。其中,TIM1和TIM8为高级定时器,TIM2-TIM6为通用定时器,TIM6和TIM7为基本定时器,本文将以TIM3通用定时器为例,分析STM32定时器工作的底层寄存器…

深度学习基础—残差网络ResNets

1.残差网络结构 当网络训练的很深很深的时候,效果是否会很好?在这篇论文中,作者给出了答案:Deep Residual Learning for Image Recognitionhttps://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/He_Deep_Residual_…

EmEditor传奇脚本编辑器

主程序:EmEditor.exe 目前已有功能 可以自己指定一个快捷键 实现以下功能(默认快捷键为:F1) 以下全功能 都是鼠标所在行 按快捷键 (默认快捷键:F1) 1.在Merchant.txt中 一键打开NPC 没有…

Linux 外设驱动 应用 1 IO口输出

从这里开始外设驱动介绍,这里使用的IMX8的芯片作为驱动介绍 开发流程: 修改设备树,配置 GPIO1_IO07 为 GPIO 输出。使用 sysfs 接口或编写驱动程序控制 GPIO 引脚。编译并测试。 这里假设设备树,已经配置好了。不在论述这个问题…

Steam Deck掌机可装“黑苹果” 开发者成功安装macOS 15 Sequoia

在Steam Deck掌机上运行Windows 11相对轻松,但要让其成功搭载“黑苹果”系统则颇具挑战性。近日,有博主勇于尝试,将macOS 15 Sequoia安装到了Steam Deck上。 开发者kaitlyn在X平台上分享道:“在朋友们的鼎力相助下,我…

SQL专项练习第六天

Hive 在处理不同数据需求时的灵活性和强大功能,包括间隔连续问题的处理、行列转换、交易数据查询、用户登录统计以及专利数据分析等方面。本文将介绍五个 Hive 数据处理问题的解决方案,并通过实际案例进行演示。 先在home文件夹下建一个hivedata文件夹&a…

Unity Shader Graph基础包200+节点及术语解释

目录 Master Stack: Vertex block: Fragment block​编辑 Alpha Clip Threshold Dither transparency Graph Inspector Texture 2d Array/Texture 3d Virtual Texture Sampler State Keywords Boolean keyword 右键显示所有节点 简化测试系列节点&#x…

初入网络学习第一篇

引言 不磨磨唧唧,跟着学就好了,这个是我个人整理的学习内容梳理,学完百分百有收获。 1、使用的网络平台:eNSP 下载方法以及内容参考这篇文章 华为 eNSP 模拟器安装教程(内含下载地址)_ensp下载-CSDN博客https://b…

DBMS-3.4 SQL(4)——存储过程和函数触发器

本文章的素材与知识来自李国良老师和王珊老师。 存储过程和函数 一.存储过程 1.语法 2.示例 (1) 使用DELIMITER更换终止符后用于编写存储过程语句后,在下次执行SQL语句时记得再使用DELIMITER将终止符再换回分号。 使用DELIMITER更换终止符…

数据分布过于集中 怎么办,python 人工智能 ,数据分析,机器学习pytorch tensorflow ,

数据分布过于集中,意味着数据的大部分值都聚集在某个特定区间内,这可能会导致统计分析的结果不够稳健,或者模型训练时出现过拟合等问题。针对这种情况,可以考虑以下几种方法来处理: 变换成 1. **数据转换**&#xff1…

MySQL多表查询:列子查询

先看我的表数据 dept表 emp表 列子查询,也就是多列作为子查询去寻找一些问题 常用操作符:IN, NOT IN, ANY, SOME, ALL 1.查询 "销售部" 和 "市场部" 的所有员工的信息(拆分成以下两个问题) a. 查询"销…

基于STM32的数字温度传感器设计与实现

引言 STM32 是由意法半导体(STMicroelectronics)开发的基于 ARM Cortex-M 内核的微控制器系列,以其强大的处理能力、丰富的外设接口和低功耗著称,广泛应用于嵌入式系统设计中。在这篇文章中,我们将介绍如何基于 STM32…

如何用python抓取豆瓣电影TOP250

1.如何获取网站信息? (1)调用requests库、bs4库 #检查库是否下载好的方法:打开终端界面(terminal)输入pip install bs4, 如果返回的信息里有Successfully installed bs4 说明安装成功(request…

OJ在线评测系统 微服务 OpenFeign调整后端下 nacos注册中心配置 不给前端调用的代码 全局引入负载均衡器

OpenFeign内部调用二 4.修改各业务服务的调用代码为feignClient 开启nacos注册 把Client变成bean 该服务仅内部调用,不是给前端的 将某个服务标记为“内部调用”的目的主要有以下几个方面: 安全性: 内部API通常不对外部用户公开,这样可以防止…

Linux操作系统——概念扫盲I

目录 虚拟机概念刨析 在那之前,询问什么是虚拟化? 现在来看看什么是虚拟机 虚拟机有啥好的 小差:那JVM也叫Java Virtual Machine,有啥区别呢? Reference 虚拟机概念刨析 我们下面来简单聊聊虚拟机这个概念。对于…