Skip to content

Commit 5600455

Browse files
author
Tanya Gupta
committed
creating hook for basetype typmodin in case of dump-restore
Signed-off-by: Tanya Gupta <[email protected]>
1 parent 0b00b52 commit 5600455

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/backend/parser/parse_type.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName,
3434
check_or_set_default_typmod_hook_type check_or_set_default_typmod_hook = NULL;
3535
validate_var_datatype_scale_hook_type validate_var_datatype_scale_hook = NULL;
3636
handle_default_collation_hook_type handle_default_collation_hook = NULL;
37+
handle_basetype_typmodin_hook_type handle_basetype_typmodin_hook = NULL;
3738

3839
/*
3940
* LookupTypeName
@@ -338,16 +339,11 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
338339
{
339340
int32 result;
340341
Oid typmodin;
341-
Oid typbasetype;
342-
Oid basetypeid;
343-
Oid typeoid;
344342
Datum *datums;
345343
int n;
346344
ListCell *l;
347345
ArrayType *arrtypmod;
348346
ParseCallbackState pcbstate;
349-
const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false);
350-
HeapTuple tup;
351347

352348
/* Return prespecified typmod if no typmod expressions */
353349
if (typeName->typmods == NIL)
@@ -366,18 +362,10 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
366362
parser_errposition(pstate, typeName->location)));
367363

368364
typmodin = ((Form_pg_type) GETSTRUCT(typ))->typmodin;
369-
typeoid = ((Form_pg_type) GETSTRUCT(typ))->oid;
370-
typbasetype = ((Form_pg_type) GETSTRUCT(typ))->typbasetype;
371365

372-
if (dump_restore && (strcmp(dump_restore, "on") == 0) && !OidIsValid(typmodin) && OidIsValid(typbasetype))
373-
{
374-
basetypeid = getBaseType(typeoid);
375-
tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(basetypeid));
376-
if (!HeapTupleIsValid(tup)) /* should not happen */
377-
elog(ERROR, "cache lookup failed for type %u", basetypeid);
378-
typmodin = ((Form_pg_type) GETSTRUCT((Type)tup))->typmodin;
379-
ReleaseSysCache(tup);
380-
}
366+
/* Handle the typmodin for domains like smallmoney/money and UDTs on them. */
367+
if (handle_basetype_typmodin_hook)
368+
(*handle_basetype_typmodin_hook)(typ, &typmodin);
381369

382370
if (typmodin == InvalidOid)
383371
ereport(ERROR,

src/include/parser/parse_type.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,11 @@ extern PGDLLEXPORT validate_var_datatype_scale_hook_type validate_var_datatype_s
7272
typedef Oid (*handle_default_collation_hook_type) (Type typ, bool handle_pg_type);
7373
extern PGDLLEXPORT handle_default_collation_hook_type handle_default_collation_hook;
7474

75+
/*
76+
* Hook to find the typmodin for domains like smallmoney/money
77+
* and UDTs created on them, in case of dump_restore.
78+
*/
79+
typedef void (*handle_basetype_typmodin_hook_type) (Type typ, Oid *typmodin);
80+
extern PGDLLEXPORT handle_basetype_typmodin_hook_type handle_basetype_typmodin_hook;
81+
7582
#endif /* PARSE_TYPE_H */

0 commit comments

Comments
 (0)