Skip to content

Commit 8a0b95c

Browse files
author
Devansh Saxena
committed
[#23322] YSQL: pg_partman: fix logic of checking existing table
Summary: Diff D36428 added an incorrect assertion in create_partition_time to check if a child table is already created . ``` IF v_exists IS NULL THEN RAISE DEBUG 'create_partition_time v_sql: %', v_sql; EXECUTE v_sql; END IF; ``` `v_exists` is of type `smallint` and should be check if it is greater than zero or not. This diff fixes this bug. Jira: DB-12247 Test Plan: jenkins: compile only Manual Test: ``` yugabyte=# CREATE SCHEMA IF NOT EXISTS partman; CREATE SCHEMA yugabyte=# CREATE EXTENSION pg_partman WITH SCHEMA partman; CREATE EXTENSION yugabyte=# CREATE SCHEMA partman_test; CREATE SCHEMA yugabyte=# CREATE TABLE partman_test.time_taptest_table ( yugabyte(# col1 int, yugabyte(# col2 text, yugabyte(# col3 int NOT NULL DEFAULT extract('epoch' from CURRENT_TIMESTAMP)::int) yugabyte-# PARTITION BY RANGE (col3); CREATE TABLE yugabyte=# \d partman_test.time_taptest_table Table "partman_test.time_taptest_table" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+-------------------------------------------------------- col1 | integer | | | col2 | text | | | col3 | integer | | not null | (date_part('epoch'::text, CURRENT_TIMESTAMP))::integer Partition key: RANGE (col3) Number of partitions: 0 yugabyte=# SELECT partman.create_parent('partman_test.time_taptest_table', 'col3', 'native', 'weekly', '{"col1"}', p_epoch := 'seconds' yugabyte(# , p_premake := 2, p_start_partition := to_char(CURRENT_TIMESTAMP-'8 weeks'::interval, 'YYYY-MM-DD HH24:MI:SS')); create_parent --------------- t (1 row) yugabyte=# \d+ partman_test.time_taptest_table Table "partman_test.time_taptest_table" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+--------------------------------------------------------+----------+--------------+------------- col1 | integer | | | | plain | | col2 | text | | | | extended | | col3 | integer | | not null | (date_part('epoch'::text, CURRENT_TIMESTAMP))::integer | plain | | Partition key: RANGE (col3) Partitions: partman_test.time_taptest_table_p2024w23 FOR VALUES FROM (1717353000) TO (1717957800), partman_test.time_taptest_table_p2024w24 FOR VALUES FROM (1717957800) TO (1718562600), partman_test.time_taptest_table_p2024w25 FOR VALUES FROM (1718562600) TO (1719167400), partman_test.time_taptest_table_p2024w26 FOR VALUES FROM (1719167400) TO (1719772200), partman_test.time_taptest_table_p2024w27 FOR VALUES FROM (1719772200) TO (1720377000), partman_test.time_taptest_table_p2024w28 FOR VALUES FROM (1720377000) TO (1720981800), partman_test.time_taptest_table_p2024w29 FOR VALUES FROM (1720981800) TO (1721586600), partman_test.time_taptest_table_p2024w30 FOR VALUES FROM (1721586600) TO (1722191400), partman_test.time_taptest_table_p2024w31 FOR VALUES FROM (1722191400) TO (1722796200), partman_test.time_taptest_table_p2024w32 FOR VALUES FROM (1722796200) TO (1723401000), partman_test.time_taptest_table_p2024w33 FOR VALUES FROM (1723401000) TO (1724005800), partman_test.time_taptest_table_default DEFAULT ``` Reviewers: jason, hsunder Reviewed By: hsunder Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D36916
1 parent 79902ae commit 8a0b95c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/postgres/third-party-extensions/pg_partman/sql/functions/create_partition_time.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
259259
END IF;
260260
END IF;
261261

262-
IF v_exists IS NULL THEN
262+
IF v_exists = 0 THEN
263263
RAISE DEBUG 'create_partition_time v_sql: %', v_sql;
264264
EXECUTE v_sql;
265265
END IF;

0 commit comments

Comments
 (0)