Skip to content

Commit

Permalink
Fix valgrind warning in bbf_drop_handle_partitioned_table function (#…
Browse files Browse the repository at this point in the history
…2817)

For table variables, we internally execute a DROP TABLE command after running a batch statement. There was a
possibility that the temp schema might get dropped before executing the DROP TABLE command, leading to a warning
during the get_namespace_name lookup. This commit restricts the handling inside the
bbf_drop_handle_partitioned_table function to only permanent tables and partition/partitioned tables.

Task: BABEL-5121
Signed-off-by: Sumit Jaiswal <[email protected]>
  • Loading branch information
sumitj824 authored Aug 1, 2024
1 parent 239d212 commit 118ae82
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
23 changes: 18 additions & 5 deletions contrib/babelfishpg_tsql/src/pltsql_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bbf_create_partition_tables(CreateStmt *stmt)
if (stmt->relation->relpersistence == RELPERSISTENCE_TEMP)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("Creation of tempopary partitioned tables is not supported in Babelfish.")));
errmsg("Creation of temporary partitioned tables is not supported in Babelfish.")));

/*
* Get partition function name for the provided partition scheme,
Expand Down Expand Up @@ -465,18 +465,30 @@ bbf_drop_handle_partitioned_table(DropStmt *stmt)
form = RelationGetForm(relation);
relname = RelationGetRelationName(relation);

/* Find dbid and logical schema name of table. */
/* Proceed further only for permanent and partition/partitioned table. */
if (!(form->relkind == RELKIND_PARTITIONED_TABLE || form->relispartition)
|| form->relpersistence != RELPERSISTENCE_PERMANENT)
{
relation_close(relation, AccessShareLock);
continue;
}

physical_schemaname = get_namespace_name(form->relnamespace);
logical_schemaname = (char *) get_logical_schema_name(physical_schemaname, true);
dbid = get_dbid_from_physical_schema_name(physical_schemaname, true);
pfree(physical_schemaname);

/* Find logical schema name from physical schema name. */
logical_schemaname = (char *) get_logical_schema_name(physical_schemaname, true);

if (!logical_schemaname) /* not a TSQL schema */
{
pfree(physical_schemaname);
relation_close(relation, AccessShareLock);
continue;
}

/* Find dbid from physical schema name for a TSQL schema. */
dbid = get_dbid_from_physical_schema_name(physical_schemaname, false);
pfree(physical_schemaname);

if (form->relispartition) /* relation is partition of table */
{
/* Prevent non-superusers from droping partitions of Babelfish partitioned tables. */
Expand All @@ -495,6 +507,7 @@ bbf_drop_handle_partitioned_table(DropStmt *stmt)
remove_entry_from_bbf_partition_depend(dbid, logical_schemaname, relname);
}
relation_close(relation, AccessShareLock);
pfree(logical_schemaname);
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/expected/PARTITION-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -2742,7 +2742,7 @@ ON IntPartitionScheme(id);
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Creation of tempopary partitioned tables is not supported in Babelfish.)~~
~~ERROR (Message: Creation of temporary partitioned tables is not supported in Babelfish.)~~



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2742,7 +2742,7 @@ ON IntPartitionScheme(id);
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Creation of tempopary partitioned tables is not supported in Babelfish.)~~
~~ERROR (Message: Creation of temporary partitioned tables is not supported in Babelfish.)~~



Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/expected/parallel_query/PARTITION-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,7 @@ ON IntPartitionScheme(id);
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: Creation of tempopary partitioned tables is not supported in Babelfish.)~~
~~ERROR (Message: Creation of temporary partitioned tables is not supported in Babelfish.)~~



Expand Down

0 comments on commit 118ae82

Please sign in to comment.