在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

怎么理解PostgreSQL创建数据表时的参数fillfactor

117次阅读
没有评论

共计 6546 个字符,预计需要花费 17 分钟才能阅读完成。

这篇文章主要讲解了“怎么理解 PostgreSQL 创建数据表时的参数 fillfactor”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着丸趣 TV 小编的思路慢慢深入,一起来研究和学习“怎么理解 PostgreSQL 创建数据表时的参数 fillfactor”吧!

下面创建不同 fillfactor 的数据表, 执行 update 操作

[local]:5432 pg12@testdb=# create table t_fillfactor_100(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=100);
CREATE TABLE
Time: 2.462 ms
[local]:5432 pg12@testdb=# create table t_fillfactor_70(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=70);
CREATE TABLE
Time: 3.437 ms
[local]:5432 pg12@testdb=# create table t_fillfactor_50(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=50);
CREATE TABLE
Time: 28.553 ms
[local]:5432 pg12@testdb=# insert into t_fillfactor_100(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
INSERT 0 1000000
Time: 3583.216 ms (00:03.583)
[local]:5432 pg12@testdb=# insert into t_fillfactor_70(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
INSERT 0 1000000
Time: 6506.113 ms (00:06.506)
[local]:5432 pg12@testdb=# insert into t_fillfactor_50(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
INSERT 0 1000000
Time: 3113.901 ms (00:03.114)
[local]:5432 pg12@testdb=# update t_fillfactor_100 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad( c3 ,30, c3 
UPDATE 1000000
Time: 10641.794 ms (00:10.642)
[local]:5432 pg12@testdb=# update t_fillfactor_70 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad( c3 ,30, c3 
UPDATE 1000000
Time: 8563.046 ms (00:08.563)
[local]:5432 pg12@testdb=# update t_fillfactor_50 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad( c3 ,30, c3 
UPDATE 1000000
Time: 4036.735 ms (00:04.037)

可以看到, 在插入时,fillfactor 较高的数据表耗时较短, 而在 update 时 (全量),fillfactor 的则有较大的优势. 但, 经过多次 update 后, 耗时并不明显, 原因在于经过多次 update, 每个块的空闲空间跟 fillfactor=100 的设定已相差无几.

[local]:5432 pg12@testdb=# update t_fillfactor_100 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad( c3 ,30, c3 
UPDATE 1000000
Time: 4276.404 ms (00:04.276)
[local]:5432 pg12@testdb=# update t_fillfactor_70 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad( c3 ,30, c3 
UPDATE 1000000
Time: 3856.575 ms (00:03.857)
[local]:5432 pg12@testdb=# update t_fillfactor_50 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad( c3 ,30, c3 
UPDATE 1000000
Time: 4364.962 ms (00:04.365)
[local]:5432 pg12@testdb=#

重新创建表, 使用 pgbench 进行测试

