Skip to content

Commit dba1b67

Browse files
Ayush-061Ayush-061
andauthored
[BABEL] Functions find_ENR_queryEnv, get_toast_parent_oid moved from header file to C file. (#728)
Functions moved to queryenv C file Co-authored-by: Ayush-061 <ayushhx@amazon.com>
1 parent 98a6fdc commit dba1b67

2 files changed

Lines changed: 46 additions & 48 deletions

File tree

src/backend/utils/misc/queryenvironment.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
#include "utils/rel.h"
5555

5656
#define NUM_ENR_CATALOGS 11
57+
#define BBF_TEMP_TOAST_PREFIX "#pg_toast_"
58+
#define BBF_TABLEVAR_TOAST_PREFIX "@pg_toast_"
59+
#define BBF_TOAST_PREFIX_LEN 10
60+
#define BASE_10 10
5761

5862
find_object_in_enr_hook_type find_object_in_enr_hook = NULL;
5963
is_enr_to_sys_object_dependency_hook_type is_enr_to_sys_object_dependency_hook = NULL;
@@ -1965,4 +1969,43 @@ bool has_existing_enr_relations()
19651969
}
19661970

19671971
return false;
1972+
}
1973+
1974+
/*
1975+
* get_toast_parent_oid
1976+
*
1977+
* Extract parent table OID from temp toast table name.
1978+
* Toast table names follow the pattern "#pg_toast_<parent_rel_oid>" for temp tables
1979+
* or "@pg_toast_<parent_rel_oid>" for table variables.
1980+
* Returns the parent OID, or InvalidOid if the name doesn't match either pattern.
1981+
*/
1982+
Oid
1983+
get_toast_parent_oid(const char *relname)
1984+
{
1985+
if (strncmp(relname, BBF_TEMP_TOAST_PREFIX, BBF_TOAST_PREFIX_LEN) == 0 ||
1986+
strncmp(relname, BBF_TABLEVAR_TOAST_PREFIX, BBF_TOAST_PREFIX_LEN) == 0)
1987+
return (Oid) strtoul(relname + BBF_TOAST_PREFIX_LEN, NULL, BASE_10);
1988+
return InvalidOid;
1989+
}
1990+
1991+
/*
1992+
* find_ENR_queryEnv
1993+
*
1994+
* Find the query environment where an ENR with the given OID is registered.
1995+
* Searches from currentQueryEnv up through parent environments.
1996+
* Returns the queryEnv where the ENR is found, or NULL if not found.
1997+
*/
1998+
QueryEnvironment *
1999+
find_ENR_queryEnv(Oid relid)
2000+
{
2001+
QueryEnvironment *qe = currentQueryEnv;
2002+
2003+
while (qe)
2004+
{
2005+
if (get_ENR_withoid(qe, relid, ENR_TSQL_TEMP, false))
2006+
return qe;
2007+
qe = qe->parentEnv;
2008+
}
2009+
2010+
return NULL;
19682011
}

src/include/utils/queryenvironment.h

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ extern bool ENRGetSystableScan(Relation rel, Oid indexoid, int nkeys, ScanKey ke
157157
extern bool ENRAddTuple(Relation rel, HeapTuple tup);
158158
extern bool ENRDropTuple(Relation rel, HeapTuple tup);
159159
extern bool ENRUpdateTuple(Relation rel, HeapTuple tup);
160+
extern Oid get_toast_parent_oid(const char *relname);
161+
extern QueryEnvironment *find_ENR_queryEnv(Oid relid);
160162

161163
extern void ENRDropEntry(Oid id);
162164
extern PGDLLEXPORT void ENRDropTempTables(QueryEnvironment *queryEnv);
@@ -188,51 +190,4 @@ extern PGDLLIMPORT find_object_in_enr_hook_type find_object_in_enr_hook;
188190
typedef bool (*is_enr_to_sys_object_dependency_hook_type) (const ObjectAddress *depender, const ObjectAddress *referenced);
189191
extern PGDLLIMPORT is_enr_to_sys_object_dependency_hook_type is_enr_to_sys_object_dependency_hook;
190192

191-
/*
192-
* Babelfish toast table name prefixes and length.
193-
* Toast tables for temp tables are named "#pg_toast_<parent_rel_oid>".
194-
* Toast tables for table variables are named "@pg_toast_<parent_rel_oid>".
195-
* Both prefixes have the same length (10 characters).
196-
*/
197-
#define BBF_TEMP_TOAST_PREFIX "#pg_toast_"
198-
#define BBF_TABLEVAR_TOAST_PREFIX "@pg_toast_"
199-
#define BBF_TOAST_PREFIX_LEN 10
200-
201-
/*
202-
* Extract parent table OID from temp toast table name.
203-
* Toast table names follow the pattern "#pg_toast_<parent_rel_oid>" for temp tables
204-
* or "@pg_toast_<parent_rel_oid>" for table variables.
205-
* Returns the parent OID, or InvalidOid if the name doesn't match either pattern.
206-
*/
207-
static inline Oid
208-
get_toast_parent_oid(const char *relname)
209-
{
210-
if (strncmp(relname, BBF_TEMP_TOAST_PREFIX, BBF_TOAST_PREFIX_LEN) == 0 ||
211-
strncmp(relname, BBF_TABLEVAR_TOAST_PREFIX, BBF_TOAST_PREFIX_LEN) == 0)
212-
return (Oid) strtoul(relname + BBF_TOAST_PREFIX_LEN, NULL, 10);
213-
return InvalidOid;
214-
}
215-
216-
/*
217-
* find_ENR_queryEnv
218-
*
219-
* Find the query environment where an ENR with the given OID is registered.
220-
* Searches from currentQueryEnv up through parent environments.
221-
* Returns the queryEnv where the ENR is found, or NULL if not found.
222-
*/
223-
static inline QueryEnvironment *
224-
find_ENR_queryEnv(Oid relid)
225-
{
226-
QueryEnvironment *qe = currentQueryEnv;
227-
228-
while (qe)
229-
{
230-
if (get_ENR_withoid(qe, relid, ENR_TSQL_TEMP, false))
231-
return qe;
232-
qe = qe->parentEnv;
233-
}
234-
235-
return NULL;
236-
}
237-
238-
#endif /* QUERYENVIRONMENT_H */
193+
#endif /* QUERYENVIRONMENT_H */

0 commit comments

Comments
 (0)