mirror of
https://github.com/postgres/postgres.git
synced 2025-05-31 00:01:57 -04:00
Make ALTER TABLE ... SET ACCESS METHOD logic easier to read
Also add a couple of tests for the DEFAULT case to avoid regressions.
This commit is contained in:
parent
ae04e97e4b
commit
dffece72a5
@ -121,6 +121,24 @@ SELECT pg_tde_is_encrypted('country_table_pkey');
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- Test that we honor the default value
|
||||
SET default_table_access_method = 'heap';
|
||||
ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
|
||||
SELECT pg_tde_is_encrypted('country_table');
|
||||
pg_tde_is_encrypted
|
||||
---------------------
|
||||
f
|
||||
(1 row)
|
||||
|
||||
SET default_table_access_method = 'tde_heap';
|
||||
ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
|
||||
SELECT pg_tde_is_encrypted('country_table');
|
||||
pg_tde_is_encrypted
|
||||
---------------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
RESET default_table_access_method;
|
||||
ALTER TABLE country_table ADD y text;
|
||||
SELECT pg_tde_is_encrypted('pg_toast.pg_toast_' || 'country_table'::regclass::oid);
|
||||
pg_tde_is_encrypted
|
||||
|
@ -46,6 +46,21 @@ SELECT pg_tde_is_encrypted('country_table');
|
||||
SELECT pg_tde_is_encrypted('country_table_country_id_seq');
|
||||
SELECT pg_tde_is_encrypted('country_table_pkey');
|
||||
|
||||
-- Test that we honor the default value
|
||||
SET default_table_access_method = 'heap';
|
||||
|
||||
ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
|
||||
|
||||
SELECT pg_tde_is_encrypted('country_table');
|
||||
|
||||
SET default_table_access_method = 'tde_heap';
|
||||
|
||||
ALTER TABLE country_table SET ACCESS METHOD DEFAULT;
|
||||
|
||||
SELECT pg_tde_is_encrypted('country_table');
|
||||
|
||||
RESET default_table_access_method;
|
||||
|
||||
ALTER TABLE country_table ADD y text;
|
||||
|
||||
SELECT pg_tde_is_encrypted('pg_toast.pg_toast_' || 'country_table'::regclass::oid);
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
/* Global variable that gets set at ddl start and cleard out at ddl end*/
|
||||
static TdeCreateEvent tdeCurrentCreateEvent = {.tid = {.value = 0}};
|
||||
static bool alterSetAccessMethod = false;
|
||||
|
||||
static void reset_current_tde_create_event(void);
|
||||
static Oid get_tde_table_am_oid(void);
|
||||
@ -176,6 +175,7 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
|
||||
AlterTableStmt *stmt = castNode(AlterTableStmt, parsetree);
|
||||
ListCell *lcmd;
|
||||
Oid relationId = RangeVarGetRelid(stmt->relation, AccessShareLock, true);
|
||||
AlterTableCmd *setAccessMethod = NULL;
|
||||
|
||||
validateCurrentEventTriggerState(true);
|
||||
tdeCurrentCreateEvent.tid = GetCurrentFullTransactionId();
|
||||
@ -185,29 +185,27 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
|
||||
AlterTableCmd *cmd = castNode(AlterTableCmd, lfirst(lcmd));
|
||||
|
||||
if (cmd->subtype == AT_SetAccessMethod)
|
||||
{
|
||||
tdeCurrentCreateEvent.baseTableOid = relationId;
|
||||
tdeCurrentCreateEvent.alterAccessMethodMode = true;
|
||||
|
||||
if (shouldEncryptTable(cmd->name))
|
||||
tdeCurrentCreateEvent.encryptMode = true;
|
||||
|
||||
checkEncryptionStatus();
|
||||
|
||||
alterSetAccessMethod = true;
|
||||
}
|
||||
setAccessMethod = cmd;
|
||||
}
|
||||
|
||||
if (!alterSetAccessMethod)
|
||||
tdeCurrentCreateEvent.baseTableOid = relationId;
|
||||
|
||||
/*
|
||||
* With a SET ACCESS METHOD clause, use that as the basis for
|
||||
* decisions. But if it's not present, look up encryption status of
|
||||
* the table.
|
||||
*/
|
||||
if (setAccessMethod)
|
||||
{
|
||||
/*
|
||||
* With a SET ACCESS METHOD clause, use that as the basis for
|
||||
* decisions. But if it's not present, look up encryption status
|
||||
* of the table.
|
||||
*/
|
||||
if (shouldEncryptTable(setAccessMethod->name))
|
||||
tdeCurrentCreateEvent.encryptMode = true;
|
||||
|
||||
tdeCurrentCreateEvent.baseTableOid = relationId;
|
||||
checkEncryptionStatus();
|
||||
|
||||
tdeCurrentCreateEvent.alterAccessMethodMode = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (relationId != InvalidOid)
|
||||
{
|
||||
Relation rel = relation_open(relationId, NoLock);
|
||||
@ -307,7 +305,6 @@ reset_current_tde_create_event(void)
|
||||
tdeCurrentCreateEvent.baseTableOid = InvalidOid;
|
||||
tdeCurrentCreateEvent.tid = InvalidFullTransactionId;
|
||||
tdeCurrentCreateEvent.alterAccessMethodMode = false;
|
||||
alterSetAccessMethod = false;
|
||||
}
|
||||
|
||||
static Oid
|
||||
|
Loading…
x
Reference in New Issue
Block a user