Clean-up old metadata on TRUNCATE

merge-cstore-pykello
Hadi Moshayedi 2020-10-05 10:08:26 -07:00
parent 2e47bf5172
commit b72a4d8d19
6 changed files with 30 additions and 0 deletions

View File

@ -825,6 +825,7 @@ FdwNewRelFileNode(Relation relation)
if (OidIsValid(relation->rd_rel->relfilenode)) if (OidIsValid(relation->rd_rel->relfilenode))
{ {
RelationDropStorage(relation); RelationDropStorage(relation);
DeleteDataFileMetadataRowIfExists(relation->rd_rel->relfilenode);
} }
if (OidIsValid(relation->rd_rel->reltablespace)) if (OidIsValid(relation->rd_rel->reltablespace))

View File

@ -445,6 +445,9 @@ cstore_relation_set_new_filenode(Relation rel,
SMgrRelation srel; SMgrRelation srel;
CStoreOptions *options = CStoreTableAMGetOptions(); CStoreOptions *options = CStoreTableAMGetOptions();
/* delete old relfilenode metadata */
DeleteDataFileMetadataRowIfExists(rel->rd_node.relNode);
Assert(persistence == RELPERSISTENCE_PERMANENT); Assert(persistence == RELPERSISTENCE_PERMANENT);
*freezeXid = RecentXmin; *freezeXid = RecentXmin;
*minmulti = GetOldestMultiXactId(); *minmulti = GetOldestMultiXactId();

View File

@ -15,6 +15,7 @@ CREATE TABLE cstore_truncate_test_second (a int, b int) USING cstore_tableam;
-- COMPRESSED -- COMPRESSED
CREATE TABLE cstore_truncate_test_compressed (a int, b int) USING cstore_tableam; CREATE TABLE cstore_truncate_test_compressed (a int, b int) USING cstore_tableam;
CREATE TABLE cstore_truncate_test_regular (a int, b int); CREATE TABLE cstore_truncate_test_regular (a int, b int);
SELECT count(*) AS cstore_data_files_before_truncate FROM cstore.cstore_data_files \gset
INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a;
set cstore.compression = 'pglz'; set cstore.compression = 'pglz';
INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a;
@ -145,6 +146,13 @@ SELECT * from cstore_truncate_test;
---+--- ---+---
(0 rows) (0 rows)
-- make sure TRUNATE deletes metadata for old relfilenode
SELECT :cstore_data_files_before_truncate - count(*) FROM cstore.cstore_data_files;
?column?
----------
0
(1 row)
-- test if a cached truncate from a pl/pgsql function works -- test if a cached truncate from a pl/pgsql function works
CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$ CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$
BEGIN BEGIN

View File

@ -14,6 +14,7 @@ CREATE FOREIGN TABLE cstore_truncate_test (a int, b int) SERVER cstore_server;
CREATE FOREIGN TABLE cstore_truncate_test_second (a int, b int) SERVER cstore_server; CREATE FOREIGN TABLE cstore_truncate_test_second (a int, b int) SERVER cstore_server;
CREATE FOREIGN TABLE cstore_truncate_test_compressed (a int, b int) SERVER cstore_server OPTIONS (compression 'pglz'); CREATE FOREIGN TABLE cstore_truncate_test_compressed (a int, b int) SERVER cstore_server OPTIONS (compression 'pglz');
CREATE TABLE cstore_truncate_test_regular (a int, b int); CREATE TABLE cstore_truncate_test_regular (a int, b int);
SELECT count(*) AS cstore_data_files_before_truncate FROM cstore.cstore_data_files \gset
INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a;
INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a;
INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a;
@ -142,6 +143,13 @@ SELECT * from cstore_truncate_test;
---+--- ---+---
(0 rows) (0 rows)
-- make sure TRUNATE deletes metadata for old relfilenode
SELECT :cstore_data_files_before_truncate - count(*) FROM cstore.cstore_data_files;
?column?
----------
0
(1 row)
-- test if a cached truncate from a pl/pgsql function works -- test if a cached truncate from a pl/pgsql function works
CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$ CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$
BEGIN BEGIN

View File

@ -13,6 +13,8 @@ CREATE TABLE cstore_truncate_test_second (a int, b int) USING cstore_tableam;
CREATE TABLE cstore_truncate_test_compressed (a int, b int) USING cstore_tableam; CREATE TABLE cstore_truncate_test_compressed (a int, b int) USING cstore_tableam;
CREATE TABLE cstore_truncate_test_regular (a int, b int); CREATE TABLE cstore_truncate_test_regular (a int, b int);
SELECT count(*) AS cstore_data_files_before_truncate FROM cstore.cstore_data_files \gset
INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a;
set cstore.compression = 'pglz'; set cstore.compression = 'pglz';
@ -60,6 +62,9 @@ SELECT * from cstore_truncate_test_regular;
TRUNCATE TABLE cstore_truncate_test; TRUNCATE TABLE cstore_truncate_test;
SELECT * from cstore_truncate_test; SELECT * from cstore_truncate_test;
-- make sure TRUNATE deletes metadata for old relfilenode
SELECT :cstore_data_files_before_truncate - count(*) FROM cstore.cstore_data_files;
-- test if a cached truncate from a pl/pgsql function works -- test if a cached truncate from a pl/pgsql function works
CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$ CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$
BEGIN BEGIN

View File

@ -12,6 +12,8 @@ CREATE FOREIGN TABLE cstore_truncate_test_second (a int, b int) SERVER cstore_se
CREATE FOREIGN TABLE cstore_truncate_test_compressed (a int, b int) SERVER cstore_server OPTIONS (compression 'pglz'); CREATE FOREIGN TABLE cstore_truncate_test_compressed (a int, b int) SERVER cstore_server OPTIONS (compression 'pglz');
CREATE TABLE cstore_truncate_test_regular (a int, b int); CREATE TABLE cstore_truncate_test_regular (a int, b int);
SELECT count(*) AS cstore_data_files_before_truncate FROM cstore.cstore_data_files \gset
INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a;
INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test_compressed select a, a from generate_series(1, 10) a;
@ -57,6 +59,9 @@ SELECT * from cstore_truncate_test_regular;
TRUNCATE TABLE cstore_truncate_test; TRUNCATE TABLE cstore_truncate_test;
SELECT * from cstore_truncate_test; SELECT * from cstore_truncate_test;
-- make sure TRUNATE deletes metadata for old relfilenode
SELECT :cstore_data_files_before_truncate - count(*) FROM cstore.cstore_data_files;
-- test if a cached truncate from a pl/pgsql function works -- test if a cached truncate from a pl/pgsql function works
CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$ CREATE FUNCTION cstore_truncate_test_regular_func() RETURNS void AS $$
BEGIN BEGIN