Skip to content

Commit

Permalink
Fix IF eval precedence in ALTER trigger (#322)
Browse files Browse the repository at this point in the history
... and add tests for ALTER INDEX
  • Loading branch information
dAdAbird authored Oct 31, 2024
1 parent 59960a3 commit c5f2fbb
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ trigger_on_view_basic \
change_access_method_basic \
insert_update_delete_basic \
keyprovider_dependency_basic \
vault_v2_test_basic
vault_v2_test_basic \
alter_index_basic
TAP_TESTS = 1

OBJS = src/encryption/enc_tde.o \
Expand Down
73 changes: 73 additions & 0 deletions expected/alter_index.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
\set tde_am tde_heap
\i sql/alter_index.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)

SET default_table_access_method = :"tde_am";
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
CREATE TABLE concur_reindex_part_0 PARTITION OF concur_reindex_part
FOR VALUES FROM (0) TO (10) PARTITION BY list (c2);
CREATE TABLE concur_reindex_part_0_1 PARTITION OF concur_reindex_part_0
FOR VALUES IN (1);
CREATE TABLE concur_reindex_part_0_2 PARTITION OF concur_reindex_part_0
FOR VALUES IN (2);
-- This partitioned table will have no partitions.
CREATE TABLE concur_reindex_part_10 PARTITION OF concur_reindex_part
FOR VALUES FROM (10) TO (20) PARTITION BY list (c2);
-- Create some partitioned indexes
CREATE INDEX concur_reindex_part_index ON ONLY concur_reindex_part (c1);
CREATE INDEX concur_reindex_part_index_0 ON ONLY concur_reindex_part_0 (c1);
ALTER INDEX concur_reindex_part_index ATTACH PARTITION concur_reindex_part_index_0;
-- This partitioned index will have no partitions.
CREATE INDEX concur_reindex_part_index_10 ON ONLY concur_reindex_part_10 (c1);
ALTER INDEX concur_reindex_part_index ATTACH PARTITION concur_reindex_part_index_10;
CREATE INDEX concur_reindex_part_index_0_1 ON ONLY concur_reindex_part_0_1 (c1);
ALTER INDEX concur_reindex_part_index_0 ATTACH PARTITION concur_reindex_part_index_0_1;
CREATE INDEX concur_reindex_part_index_0_2 ON ONLY concur_reindex_part_0_2 (c1);
ALTER INDEX concur_reindex_part_index_0 ATTACH PARTITION concur_reindex_part_index_0_2;
SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
relid | parentrelid | level
-------------------------------+-----------------------------+-------
concur_reindex_part_index | | 0
concur_reindex_part_index_0 | concur_reindex_part_index | 1
concur_reindex_part_index_10 | concur_reindex_part_index | 1
concur_reindex_part_index_0_1 | concur_reindex_part_index_0 | 2
concur_reindex_part_index_0_2 | concur_reindex_part_index_0 | 2
(5 rows)

SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
relid | parentrelid | level
-------------------------------+-----------------------------+-------
concur_reindex_part_index | | 0
concur_reindex_part_index_0 | concur_reindex_part_index | 1
concur_reindex_part_index_10 | concur_reindex_part_index | 1
concur_reindex_part_index_0_1 | concur_reindex_part_index_0 | 2
concur_reindex_part_index_0_2 | concur_reindex_part_index_0 | 2
(5 rows)

SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
relid | parentrelid | level
-------------------------------+-----------------------------+-------
concur_reindex_part_index | | 0
concur_reindex_part_index_0 | concur_reindex_part_index | 1
concur_reindex_part_index_10 | concur_reindex_part_index | 1
concur_reindex_part_index_0_1 | concur_reindex_part_index_0 | 2
concur_reindex_part_index_0_2 | concur_reindex_part_index_0 | 2
(5 rows)

DROP TABLE concur_reindex_part;
DROP EXTENSION pg_tde;
RESET default_table_access_method;
73 changes: 73 additions & 0 deletions expected/alter_index_basic.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
\set tde_am tde_heap_basic
\i sql/alter_index.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)

SET default_table_access_method = :"tde_am";
CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
CREATE TABLE concur_reindex_part_0 PARTITION OF concur_reindex_part
FOR VALUES FROM (0) TO (10) PARTITION BY list (c2);
CREATE TABLE concur_reindex_part_0_1 PARTITION OF concur_reindex_part_0
FOR VALUES IN (1);
CREATE TABLE concur_reindex_part_0_2 PARTITION OF concur_reindex_part_0
FOR VALUES IN (2);
-- This partitioned table will have no partitions.
CREATE TABLE concur_reindex_part_10 PARTITION OF concur_reindex_part
FOR VALUES FROM (10) TO (20) PARTITION BY list (c2);
-- Create some partitioned indexes
CREATE INDEX concur_reindex_part_index ON ONLY concur_reindex_part (c1);
CREATE INDEX concur_reindex_part_index_0 ON ONLY concur_reindex_part_0 (c1);
ALTER INDEX concur_reindex_part_index ATTACH PARTITION concur_reindex_part_index_0;
-- This partitioned index will have no partitions.
CREATE INDEX concur_reindex_part_index_10 ON ONLY concur_reindex_part_10 (c1);
ALTER INDEX concur_reindex_part_index ATTACH PARTITION concur_reindex_part_index_10;
CREATE INDEX concur_reindex_part_index_0_1 ON ONLY concur_reindex_part_0_1 (c1);
ALTER INDEX concur_reindex_part_index_0 ATTACH PARTITION concur_reindex_part_index_0_1;
CREATE INDEX concur_reindex_part_index_0_2 ON ONLY concur_reindex_part_0_2 (c1);
ALTER INDEX concur_reindex_part_index_0 ATTACH PARTITION concur_reindex_part_index_0_2;
SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
relid | parentrelid | level
-------------------------------+-----------------------------+-------
concur_reindex_part_index | | 0
concur_reindex_part_index_0 | concur_reindex_part_index | 1
concur_reindex_part_index_10 | concur_reindex_part_index | 1
concur_reindex_part_index_0_1 | concur_reindex_part_index_0 | 2
concur_reindex_part_index_0_2 | concur_reindex_part_index_0 | 2
(5 rows)

SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
relid | parentrelid | level
-------------------------------+-----------------------------+-------
concur_reindex_part_index | | 0
concur_reindex_part_index_0 | concur_reindex_part_index | 1
concur_reindex_part_index_10 | concur_reindex_part_index | 1
concur_reindex_part_index_0_1 | concur_reindex_part_index_0 | 2
concur_reindex_part_index_0_2 | concur_reindex_part_index_0 | 2
(5 rows)

SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
relid | parentrelid | level
-------------------------------+-----------------------------+-------
concur_reindex_part_index | | 0
concur_reindex_part_index_0 | concur_reindex_part_index | 1
concur_reindex_part_index_10 | concur_reindex_part_index | 1
concur_reindex_part_index_0_1 | concur_reindex_part_index_0 | 2
concur_reindex_part_index_0_2 | concur_reindex_part_index_0 | 2
(5 rows)

DROP TABLE concur_reindex_part;
DROP EXTENSION pg_tde;
RESET default_table_access_method;
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ sql_tests = [
'change_access_method_basic',
'insert_update_delete_basic',
'vault_v2_test_basic',
'alter_index_basic',
]

tap_tests = [
Expand Down Expand Up @@ -125,6 +126,7 @@ if get_variable('percona_ext', false)
'change_access_method',
'insert_update_delete',
'vault_v2_test',
'alter_index',
]

tap_tests += [
Expand Down
37 changes: 37 additions & 0 deletions sql/alter_index.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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');

SET default_table_access_method = :"tde_am";

CREATE TABLE concur_reindex_part (c1 int, c2 int) PARTITION BY RANGE (c1);
CREATE TABLE concur_reindex_part_0 PARTITION OF concur_reindex_part
FOR VALUES FROM (0) TO (10) PARTITION BY list (c2);
CREATE TABLE concur_reindex_part_0_1 PARTITION OF concur_reindex_part_0
FOR VALUES IN (1);
CREATE TABLE concur_reindex_part_0_2 PARTITION OF concur_reindex_part_0
FOR VALUES IN (2);
-- This partitioned table will have no partitions.
CREATE TABLE concur_reindex_part_10 PARTITION OF concur_reindex_part
FOR VALUES FROM (10) TO (20) PARTITION BY list (c2);
-- Create some partitioned indexes
CREATE INDEX concur_reindex_part_index ON ONLY concur_reindex_part (c1);
CREATE INDEX concur_reindex_part_index_0 ON ONLY concur_reindex_part_0 (c1);
ALTER INDEX concur_reindex_part_index ATTACH PARTITION concur_reindex_part_index_0;
-- This partitioned index will have no partitions.
CREATE INDEX concur_reindex_part_index_10 ON ONLY concur_reindex_part_10 (c1);
ALTER INDEX concur_reindex_part_index ATTACH PARTITION concur_reindex_part_index_10;
CREATE INDEX concur_reindex_part_index_0_1 ON ONLY concur_reindex_part_0_1 (c1);
ALTER INDEX concur_reindex_part_index_0 ATTACH PARTITION concur_reindex_part_index_0_1;
CREATE INDEX concur_reindex_part_index_0_2 ON ONLY concur_reindex_part_0_2 (c1);
ALTER INDEX concur_reindex_part_index_0 ATTACH PARTITION concur_reindex_part_index_0_2;
SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
SELECT relid, parentrelid, level FROM pg_partition_tree('concur_reindex_part_index')
ORDER BY relid, level;
DROP TABLE concur_reindex_part;
DROP EXTENSION pg_tde;
RESET default_table_access_method;
2 changes: 2 additions & 0 deletions sql/alter_index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\set tde_am tde_heap
\i sql/alter_index.inc
2 changes: 2 additions & 0 deletions sql/alter_index_basic.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\set tde_am tde_heap_basic
\i sql/alter_index.inc
4 changes: 2 additions & 2 deletions src/pg_tde_event_capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
{
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
if (cmd->subtype == AT_SetAccessMethod &&
(cmd->name != NULL && strcmp(cmd->name, "tde_heap")==0) ||
(cmd->name == NULL && strcmp(default_table_access_method, "tde_heap") == 0)
((cmd->name != NULL && strcmp(cmd->name, "tde_heap")==0) ||
(cmd->name == NULL && strcmp(default_table_access_method, "tde_heap") == 0))
)
{
tdeCurrentCreateEvent.encryptMode = true;
Expand Down

0 comments on commit c5f2fbb

Please sign in to comment.