Skip to content

Commit 43856cd

Browse files
zhrt123higuoxing
authored andcommitted
Fix bug: calculate AO table size in CTAS (#105)
The extension file with (segno=0, column=1) is not traversed by ao_foreach_extent_file(), we need to handle the size of it additionally. Co-authored-by: hzhang2 <hzhang2@vmware.com> Co-authored-by: Xing Guo <higuoxing+github@gmail.com>
1 parent 0dd04cb commit 43856cd

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

gpcontrib/diskquota/diskquota_utility.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,12 @@ calculate_relation_size_all_forks(RelFileNodeBackend *rnode, char relstorage)
12521252
RelationFileStatCtx ctx = {0};
12531253
ctx.relation_path = relpathbackend(rnode->node, rnode->backend, MAIN_FORKNUM);
12541254
ctx.size = 0;
1255+
/*
1256+
* Since the extension file with (segno=0, column=1) is not traversed by
1257+
* ao_foreach_extent_file(), we need to handle the size of it additionally.
1258+
* See comments in ao_foreach_extent_file() for details.
1259+
*/
1260+
relation_file_stat(0, &ctx);
12551261
ao_foreach_extent_file(relation_file_stat, &ctx);
12561262
return ctx.size;
12571263
}

gpcontrib/diskquota/tests/regress/expected/test_uncommitted_table_size.out

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ SELECT pg_table_size('ao');
123123
(1 row)
124124

125125
commit;
126-
-- AOCS table index
126+
-- AO table index
127127
begin;
128128
CREATE INDEX ao_idx on ao(i);
129129
SELECT pg_sleep(5);
@@ -144,6 +144,30 @@ SELECT pg_table_size('ao_idx');
144144
2490368
145145
(1 row)
146146

147+
commit;
148+
DROP TABLE ao;
149+
-- AO table CTAS
150+
begin;
151+
CREATE TABLE ao WITH(appendonly=true) AS SELECT generate_series(1, 10000);
152+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause. Creating a NULL policy entry.
153+
SELECT pg_sleep(5);
154+
pg_sleep
155+
----------
156+
157+
(1 row)
158+
159+
SELECT tableid::regclass, size, segid FROM diskquota.table_size WHERE tableid = 'ao'::regclass and segid = -1;
160+
tableid | size | segid
161+
---------+--------+-------
162+
ao | 329576 | -1
163+
(1 row)
164+
165+
SELECT pg_table_size('ao');
166+
pg_table_size
167+
---------------
168+
329576
169+
(1 row)
170+
147171
commit;
148172
DROP TABLE ao;
149173
-- AOCS table
@@ -194,3 +218,28 @@ SELECT pg_table_size('aocs_idx');
194218

195219
commit;
196220
DROP TABLE aocs;
221+
-- AOCS table CTAS
222+
begin;
223+
CREATE TABLE aocs WITH(appendonly=true, orientation=column) AS SELECT i, array(select * from generate_series(1,1000)) FROM generate_series(1, 100) AS i;
224+
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'i' as the Greenplum Database data distribution key for this table.
225+
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
226+
SELECT pg_sleep(5);
227+
pg_sleep
228+
----------
229+
230+
(1 row)
231+
232+
SELECT tableid::regclass, size, segid FROM diskquota.table_size WHERE tableid = 'aocs'::regclass and segid = -1;
233+
tableid | size | segid
234+
---------+--------+-------
235+
aocs | 763936 | -1
236+
(1 row)
237+
238+
SELECT pg_table_size('aocs');
239+
pg_table_size
240+
---------------
241+
763936
242+
(1 row)
243+
244+
commit;
245+
DROP TABLE aocs;

gpcontrib/diskquota/tests/regress/sql/test_uncommitted_table_size.sql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ SELECT tableid::regclass, size, segid FROM diskquota.table_size WHERE tableid =
4848
SELECT pg_table_size('ao');
4949
commit;
5050

51-
-- AOCS table index
51+
-- AO table index
5252
begin;
5353
CREATE INDEX ao_idx on ao(i);
5454
SELECT pg_sleep(5);
@@ -58,6 +58,15 @@ commit;
5858

5959
DROP TABLE ao;
6060

61+
-- AO table CTAS
62+
begin;
63+
CREATE TABLE ao WITH(appendonly=true) AS SELECT generate_series(1, 10000);
64+
SELECT pg_sleep(5);
65+
SELECT tableid::regclass, size, segid FROM diskquota.table_size WHERE tableid = 'ao'::regclass and segid = -1;
66+
SELECT pg_table_size('ao');
67+
commit;
68+
DROP TABLE ao;
69+
6170
-- AOCS table
6271
begin;
6372
CREATE TABLE aocs (i int, t text) WITH (appendonly=true, orientation=column);
@@ -76,3 +85,12 @@ SELECT pg_table_size('aocs_idx');
7685
commit;
7786

7887
DROP TABLE aocs;
88+
89+
-- AOCS table CTAS
90+
begin;
91+
CREATE TABLE aocs WITH(appendonly=true, orientation=column) AS SELECT i, array(select * from generate_series(1,1000)) FROM generate_series(1, 100) AS i;
92+
SELECT pg_sleep(5);
93+
SELECT tableid::regclass, size, segid FROM diskquota.table_size WHERE tableid = 'aocs'::regclass and segid = -1;
94+
SELECT pg_table_size('aocs');
95+
commit;
96+
DROP TABLE aocs;

0 commit comments

Comments
 (0)