利用系统缓存提高PostgreSQL操作效率(2)

3、建立表testmem,分别在使用和不适用pgfincore情况下进行select, update, delete的操作,并对比执行时间,在这里为了更好的去作比较,建立三张表testmem1,testmem2,testmem3,分别进行三种操作进行对比。并插入相同的数据。

[postgres@localhost bin]$ ./psql
psql (9.4.5)
Type "help" for help.
 
postgres=# \d
No relations found.
postgres=# create table testmem1(t1 int, t2 text, t3 text, t4 bigint, t5 text, t6 text, t7 varchar, t8 char(22), t9 numeric);CREATE TABLE
postgres=# create table testmem2(t1 int, t2 text, t3 text, t4 bigint, t5 text, t6 text, t7 varchar, t8 char(22), t9 numeric);
CREATE TABLE
postgres=# create table testmem3(t1 int, t2 text, t3 text, t4 bigint, t5 text, t6 text, t7 varchar, t8 char(22), t9 numeric);
CREATE TABLE
postgres=# insert into testmem1 select generate_series(1,999999), 'wangshuo'||generate_series(1,999999)::text||random()::text, generate_series(1,999999)::text||'sure',generate_series(1,999999), random()::text,random()::text,random()::text,'liuyuanyuan', generate_series(1,999999);
INSERT 0 999999
postgres=# select pg_relation_size('testmem1')/1024/1024||'MB';
 ?column?
----------
 166MB
(1 row)
 
postgres=# insert into testmem2 select generate_series(1,999999), 'wangshuo'||generate_series(1,999999)::text||random()::text, generate_series(1,999999)::text||'sure',generate_series(1,999999), random()::text,random()::text,random()::text,'liuyuanyuan', generate_series(1,999999);
INSERT 0 999999
postgres=# insert into testmem3 select generate_series(1,999999), 'wangshuo'||generate_series(1,999999)::text||random()::text, generate_series(1,999999)::text||'sure',generate_series(1,999999), random()::text,random()::text,random()::text,'liuyuanyuan', generate_series(1,999999);
INSERT 0 999999
postgres=# select pg_relation_size('testmem2')/1024/1024||'MB'; ?column?
----------
 166MB
(1 row)
 
postgres=# select pg_relation_size('testmem3')/1024/1024||'MB';
 ?column?
----------
 166MB
(1 row)
 
postgres=#

三种操作性能对比:

postgres=# select * from testmem1 where t1 < 789432 and t1 > 1208;
  t1  |                t2                |    t3    |  t4  |          t5
          |          t6          |          t7          |          t8         
 |  t9 
--------+------------------------------------+------------+--------+------------
----------+----------------------+----------------------+-----------------------
-+--------
  1209 | wangshuo12090.964191045146435      | 1209sure  |  1209 | 0.075409890
152514    | 0.468206159770489    | 0.692714618053287    | liuyuanyuan         
 |  1209
  1210 | wangshuo12100.652063825167716      | 1210sure  |  1210 | 0.026932121
720165    | 0.802233531605452    | 0.706556385848671    | liuyuanyuan         
 |  1210
  1211 | wangshuo12110.724962076637894      | 1211sure  |  1211 | 0.732285636
477172    | 0.816857317462564    | 0.868489125277847    | liuyuanyuan         
 |  1211
  1212 | wangshuo12120.0478062951005995    | 1212sure  |  1212 | 0.190716865
006834    | 0.898683389648795    | 0.537546805106103    | liuyuanyuan         
 |  1212
  1213 | wangshuo12130.582098880317062      | 1213sure  |  1213 | 0.161297460
086644    | 0.395338968373835    | 0.684920639265329    | liuyuanyuan         
 |  1213
  1214 | wangshuo12140.53120110463351      | 1214sure  |  1214 | 0.253457680
810243    | 0.428548218682408    | 0.671272001229227    | liuyuanyuan         
 
postgres=# update testmem2 set t7 = random()::text where t1 < 789432 and t1 > 1208;
UPDATE 788223
postgres=# delete from testmem3 where t1 < 789432 and t1 > 1208;
DELETE 788223
 

使用pgfincore前:通过查询表pg_stat_statments查看三种操作时间:


?

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/ccf3ad895676a5e8e1c2debc10cdfc74.html