copy_par_regress_test-7.sql

application/sql

Filename: copy_par_regress_test-7.sql
Type: application/sql
Part: 0
Message: Re: speedup COPY TO for partitioned table.
begin;
drop table if exists pp;
CREATE TABLE pp (id int, val int, f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int ) PARTITION BY RANGE (id);
create table pp_110 partition of pp for values from (1) to (100_000) partition by range (id);
create table pp_112 partition of pp for values from (100_000) to (150_000) partition by range (id);
create table pp_113 partition of pp for values from (150_000) to (200_000) partition by range (id);
create table pp_114 partition of pp for values from (200_000) to (250_000) partition by range (id);
create table pp_115 partition of pp for values from (250_000) to (300_000) partition by range (id);
create table pp_116 partition of pp for values from (300_000) to (350_000) partition by range (id);
create table pp_117 partition of pp for values from (350_000) to (400_000) partition by range (id);
create table pp_118 partition of pp for values from (400_000) to (450_000) partition by range (id);
create table pp_119 partition of pp for values from (450_000) to (500_000) partition by range (id);
create table pp_120 partition of pp for values from (500_000) to (550_000) partition by range (id);

create table pp_121 partition of pp for values from (550_000) to (600_000) partition by range (id);
create table pp_122 partition of pp for values from (600_000) to (650_000) partition by range (id);
create table pp_123 partition of pp for values from (650_000) to (700_000) partition by range (id);
create table pp_124 partition of pp for values from (700_000) to (750_000) partition by range (id);
create table pp_125 partition of pp for values from (750_000) to (800_000) partition by range (id);
create table pp_126 partition of pp for values from (800_000) to (850_000) partition by range (id);
create table pp_127 partition of pp for values from (850_000) to (900_000) partition by range (id);
create table pp_128 partition of pp for values from (900_000) to (950_000) partition by range (id);
create table pp_129 partition of pp for values from (950_000) to (1000_000) partition by range (id);
create table pp_130 partition of pp for values from (1000_000) to (1_050_000) partition by range (id);

create table pp_131 partition of pp for values from (1_050_000) to (1_100_000) partition by range (id);
create table pp_132 partition of pp for values from (1_100_000) to (1_150_000) partition by range (id);
create table pp_133 partition of pp for values from (1_150_000) to (1_200_000) partition by range (id);
create table pp_134 partition of pp for values from (1_200_000) to (1_250_000) partition by range (id);
create table pp_135 partition of pp for values from (1_250_000) to (1_300_000) partition by range (id);
create table pp_136 partition of pp for values from (1_300_000) to (1_350_000) partition by range (id);
create table pp_137 partition of pp for values from (1_350_000) to (1_400_000) partition by range (id);
create table pp_138 partition of pp for values from (1_400_000) to (1_450_000) partition by range (id);
create table pp_139 partition of pp for values from (1_450_000) to (1_500_000) partition by range (id);
create table pp_140 partition of pp for values from (1_500_000) to (1_550_000) partition by range (id);

create table pp_110_1 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_2 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_3 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_4 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_5 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_6 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_7 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_8 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_9 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_10 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_11 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_12 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_13 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_14 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_15 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_16 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_17 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_18 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_19 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_20 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);

create table pp_110_21 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_22 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_23 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_24 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_25 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_26 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_27 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_28 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_29 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
create table pp_110_30 (val int, id int, f2 int, f1 int, f3 int, f4 int, f5 int, f6 int, f7 int, f8 int);
 
ALTER TABLE pp_110 ATTACH PARTITION pp_110_1 FOR VALUES FROM (1) TO (100_000);
ALTER TABLE pp_112 ATTACH PARTITION pp_110_2 for values from (100_000) to (150_000);
ALTER TABLE pp_113 ATTACH PARTITION pp_110_3 for values from (150_000) to (200_000);
ALTER TABLE pp_114 ATTACH PARTITION pp_110_4 for values from (200_000) to (250_000);
ALTER TABLE pp_115 ATTACH PARTITION pp_110_5 for values from (250_000) to (300_000);
ALTER TABLE pp_116 ATTACH PARTITION pp_110_6 for values from (300_000) to (350_000);
ALTER TABLE pp_117 ATTACH PARTITION pp_110_7 for values from (350_000) to (400_000);
ALTER TABLE pp_118 ATTACH PARTITION pp_110_8 for values from (400_000) to (450_000);
ALTER TABLE pp_119 ATTACH PARTITION pp_110_9 for values from (450_000) to (500_000);
ALTER TABLE pp_120 ATTACH PARTITION pp_110_10 for values from (500_000) to (550_000);

ALTER TABLE pp_121 ATTACH PARTITION pp_110_11 for values from (550_000) to (600_000);
ALTER TABLE pp_122 ATTACH PARTITION pp_110_12 for values from (600_000) to (650_000);
ALTER TABLE pp_123 ATTACH PARTITION pp_110_13 for values from (650_000) to (700_000);
ALTER TABLE pp_124 ATTACH PARTITION pp_110_14 for values from (700_000) to (750_000);
ALTER TABLE pp_125 ATTACH PARTITION pp_110_15 for values from (750_000) to (800_000);
ALTER TABLE pp_126 ATTACH PARTITION pp_110_16 for values from (800_000) to (850_000);
ALTER TABLE pp_127 ATTACH PARTITION pp_110_17 for values from (850_000) to (900_000);
ALTER TABLE pp_128 ATTACH PARTITION pp_110_18 for values from (900_000) to (950_000);
ALTER TABLE pp_129 ATTACH PARTITION pp_110_19 for values from (950_000) to (1000_000);
ALTER TABLE pp_130 ATTACH PARTITION pp_110_20 for values from (1000_000) to (1_050_000);

ALTER TABLE pp_131 ATTACH PARTITION pp_110_21 for values from (1_050_000) to (1_100_000);
ALTER TABLE pp_132 ATTACH PARTITION pp_110_22 for values from (1_100_000) to (1_150_000);
ALTER TABLE pp_133 ATTACH PARTITION pp_110_23 for values from (1_150_000) to (1_200_000);
ALTER TABLE pp_134 ATTACH PARTITION pp_110_24 for values from (1_200_000) to (1_250_000);
ALTER TABLE pp_135 ATTACH PARTITION pp_110_25 for values from (1_250_000) to (1_300_000);
ALTER TABLE pp_136 ATTACH PARTITION pp_110_26 for values from (1_300_000) to (1_350_000);
ALTER TABLE pp_137 ATTACH PARTITION pp_110_27 for values from (1_350_000) to (1_400_000);
ALTER TABLE pp_138 ATTACH PARTITION pp_110_28 for values from (1_400_000) to (1_450_000);
ALTER TABLE pp_139 ATTACH PARTITION pp_110_29 for values from (1_450_000) to (1_500_000);
ALTER TABLE pp_140 ATTACH PARTITION pp_110_30 for values from (1_500_000) to (1_550_000);

insert into pp select g, g+1, g, g, g, g, g, g, g, g from generate_series(1, 1_550_000 - 1) g;
commit;

analyze pp;
select count(*) from pp \watch i=0.1 c=2
--last time of the 10 execution
-- Time: 376.371 ms
copy (select * from pp) to '/tmp/1.txt' \watch i=0.1 c=10

--last time of the 10 execution
--Time: 359.463 ms
copy pp to '/tmp/2.txt' \watch i=0.1 c=10