[local]:5432 pg12@testdb=# drop table if exists t_fillfactor_100;
t,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=70);
create table t_fillfactor_50(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=50);
insert into t_fillfactor_100(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
insert into t_fillfactor_70(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
insert into t_fillfactor_50(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
DROP TABLE
Time: 191.706 ms
[local]:5432 pg12@testdb=# drop table if exists t_fillfactor_70;
DROP TABLE
Time: 35.313 ms
[local]:5432 pg12@testdb=# drop table if exists t_fillfactor_50;
DROP TABLE
Time: 30.078 ms
[local]:5432 pg12@testdb=# 
[local]:5432 pg12@testdb=# create table t_fillfactor_100(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=100);
CREATE TABLE
Time: 40.443 ms
[local]:5432 pg12@testdb=# create table t_fillfactor_70(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=70);
CREATE TABLE
Time: 1.334 ms
[local]:5432 pg12@testdb=# create table t_fillfactor_50(id int,c1 varchar(30),c2 varchar(30),c3 varchar(30)) with (fillfactor=50);
CREATE TABLE
Time: 1.024 ms
[local]:5432 pg12@testdb=# 
[local]:5432 pg12@testdb=# insert into t_fillfactor_100(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
INSERT 0 1000000
Time: 2623.943 ms (00:02.624)
[local]:5432 pg12@testdb=# insert into t_fillfactor_70(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
INSERT 0 1000000
Time: 2543.045 ms (00:02.543)
[local]:5432 pg12@testdb=# insert into t_fillfactor_50(id,c1,c2,c3) select x, c1 ||x, c2 ||x, c3 ||x from generate_series(1,1000000) as x;
INSERT 0 1000000
Time: 2662.223 ms (00:02.662)
[local]:5432 pg12@testdb=#

使用 pgbench 进行测试

[pg12@localhost script]$ cat update_100.sql 
\set id random(1,1000000)
begin;
update t_fillfactor_100 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad(c3 ,30, c3) where id= :id;
[pg12@localhost script]$ cat update_70.sql 
\set id random(1,1000000)
begin;
update t_fillfactor_70 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad(c3 ,30, c3) where id= :id;
[pg12@localhost script]$ cat update_50.sql 
\set id random(1,1000000)
begin;
update t_fillfactor_50 set c1=lpad(c1 ,30, c1),c2=lpad(c2 ,30, c2),c3=lpad(c3 ,30, c3) where id= :id;
[pg12@localhost script]$ pgbench -c 2 -C -f ~/script/update_100.sql -j 1 -n -T 60 -U pg12 testdb
transaction type: /home/pg12/script/update_100.sql
scaling factor: 1
query mode: simple
number of clients: 2
number of threads: 1
duration: 60 s
number of transactions actually processed: 691
latency average = 174.136 ms
tps = 11.485277 (including connections establishing)
tps = 11.625959 (excluding connections establishing)
[pg12@localhost script]$ pgbench -c 2 -C -f ~/script/update_70.sql -j 1 -n -T 60 -U pg12 testdb
transaction type: /home/pg12/script/update_70.sql
scaling factor: 1
query mode: simple
number of clients: 2
number of threads: 1
duration: 60 s
number of transactions actually processed: 652
latency average = 184.293 ms
tps = 10.852275 (including connections establishing)
tps = 10.981136 (excluding connections establishing)
[pg12@localhost script]$ pgbench -c 2 -C -f ~/script/update_50.sql -j 1 -n -T 60 -U pg12 testdb
transaction type: /home/pg12/script/update_50.sql
scaling factor: 1
query mode: simple
number of clients: 2
number of threads: 1
duration: 60 s
number of transactions actually processed: 627
latency average = 191.700 ms
tps = 10.432967 (including connections establishing)
tps = 10.551899 (excluding connections establishing)
[pg12@localhost script]$

使用 pgbench 使用随机值进行测试, 时长为 60s, 结果差别不大.

数据表大小的比较:

[local]:5432 pg12@testdb=# select pg_size_pretty(pg_relation_size( t_fillfactor_100 
 pg_size_pretty 
----------------
 58 MB
(1 row)
Time: 2.034 ms
[local]:5432 pg12@testdb=# select pg_size_pretty(pg_relation_size( t_fillfactor_70 
 pg_size_pretty 
----------------
 82 MB
(1 row)
Time: 1.469 ms
[local]:5432 pg12@testdb=# select pg_size_pretty(pg_relation_size( t_fillfactor_50 
 pg_size_pretty 
----------------
 117 MB
(1 row)
Time: 2.531 ms
[local]:5432 pg12@testdb=#

分别是 58MB vs 82MB vs 117MB ≈ 100 vs 70 vs 50

感谢各位的阅读,以上就是“怎么理解 PostgreSQL 创建数据表时的参数 fillfactor”的内容了,经过本文的学习后,相信大家对怎么理解 PostgreSQL 创建数据表时的参数 fillfactor 这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是丸趣 TV,丸趣 TV 小编将为大家推送更多相关知识点的文章,欢迎关注!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-26发表,共计6546字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 国内精品免费一区二区观看 | 在线免费观看视频a | 亚洲精品宾馆在线精品酒店 | 亚洲天堂成人在线 | 国产毛片久久久久久国产毛片 | 亚洲 欧美 综合 | 欧美精品久久久久久久久大尺度 | 亚洲人成色7777在线观看 | 国产精品三级av及在线观看 | 国产日韩精品视频一区二区三区 | 久久国产色av免费看 | 亚洲h视频在线观看 | 欧美在线精品一区二区三区 | 天堂资源在线www中文 | 日本一本视频 | 欧美性受xxxx白人性爽 | 国产精品久久久久久久专区 | 成人欧美日本免费观看 | 亚洲国产成人久久综合一区 | 精品亚洲永久免费精品 | 深夜大尺度视频在线观看 | 亚洲精品456在线播放 | 综合久久99久久99播放 | 男女在线无遮挡毛片免费 | 国产高清乱码又大又圆 | 午夜啪啪免费视频 | 久久涩视频 | 欧美一级片观看 | 中文乱码免费一区二区 | 欧美一级在线毛片免费观看 | 91欧美激情一区二区三区成人 | 欧美综合区自拍亚洲综合 | 国产精品久久久精品三级 | 日本精品在线观看视频 | 欧美视频国产 | 黑巨茎大战俄罗斯美女 | 亚洲色图综合网 | 久久这里只有精品免费看青草 | 欧美日韩国产亚洲一区二区三区 | 七七久久| 一级免费黄色片 |