From a457f9e54933dd5e9341d1c20256e4418ca926c5 Mon Sep 17 00:00:00 2001 From: Tim Chang Date: Thu, 7 Nov 2024 17:48:07 -0500 Subject: [PATCH] Clean up temp table naming, introduce new functions for readability (#2975) Signed-off-by: Tim Chang --- contrib/babelfishpg_tsql/runtime/functions.c | 2 +- contrib/babelfishpg_tsql/src/catalog.c | 3 +- contrib/babelfishpg_tsql/src/hooks.c | 30 +++++++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/contrib/babelfishpg_tsql/runtime/functions.c b/contrib/babelfishpg_tsql/runtime/functions.c index e57eeeda2a..f30a575037 100644 --- a/contrib/babelfishpg_tsql/runtime/functions.c +++ b/contrib/babelfishpg_tsql/runtime/functions.c @@ -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)); diff --git a/contrib/babelfishpg_tsql/src/catalog.c b/contrib/babelfishpg_tsql/src/catalog.c index 6501c09b61..5843773213 100644 --- a/contrib/babelfishpg_tsql/src/catalog.c +++ b/contrib/babelfishpg_tsql/src/catalog.c @@ -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; diff --git a/contrib/babelfishpg_tsql/src/hooks.c b/contrib/babelfishpg_tsql/src/hooks.c index 716c277ff8..6e272c95e4 100644 --- a/contrib/babelfishpg_tsql/src/hooks.c +++ b/contrib/babelfishpg_tsql/src/hooks.c @@ -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 *****************************************/ @@ -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, @@ -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; @@ -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; } /*