Skip to content

Commit

Permalink
Clean up temp table naming, introduce new functions for readability (#…
Browse files Browse the repository at this point in the history
…2975)


Signed-off-by: Tim Chang <[email protected]>
  • Loading branch information
timchang514 authored Nov 7, 2024
1 parent 0f3efb9 commit a457f9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/runtime/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ object_name(PG_FUNCTION_ARGS)
* search in list of ENRs registered in the current query environment by
* object_id
*/
enr = get_ENR_withoid(currentQueryEnv, object_id, ENR_TSQL_TEMP);
enr = GetENRTempTableWithOid(object_id);
if (enr != NULL && enr->md.enrtype == ENR_TSQL_TEMP)
{
PG_RETURN_VARCHAR_P((VarChar *) cstring_to_text(enr->md.name));
Expand Down
3 changes: 1 addition & 2 deletions contrib/babelfishpg_tsql/src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ bool IsPltsqlToastClassHook(Form_pg_class pg_class_tup)
void pltsql_drop_relation_refcnt_hook(Relation relation)
{
int expected_refcnt = 0;
if (sql_dialect != SQL_DIALECT_TSQL ||
!RelationIsBBFTableVariable(relation))
if (!IsTsqlTableVariable(relation))
return;

expected_refcnt = relation->rd_isnailed ? 2 : 1;
Expand Down
30 changes: 17 additions & 13 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ extern char *babelfish_dump_restore_min_oid;
extern bool pltsql_quoted_identifier;
extern bool pltsql_ansi_nulls;

#define OID_TO_BUFFER_START(oid) ((oid) + INT_MIN)
#define BUFFER_START_TO_OID ((Oid) (temp_oid_buffer_start) - INT_MIN)

/* For unit testing, to avoid concurrent heap update issues. */
bool TEST_persist_temp_oid_buffer_start_disable_catalog_update = false;

/*****************************************
* Catalog Hooks
*****************************************/
Expand Down Expand Up @@ -162,12 +156,6 @@ static void preserve_view_constraints_from_base_table(ColumnDef *col, Oid tableO
static bool pltsql_detect_numeric_overflow(int weight, int dscale, int first_block, int numeric_base);
static void insert_pltsql_function_defaults(HeapTuple func_tuple, List *defaults, Node **argarray);
static int print_pltsql_function_arguments(StringInfo buf, HeapTuple proctup, bool print_table_args, bool print_defaults);
static void pltsql_GetNewObjectId(VariableCache variableCache);
static Oid pltsql_GetNewTempObjectId(void);
static Oid pltsql_GetNewTempOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn);
static bool set_and_persist_temp_oid_buffer_start(Oid new_oid);
static bool pltsql_is_local_only_inval_msg(const SharedInvalidationMessage *msg);
static EphemeralNamedRelation pltsql_get_tsql_enr_from_oid(Oid oid);
static void pltsql_validate_var_datatype_scale(const TypeName *typeName, Type typ);
static bool pltsql_bbfCustomProcessUtility(ParseState *pstate,
PlannedStmt *pstmt,
Expand Down Expand Up @@ -222,6 +210,22 @@ static Oid set_param_collation(Param *param);
static Oid default_collation_for_builtin_type(Type typ, bool handle_text);
static char* pltsql_get_object_identity_event_trigger(ObjectAddress *addr);

/***************************************************
* Temp Table Related Declarations + Hooks
***************************************************/
#define OID_TO_BUFFER_START(oid) ((oid) + INT_MIN)
#define BUFFER_START_TO_OID ((Oid) (temp_oid_buffer_start) - INT_MIN)

/* For unit testing, to avoid concurrent heap update issues. */
bool TEST_persist_temp_oid_buffer_start_disable_catalog_update = false;

static void pltsql_GetNewObjectId(VariableCache variableCache);
static Oid pltsql_GetNewTempObjectId(void);
static Oid pltsql_GetNewTempOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn);
static bool set_and_persist_temp_oid_buffer_start(Oid new_oid);
static bool pltsql_is_local_only_inval_msg(const SharedInvalidationMessage *msg);
static EphemeralNamedRelation pltsql_get_tsql_enr_from_oid(Oid oid);

/* Save hook values in case of unload */
static core_yylex_hook_type prev_core_yylex_hook = NULL;
static pre_transform_returning_hook_type prev_pre_transform_returning_hook = NULL;
Expand Down Expand Up @@ -4796,7 +4800,7 @@ pltsql_is_local_only_inval_msg(const SharedInvalidationMessage *msg)
static EphemeralNamedRelation
pltsql_get_tsql_enr_from_oid(const Oid oid)
{
return temp_oid_buffer_size > 0 ? get_ENR_withoid(currentQueryEnv, oid, ENR_TSQL_TEMP) : NULL;
return temp_oid_buffer_size > 0 ? GetENRTempTableWithOid(oid) : NULL;
}

/*
Expand Down

0 comments on commit a457f9e

Please sign in to comment.