Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion columnar/src/backend/columnar/columnar_tableam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,45 @@ columnar_relation_nontransactional_truncate(Relation rel)
static void
columnar_relation_copy_data(Relation rel, const RelFileLocator *newrnode)
{
elog(ERROR, "columnar_relation_copy_data not implemented");
char persistence = rel->rd_rel->relpersistence;

/*
* Since we copy the file directly without looking at the shared buffers,
* we'd better first flush out any pages of the source relation that are
* in shared buffers. We assume on new changes will be made while we are
* holding exclusive lock on the rel.
*/
FlushRelationBuffers(rel);

#if PG_VERSION_NUM >= PG_VERSION_15
SMgrRelation srel = RelationCreateStorage(*newrnode, persistence, true);
#else
SMgrRelation srel = RelationCreateStorage(*newrnode, persistence);
#endif

/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), srel, MAIN_FORKNUM, persistence);

for (ForkNumber forkNum = MAIN_FORKNUM + 1;
forkNum <= MAX_FORKNUM; forkNum++)
{
if (smgrexists(srel, forkNum))
{
smgrcreate(srel, forkNum, false);

/*
* WAL log creation if the relation is persistent, or
* this is the init fork of an unlogged relation.
*/
if (RelationIsPermanent(rel) ||
(persistence == RELPERSISTENCE_UNLOGGED &&
forkNum == INIT_FORKNUM))
log_smgrcreate(newrnode, forkNum);

RelationCopyStorage(RelationGetSmgr(rel), srel,
forkNum, persistence);
}
}
}


Expand Down
1 change: 1 addition & 0 deletions columnar/src/test/regress/columnar_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test: columnar_types_without_comparison
test: columnar_join
test: columnar_trigger
test: columnar_tableoptions
test: columnar_tablespace
test: columnar_recursive
test: columnar_transactions
test: columnar_matview
Expand Down
33 changes: 33 additions & 0 deletions columnar/src/test/regress/expected/columnar_tablespace.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--
-- Test the columnar table move between tablespace.
--
-- An empty location can be allowed as a way to say that the tablespace
-- should be created as a directory in pg_tblspc, rather than being a
-- symlink.
SET allow_in_place_tablespaces = true;
CREATE TABLE regress_tbl (id int, info text) USING columnar;
INSERT INTO regress_tbl
SELECT id, md5(id::text) FROM generate_series(1, 10000) id;
CREATE TABLESPACE regress_tblspc LOCATION '';
-- no relation moved to the new tablespace
SELECT c.relname FROM pg_class c, pg_tablespace s
WHERE c.reltablespace = s.oid AND s.spcname = 'regress_tblspc';
relname
---------
(0 rows)

ALTER TABLE regress_tbl SET TABLESPACE regress_tblspc;
-- a columnar table moved to the new tablespace
SELECT c.relname FROM pg_class c, pg_tablespace s
WHERE c.reltablespace = s.oid AND s.spcname = 'regress_tblspc';
relname
-------------
regress_tbl
(1 row)

SELECT count(*) FROM regress_tbl;
count
-------
10000
(1 row)

26 changes: 26 additions & 0 deletions columnar/src/test/regress/sql/columnar_tablespace.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--
-- Test the columnar table move between tablespace.
--

-- An empty location can be allowed as a way to say that the tablespace
-- should be created as a directory in pg_tblspc, rather than being a
-- symlink.
SET allow_in_place_tablespaces = true;

CREATE TABLE regress_tbl (id int, info text) USING columnar;
INSERT INTO regress_tbl
SELECT id, md5(id::text) FROM generate_series(1, 10000) id;

CREATE TABLESPACE regress_tblspc LOCATION '';

-- no relation moved to the new tablespace
SELECT c.relname FROM pg_class c, pg_tablespace s
WHERE c.reltablespace = s.oid AND s.spcname = 'regress_tblspc';

ALTER TABLE regress_tbl SET TABLESPACE regress_tblspc;

-- a columnar table moved to the new tablespace
SELECT c.relname FROM pg_class c, pg_tablespace s
WHERE c.reltablespace = s.oid AND s.spcname = 'regress_tblspc';

SELECT count(*) FROM regress_tbl;