Skip to content

Commit

Permalink
Merge pull request #288 from percona/PG-1038-tablespaces
Browse files Browse the repository at this point in the history
Fix ALTER ... TABLESPACE (PG-1038)
  • Loading branch information
dAdAbird authored Nov 1, 2024
2 parents e9f028e + 5d8436a commit 9501818
Show file tree
Hide file tree
Showing 19 changed files with 325 additions and 55 deletions.
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ insert_update_delete_basic \
keyprovider_dependency_basic \
vault_v2_test_basic \
alter_index_basic \
merge_join_basic
merge_join_basic \
tablespace_basic
TAP_TESTS = 1

OBJS = src/encryption/enc_tde.o \
Expand Down
41 changes: 41 additions & 0 deletions expected/tablespace.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
\set tde_am tde_heap
\i sql/tablespace.inc
CREATE EXTENSION pg_tde;
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
pg_tde_add_key_provider_file
------------------------------
1
(1 row)

SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
pg_tde_set_principal_key
--------------------------
t
(1 row)

CREATE TABLE test(num1 bigint, num2 double precision, t text) USING :tde_am;
INSERT INTO test(num1, num2, t)
SELECT round(random()*100), random(), 'text'
FROM generate_series(1, 10) s(i);
CREATE INDEX test_idx ON test(num1);
SET allow_in_place_tablespaces = true;
CREATE TABLESPACE test_tblspace LOCATION '';
ALTER TABLE test SET TABLESPACE test_tblspace;
SELECT count(*) FROM test;
count
-------
10
(1 row)

ALTER TABLE test SET TABLESPACE pg_default;
REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test;
INSERT INTO test VALUES (110, 2);
SELECT * FROM test WHERE num1=110;
num1 | num2 | t
------+------+---
110 | 2 |
(1 row)

DROP TABLE test;
DROP TABLESPACE test_tblspace;
DROP EXTENSION pg_tde;
41 changes: 41 additions & 0 deletions expected/tablespace_basic.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
\set tde_am tde_heap_basic
\i sql/tablespace.inc
CREATE EXTENSION pg_tde;
SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
pg_tde_add_key_provider_file
------------------------------
1
(1 row)

SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');
pg_tde_set_principal_key
--------------------------
t
(1 row)

CREATE TABLE test(num1 bigint, num2 double precision, t text) USING :tde_am;
INSERT INTO test(num1, num2, t)
SELECT round(random()*100), random(), 'text'
FROM generate_series(1, 10) s(i);
CREATE INDEX test_idx ON test(num1);
SET allow_in_place_tablespaces = true;
CREATE TABLESPACE test_tblspace LOCATION '';
ALTER TABLE test SET TABLESPACE test_tblspace;
SELECT count(*) FROM test;
count
-------
10
(1 row)

ALTER TABLE test SET TABLESPACE pg_default;
REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test;
INSERT INTO test VALUES (110, 2);
SELECT * FROM test WHERE num1=110;
num1 | num2 | t
------+------+---
110 | 2 |
(1 row)

DROP TABLE test;
DROP TABLESPACE test_tblspace;
DROP EXTENSION pg_tde;
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ sql_tests = [
'trigger_on_view_basic',
'change_access_method_basic',
'insert_update_delete_basic',
'tablespace_basic',
'vault_v2_test_basic',
'alter_index_basic',
'merge_join_basic',
Expand Down Expand Up @@ -126,6 +127,7 @@ if get_variable('percona_ext', false)
'trigger_on_view',
'change_access_method',
'insert_update_delete',
'tablespace',
'vault_v2_test',
'alter_index',
'merge_join',
Expand Down
26 changes: 26 additions & 0 deletions sql/tablespace.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE EXTENSION pg_tde;

SELECT pg_tde_add_key_provider_file('file-vault','/tmp/pg_tde_test_keyring.per');
SELECT pg_tde_set_principal_key('test-db-principal-key','file-vault');

CREATE TABLE test(num1 bigint, num2 double precision, t text) USING :tde_am;
INSERT INTO test(num1, num2, t)
SELECT round(random()*100), random(), 'text'
FROM generate_series(1, 10) s(i);
CREATE INDEX test_idx ON test(num1);

SET allow_in_place_tablespaces = true;
CREATE TABLESPACE test_tblspace LOCATION '';

ALTER TABLE test SET TABLESPACE test_tblspace;
SELECT count(*) FROM test;
ALTER TABLE test SET TABLESPACE pg_default;

REINDEX (TABLESPACE test_tblspace, CONCURRENTLY) TABLE test;
INSERT INTO test VALUES (110, 2);

SELECT * FROM test WHERE num1=110;

DROP TABLE test;
DROP TABLESPACE test_tblspace;
DROP EXTENSION pg_tde;
2 changes: 2 additions & 0 deletions sql/tablespace.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\set tde_am tde_heap
\i sql/tablespace.inc
2 changes: 2 additions & 0 deletions sql/tablespace_basic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\set tde_am tde_heap_basic
\i sql/tablespace.inc
3 changes: 3 additions & 0 deletions src/access/pg_tde_slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ PGTdeExecStoreBufferHeapTuple(Relation rel,
if (rel->rd_rel->relkind != RELKIND_TOASTVALUE)
{
RelKeyData *key = get_current_slot_relation_key(bslot, rel);

Assert(key != NULL);

slot_copytuple(bslot->decrypted_buffer, tuple);
PG_TDE_DECRYPT_TUPLE_EX(tuple, (HeapTuple)bslot->decrypted_buffer, key, "ExecStoreBuffer");
tuple->t_data = ((HeapTuple)bslot->decrypted_buffer)->t_data;
Expand Down
Loading

0 comments on commit 9501818

Please sign in to comment.