Skip to content

Commit

Permalink
[#23064] YSQL: pg_partman: disable p_retention_schema parameter
Browse files Browse the repository at this point in the history
Summary:
In drop_partition_id and drop_partition_time pg_partman functions which is used
to drop child tables from a id-based or time-based partition set, there is parameter `p_retention_schema` which if set
moves a child table to another schema instead of dropping it.

If set, then these two functions executes an `ALTER TABLE SET SCHEMA` to move the child partition to new schema.

Currently `ALTER TABLE SET SCHEMA ` is not supported in YB therefore returning error if set.

```
yugabyte=# create table tab(a int);
CREATE TABLE
yugabyte=# create schema new_schema;
CREATE SCHEMA
yugabyte=# alter table tab set schema new_schema;;
ERROR:  ALTER TABLE SET SCHEMA not supported yet
LINE 1: alter table tab set schema new_schema;
        ^
HINT:  Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
```

If the drop_partition_time and drop_partition_id are not early exited when `p_retention_schema` is not NULL that could cause detaching of child partitions.

There is this logic in both functions that detaches child tables if `p_retention_schema` is not NULL.

```
IF v_retention_keep_table = true OR v_retention_schema IS NOT NULL THEN
           -- No need to detach partition before dropping since it's going away anyway
           -- Avoids issue of FKs not allowing detachment (Github Issue #294).
           IF v_partition_type = 'native' THEN
               v_sql := format('ALTER TABLE %I.%I DETACH PARTITION %I.%I'
                   , v_parent_schema
                   , v_parent_tablename
                   , v_row.partition_schemaname
                   , v_row.partition_tablename);
               EXECUTE v_sql;
           ELSE
               EXECUTE format('ALTER TABLE %I.%I NO INHERIT %I.%I'
                       , v_row.partition_schemaname
                       , v_row.partition_tablename
                       , v_parent_schema
                       , v_parent_tablename);
```
So if retention_schema is not null in parameters, child partition would be detached , there is later this call to move it to new schema

```
ELSE -- Move to new schema
           IF v_jobmon_schema IS NOT NULL THEN
               v_step_id := add_step(v_job_id, format('Moving table %s.%s to schema %s'
                                               , v_row.partition_schemaname
                                               , v_row.partition_tablename
                                               , v_retention_schema));
           END IF;
           EXECUTE format('ALTER TABLE %I.%I SET SCHEMA %I', v_row.partition_schemaname, v_row.partition_tablename, v_retention_schema);
```
So, if we allow procedure to fail here instead of early exiting, the child table would be actually detached even if the stored procedure errors out.
Given YugabyteDB don't have transactional DDL support yet, the detach call we not be rolled back.
Jira: DB-12001

Test Plan: jenkins: compile only

Reviewers: skumar, hsunder, jason

Reviewed By: jason

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D36427
  • Loading branch information
Devansh Saxena committed Jul 16, 2024
1 parent 3273e9b commit 52f7e79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ IF p_keep_index IS NOT NULL THEN
v_retention_keep_index = p_keep_index;
END IF;
IF p_retention_schema IS NOT NULL THEN
/* YB: Early exiting if p_retention_schema is not NULL.
Transactional DDL is not supported yet, hence the detach
call we not be rolled back.
*/
RAISE EXCEPTION 'Setting retention schema is not supported';
v_retention_schema = p_retention_schema;
END IF;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ IF p_keep_index IS NOT NULL THEN
v_retention_keep_index = p_keep_index;
END IF;
IF p_retention_schema IS NOT NULL THEN
/* YB: Early exiting if p_retention_schema is not NULL.
Transactional DDL is not supported yet, hence the detach
call we not be rolled back.
*/
RAISE EXCEPTION 'Setting retention schema is not supported';
v_retention_schema = p_retention_schema;
END IF;

Expand Down

0 comments on commit 52f7e79

Please sign in to comment.