Skip to content

Commit

Permalink
Add proper check for toast tables
Browse files Browse the repository at this point in the history
  • Loading branch information
timchang514 committed Nov 7, 2023
1 parent b47cdb0 commit 84c4cea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/backend/catalog/toasting.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,13 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
* Create the toast table and its index
*/
if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTableVariable(rel))
{
pg_toast_prefix = "@pg_toast";

if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTempTable(rel))
}
else if (sql_dialect == SQL_DIALECT_TSQL && RelationIsBBFTempTable(rel) && get_ENR_withoid(currentQueryEnv, rel->rd_id, ENR_TSQL_TEMP))
{
pg_toast_prefix = "#pg_toast";
}

snprintf(toast_relname, sizeof(toast_relname),
"%s_%u", pg_toast_prefix, relOid);
Expand Down
6 changes: 0 additions & 6 deletions src/backend/utils/misc/queryenvironment.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,21 +878,15 @@ static bool _ENR_tuple_operation(Relation catalog_rel, HeapTuple tup, ENRTupleOp
CacheInvalidateHeapTuple(catalog_rel, newtup, NULL);
break;
case ENR_OP_UPDATE:
if (lc)
{
oldtup = lfirst(lc);
lfirst(lc) = heap_copytuple(tup);
CacheInvalidateHeapTuple(catalog_rel, oldtup, tup);
}
break;
case ENR_OP_DROP:
if (lc)
{
tmp = lfirst(lc);
*list_ptr = list_delete_ptr(*list_ptr, tmp);
CacheInvalidateHeapTuple(catalog_rel, tup, NULL);
heap_freetuple(tmp);
}
break;
default:
break;
Expand Down
1 change: 1 addition & 0 deletions src/include/utils/rel.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ extern void RelationDecrementReferenceCount(Relation rel);
strlen((relation)->rd_rel->relname.data) >= 1 && \
(relation)->rd_rel->relname.data[0] == '@')

/* PG Tables can begin with '#' as well, so check sql_dialect additionally */
#define RelationIsBBFTempTable(relation) \
((relation)->rd_rel->relpersistence == RELPERSISTENCE_TEMP && \
(relation)->rd_rel->relname.data && \
Expand Down

0 comments on commit 84c4cea

Please sign in to comment.