MCPcopy Create free account
hub / github.com/apache/cloudberry / gettype

Function gettype

src/backend/bootstrap/bootstrap.c:959–1018  ·  view source on GitHub ↗

---------------- * gettype * * NB: this is really ugly; it will return an integer index into TypInfo[], * and not an OID at all, until the first reference to a type not known in * TypInfo[]. At that point it will read and cache pg_type in Typ, * and subsequently return a real OID (and set the global pointer Ap to * point at the found row in Typ). So caller must check whether Typ is * st

Source from the content-addressed store, hash-verified

957 * ----------------
958 */
959static Oid
960gettype(char *type)
961{
962 if (Typ != NIL)
963 {
964 ListCell *lc;
965
966 foreach(lc, Typ)
967 {
968 struct typmap *app = lfirst(lc);
969
970 if (strncmp(NameStr(app->am_typ.typname), type, NAMEDATALEN) == 0)
971 {
972 Ap = app;
973 return app->am_oid;
974 }
975 }
976
977 /*
978 * The type wasn't known; reload the pg_type contents and check again
979 * to handle composite types, added since last populating the list.
980 */
981
982 list_free_deep(Typ);
983 Typ = NIL;
984 populate_typ_list();
985
986 /*
987 * Calling gettype would result in infinite recursion for types
988 * missing in pg_type, so just repeat the lookup.
989 */
990 foreach(lc, Typ)
991 {
992 struct typmap *app = lfirst(lc);
993
994 if (strncmp(NameStr(app->am_typ.typname), type, NAMEDATALEN) == 0)
995 {
996 Ap = app;
997 return app->am_oid;
998 }
999 }
1000 }
1001 else
1002 {
1003 int i;
1004
1005 for (i = 0; i < n_types; i++)
1006 {
1007 if (strncmp(type, TypInfo[i].name, NAMEDATALEN) == 0)
1008 return i;
1009 }
1010 /* Not in TypInfo, so we'd better be able to read pg_type now */
1011 elog(DEBUG4, "external type: %s", type);
1012 populate_typ_list();
1013 return gettype(type);
1014 }
1015 elog(ERROR, "unrecognized type \"%s\"", type);
1016 /* not reached, here to make compiler happy */

Callers 1

DefineAttrFunction · 0.85

Calls 3

list_free_deepFunction · 0.85
populate_typ_listFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected