mirror of
https://github.com/postgres/postgres.git
synced 2025-06-03 00:02:26 -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
|
t
|
||||||
(1 row)
|
(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;
|
ALTER TABLE country_table ADD y text;
|
||||||
SELECT pg_tde_is_encrypted('pg_toast.pg_toast_' || 'country_table'::regclass::oid);
|
SELECT pg_tde_is_encrypted('pg_toast.pg_toast_' || 'country_table'::regclass::oid);
|
||||||
pg_tde_is_encrypted
|
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_country_id_seq');
|
||||||
SELECT pg_tde_is_encrypted('country_table_pkey');
|
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;
|
ALTER TABLE country_table ADD y text;
|
||||||
|
|
||||||
SELECT pg_tde_is_encrypted('pg_toast.pg_toast_' || 'country_table'::regclass::oid);
|
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*/
|
/* Global variable that gets set at ddl start and cleard out at ddl end*/
|
||||||
static TdeCreateEvent tdeCurrentCreateEvent = {.tid = {.value = 0}};
|
static TdeCreateEvent tdeCurrentCreateEvent = {.tid = {.value = 0}};
|
||||||
static bool alterSetAccessMethod = false;
|
|
||||||
|
|
||||||
static void reset_current_tde_create_event(void);
|
static void reset_current_tde_create_event(void);
|
||||||
static Oid get_tde_table_am_oid(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);
|
AlterTableStmt *stmt = castNode(AlterTableStmt, parsetree);
|
||||||
ListCell *lcmd;
|
ListCell *lcmd;
|
||||||
Oid relationId = RangeVarGetRelid(stmt->relation, AccessShareLock, true);
|
Oid relationId = RangeVarGetRelid(stmt->relation, AccessShareLock, true);
|
||||||
|
AlterTableCmd *setAccessMethod = NULL;
|
||||||
|
|
||||||
validateCurrentEventTriggerState(true);
|
validateCurrentEventTriggerState(true);
|
||||||
tdeCurrentCreateEvent.tid = GetCurrentFullTransactionId();
|
tdeCurrentCreateEvent.tid = GetCurrentFullTransactionId();
|
||||||
@ -185,29 +185,27 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
|
|||||||
AlterTableCmd *cmd = castNode(AlterTableCmd, lfirst(lcmd));
|
AlterTableCmd *cmd = castNode(AlterTableCmd, lfirst(lcmd));
|
||||||
|
|
||||||
if (cmd->subtype == AT_SetAccessMethod)
|
if (cmd->subtype == AT_SetAccessMethod)
|
||||||
{
|
setAccessMethod = cmd;
|
||||||
tdeCurrentCreateEvent.baseTableOid = relationId;
|
|
||||||
tdeCurrentCreateEvent.alterAccessMethodMode = true;
|
|
||||||
|
|
||||||
if (shouldEncryptTable(cmd->name))
|
|
||||||
tdeCurrentCreateEvent.encryptMode = true;
|
|
||||||
|
|
||||||
checkEncryptionStatus();
|
|
||||||
|
|
||||||
alterSetAccessMethod = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
/*
|
if (shouldEncryptTable(setAccessMethod->name))
|
||||||
* With a SET ACCESS METHOD clause, use that as the basis for
|
tdeCurrentCreateEvent.encryptMode = true;
|
||||||
* decisions. But if it's not present, look up encryption status
|
|
||||||
* of the table.
|
|
||||||
*/
|
|
||||||
|
|
||||||
tdeCurrentCreateEvent.baseTableOid = relationId;
|
checkEncryptionStatus();
|
||||||
|
|
||||||
|
tdeCurrentCreateEvent.alterAccessMethodMode = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (relationId != InvalidOid)
|
if (relationId != InvalidOid)
|
||||||
{
|
{
|
||||||
Relation rel = relation_open(relationId, NoLock);
|
Relation rel = relation_open(relationId, NoLock);
|
||||||
@ -307,7 +305,6 @@ reset_current_tde_create_event(void)
|
|||||||
tdeCurrentCreateEvent.baseTableOid = InvalidOid;
|
tdeCurrentCreateEvent.baseTableOid = InvalidOid;
|
||||||
tdeCurrentCreateEvent.tid = InvalidFullTransactionId;
|
tdeCurrentCreateEvent.tid = InvalidFullTransactionId;
|
||||||
tdeCurrentCreateEvent.alterAccessMethodMode = false;
|
tdeCurrentCreateEvent.alterAccessMethodMode = false;
|
||||||
alterSetAccessMethod = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Oid
|
static Oid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user