PostgreSQL Source Code git master
Loading...
Searching...
No Matches
typcache.h File Reference
#include "access/tupdesc.h"
#include "fmgr.h"
#include "storage/dsm.h"
#include "utils/dsa.h"
Include dependency graph for typcache.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TypeCacheEntry
 
struct  DomainConstraintRef
 

Macros

#define TYPECACHE_EQ_OPR   0x00001
 
#define TYPECACHE_LT_OPR   0x00002
 
#define TYPECACHE_GT_OPR   0x00004
 
#define TYPECACHE_CMP_PROC   0x00008
 
#define TYPECACHE_HASH_PROC   0x00010
 
#define TYPECACHE_EQ_OPR_FINFO   0x00020
 
#define TYPECACHE_CMP_PROC_FINFO   0x00040
 
#define TYPECACHE_HASH_PROC_FINFO   0x00080
 
#define TYPECACHE_TUPDESC   0x00100
 
#define TYPECACHE_BTREE_OPFAMILY   0x00200
 
#define TYPECACHE_HASH_OPFAMILY   0x00400
 
#define TYPECACHE_RANGE_INFO   0x00800
 
#define TYPECACHE_DOMAIN_BASE_INFO   0x01000
 
#define TYPECACHE_DOMAIN_CONSTR_INFO   0x02000
 
#define TYPECACHE_HASH_EXTENDED_PROC   0x04000
 
#define TYPECACHE_HASH_EXTENDED_PROC_FINFO   0x08000
 
#define TYPECACHE_MULTIRANGE_INFO   0x10000
 
#define INVALID_TUPLEDESC_IDENTIFIER   ((uint64) 1)
 

Typedefs

typedef struct DomainConstraintCache DomainConstraintCache
 
typedef struct TypeCacheEntry TypeCacheEntry
 
typedef struct DomainConstraintRef DomainConstraintRef
 
typedef struct SharedRecordTypmodRegistry SharedRecordTypmodRegistry
 

Functions

TypeCacheEntrylookup_type_cache (Oid type_id, int flags)
 
void InitDomainConstraintRef (Oid type_id, DomainConstraintRef *ref, MemoryContext refctx, bool need_exprstate)
 
void UpdateDomainConstraintRef (DomainConstraintRef *ref)
 
bool DomainHasConstraints (Oid type_id)
 
TupleDesc lookup_rowtype_tupdesc (Oid type_id, int32 typmod)
 
TupleDesc lookup_rowtype_tupdesc_noerror (Oid type_id, int32 typmod, bool noError)
 
TupleDesc lookup_rowtype_tupdesc_copy (Oid type_id, int32 typmod)
 
TupleDesc lookup_rowtype_tupdesc_domain (Oid type_id, int32 typmod, bool noError)
 
void assign_record_type_typmod (TupleDesc tupDesc)
 
uint64 assign_record_type_identifier (Oid type_id, int32 typmod)
 
int compare_values_of_enum (TypeCacheEntry *tcache, Oid arg1, Oid arg2)
 
size_t SharedRecordTypmodRegistryEstimate (void)
 
void SharedRecordTypmodRegistryInit (SharedRecordTypmodRegistry *, dsm_segment *segment, dsa_area *area)
 
void SharedRecordTypmodRegistryAttach (SharedRecordTypmodRegistry *)
 
void AtEOXact_TypeCache (void)
 
void AtEOSubXact_TypeCache (void)
 

Macro Definition Documentation

◆ INVALID_TUPLEDESC_IDENTIFIER

#define INVALID_TUPLEDESC_IDENTIFIER   ((uint64) 1)

Definition at line 157 of file typcache.h.

◆ TYPECACHE_BTREE_OPFAMILY

#define TYPECACHE_BTREE_OPFAMILY   0x00200

Definition at line 147 of file typcache.h.

◆ TYPECACHE_CMP_PROC

#define TYPECACHE_CMP_PROC   0x00008

Definition at line 141 of file typcache.h.

◆ TYPECACHE_CMP_PROC_FINFO

#define TYPECACHE_CMP_PROC_FINFO   0x00040

Definition at line 144 of file typcache.h.

◆ TYPECACHE_DOMAIN_BASE_INFO

#define TYPECACHE_DOMAIN_BASE_INFO   0x01000

Definition at line 150 of file typcache.h.

◆ TYPECACHE_DOMAIN_CONSTR_INFO

#define TYPECACHE_DOMAIN_CONSTR_INFO   0x02000

Definition at line 151 of file typcache.h.

◆ TYPECACHE_EQ_OPR

#define TYPECACHE_EQ_OPR   0x00001

Definition at line 138 of file typcache.h.

◆ TYPECACHE_EQ_OPR_FINFO

#define TYPECACHE_EQ_OPR_FINFO   0x00020

Definition at line 143 of file typcache.h.

◆ TYPECACHE_GT_OPR

#define TYPECACHE_GT_OPR   0x00004

Definition at line 140 of file typcache.h.

◆ TYPECACHE_HASH_EXTENDED_PROC

#define TYPECACHE_HASH_EXTENDED_PROC   0x04000

Definition at line 152 of file typcache.h.

◆ TYPECACHE_HASH_EXTENDED_PROC_FINFO

#define TYPECACHE_HASH_EXTENDED_PROC_FINFO   0x08000

Definition at line 153 of file typcache.h.

◆ TYPECACHE_HASH_OPFAMILY

#define TYPECACHE_HASH_OPFAMILY   0x00400

Definition at line 148 of file typcache.h.

◆ TYPECACHE_HASH_PROC

#define TYPECACHE_HASH_PROC   0x00010

Definition at line 142 of file typcache.h.

◆ TYPECACHE_HASH_PROC_FINFO

#define TYPECACHE_HASH_PROC_FINFO   0x00080

Definition at line 145 of file typcache.h.

◆ TYPECACHE_LT_OPR

#define TYPECACHE_LT_OPR   0x00002

Definition at line 139 of file typcache.h.

◆ TYPECACHE_MULTIRANGE_INFO

#define TYPECACHE_MULTIRANGE_INFO   0x10000

Definition at line 154 of file typcache.h.

◆ TYPECACHE_RANGE_INFO

#define TYPECACHE_RANGE_INFO   0x00800

Definition at line 149 of file typcache.h.

◆ TYPECACHE_TUPDESC

#define TYPECACHE_TUPDESC   0x00100

Definition at line 146 of file typcache.h.

Typedef Documentation

◆ DomainConstraintCache

Definition at line 26 of file typcache.h.

◆ DomainConstraintRef

◆ SharedRecordTypmodRegistry

◆ TypeCacheEntry

Function Documentation

◆ assign_record_type_identifier()

uint64 assign_record_type_identifier ( Oid  type_id,
int32  typmod 
)
extern

Definition at line 2136 of file typcache.c.

2137{
2138 if (type_id != RECORDOID)
2139 {
2140 /*
2141 * It's a named composite type, so use the regular typcache.
2142 */
2143 TypeCacheEntry *typentry;
2144
2145 typentry = lookup_type_cache(type_id, TYPECACHE_TUPDESC);
2146 if (typentry->tupDesc == NULL)
2147 ereport(ERROR,
2149 errmsg("type %s is not composite",
2150 format_type_be(type_id))));
2151 Assert(typentry->tupDesc_identifier != 0);
2152 return typentry->tupDesc_identifier;
2153 }
2154 else
2155 {
2156 /*
2157 * It's a transient record type, so look in our record-type table.
2158 */
2159 if (typmod >= 0 && typmod < RecordCacheArrayLen &&
2160 RecordCacheArray[typmod].tupdesc != NULL)
2161 {
2162 Assert(RecordCacheArray[typmod].id != 0);
2163 return RecordCacheArray[typmod].id;
2164 }
2165
2166 /* For anonymous or unrecognized record type, generate a new ID */
2167 return ++tupledesc_id_counter;
2168 }
2169}
#define Assert(condition)
Definition c.h:873
int errcode(int sqlerrcode)
Definition elog.c:864
int errmsg(const char *fmt,...)
Definition elog.c:1081
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
char * format_type_be(Oid type_oid)
static int fb(int x)
uint64 tupDesc_identifier
Definition typcache.h:91
TupleDesc tupDesc
Definition typcache.h:90
static RecordCacheArrayEntry * RecordCacheArray
Definition typcache.c:304
static int32 RecordCacheArrayLen
Definition typcache.c:305
static uint64 tupledesc_id_counter
Definition typcache.c:313
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
Definition typcache.c:389
#define TYPECACHE_TUPDESC
Definition typcache.h:146

References Assert, ereport, errcode(), errmsg(), ERROR, fb(), format_type_be(), RecordCacheArrayEntry::id, lookup_type_cache(), RecordCacheArray, RecordCacheArrayLen, TypeCacheEntry::tupDesc, TypeCacheEntry::tupDesc_identifier, tupledesc_id_counter, and TYPECACHE_TUPDESC.

Referenced by expanded_record_fetch_tupdesc(), make_expanded_record_from_tupdesc(), and make_expanded_record_from_typeid().

◆ assign_record_type_typmod()

void assign_record_type_typmod ( TupleDesc  tupDesc)
extern

Definition at line 2044 of file typcache.c.

2045{
2048 bool found;
2050
2051 Assert(tupDesc->tdtypeid == RECORDOID);
2052
2053 if (RecordCacheHash == NULL)
2054 {
2055 /* First time through: initialize the hash table */
2056 HASHCTL ctl;
2057
2058 ctl.keysize = sizeof(TupleDesc); /* just the pointer */
2059 ctl.entrysize = sizeof(RecordCacheEntry);
2062 RecordCacheHash = hash_create("Record information cache", 64,
2063 &ctl,
2065
2066 /* Also make sure CacheMemoryContext exists */
2067 if (!CacheMemoryContext)
2069 }
2070
2071 /*
2072 * Find a hashtable entry for this tuple descriptor. We don't use
2073 * HASH_ENTER yet, because if it's missing, we need to make sure that all
2074 * the allocations succeed before we create the new entry.
2075 */
2077 &tupDesc,
2078 HASH_FIND, &found);
2079 if (found && recentry->tupdesc != NULL)
2080 {
2081 tupDesc->tdtypmod = recentry->tupdesc->tdtypmod;
2082 return;
2083 }
2084
2085 /* Not present, so need to manufacture an entry */
2087
2088 /* Look in the SharedRecordTypmodRegistry, if attached */
2090 if (entDesc == NULL)
2091 {
2092 /*
2093 * Make sure we have room before we CreateTupleDescCopy() or advance
2094 * NextRecordTypmod.
2095 */
2097
2098 /* Reference-counted local cache only. */
2099 entDesc = CreateTupleDescCopy(tupDesc);
2100 entDesc->tdrefcount = 1;
2101 entDesc->tdtypmod = NextRecordTypmod++;
2102 }
2103 else
2104 {
2106 }
2107
2109
2110 /* Assign a unique tupdesc identifier, too. */
2112
2113 /* Fully initialized; create the hash table entry */
2115 &tupDesc,
2116 HASH_ENTER, NULL);
2117 recentry->tupdesc = entDesc;
2118
2119 /* Update the caller's tuple descriptor. */
2120 tupDesc->tdtypmod = entDesc->tdtypmod;
2121
2123}
void CreateCacheMemoryContext(void)
Definition catcache.c:715
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:952
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition dynahash.c:358
@ HASH_FIND
Definition hsearch.h:113
@ HASH_ENTER
Definition hsearch.h:114
#define HASH_ELEM
Definition hsearch.h:95
#define HASH_COMPARE
Definition hsearch.h:99
#define HASH_FUNCTION
Definition hsearch.h:98
MemoryContext CacheMemoryContext
Definition mcxt.c:169
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
tree ctl
Definition radixtree.h:1838
Size keysize
Definition hsearch.h:75
int32 tdtypmod
Definition tupdesc.h:139
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition tupdesc.c:235
struct TupleDescData * TupleDesc
Definition tupdesc.h:145
static TupleDesc find_or_make_matching_shared_tupledesc(TupleDesc tupdesc)
Definition typcache.c:2945
static int32 NextRecordTypmod
Definition typcache.c:306
static HTAB * RecordCacheHash
Definition typcache.c:295
static int record_type_typmod_compare(const void *a, const void *b, size_t size)
Definition typcache.c:2028
static void ensure_record_cache_typmod_slot_exists(int32 typmod)
Definition typcache.c:1801
static uint32 record_type_typmod_hash(const void *data, size_t size)
Definition typcache.c:2017

References Assert, CacheMemoryContext, CreateCacheMemoryContext(), CreateTupleDescCopy(), ctl, ensure_record_cache_typmod_slot_exists(), fb(), find_or_make_matching_shared_tupledesc(), HASH_COMPARE, hash_create(), HASH_ELEM, HASH_ENTER, HASH_FIND, HASH_FUNCTION, hash_search(), RecordCacheArrayEntry::id, HASHCTL::keysize, MemoryContextSwitchTo(), NextRecordTypmod, record_type_typmod_compare(), record_type_typmod_hash(), RecordCacheArray, RecordCacheHash, TupleDescData::tdtypeid, TupleDescData::tdtypmod, RecordCacheArrayEntry::tupdesc, and tupledesc_id_counter.

Referenced by BlessTupleDesc(), ER_get_flat_size(), internal_get_result_type(), and SPI_returntuple().

◆ AtEOSubXact_TypeCache()

void AtEOSubXact_TypeCache ( void  )
extern

Definition at line 3200 of file typcache.c.

3201{
3203}
static void finalize_in_progress_typentries(void)
Definition typcache.c:3175

References finalize_in_progress_typentries().

Referenced by AbortSubTransaction(), and CommitSubTransaction().

◆ AtEOXact_TypeCache()

void AtEOXact_TypeCache ( void  )
extern

◆ compare_values_of_enum()

int compare_values_of_enum ( TypeCacheEntry tcache,
Oid  arg1,
Oid  arg2 
)
extern

Definition at line 2666 of file typcache.c.

2667{
2669 EnumItem *item1;
2670 EnumItem *item2;
2671
2672 /*
2673 * Equal OIDs are certainly equal --- this case was probably handled by
2674 * our caller, but we may as well check.
2675 */
2676 if (arg1 == arg2)
2677 return 0;
2678
2679 /* Load up the cache if first time through */
2680 if (tcache->enumData == NULL)
2681 load_enum_cache_data(tcache);
2682 enumdata = tcache->enumData;
2683
2684 /*
2685 * If both OIDs are known-sorted, we can just compare them directly.
2686 */
2689 {
2690 if (arg1 < arg2)
2691 return -1;
2692 else
2693 return 1;
2694 }
2695
2696 /*
2697 * Slow path: we have to identify their actual sort-order positions.
2698 */
2701
2702 if (item1 == NULL || item2 == NULL)
2703 {
2704 /*
2705 * We couldn't find one or both values. That means the enum has
2706 * changed under us, so re-initialize the cache and try again. We
2707 * don't bother retrying the known-sorted case in this path.
2708 */
2709 load_enum_cache_data(tcache);
2710 enumdata = tcache->enumData;
2711
2714
2715 /*
2716 * If we still can't find the values, complain: we must have corrupt
2717 * data.
2718 */
2719 if (item1 == NULL)
2720 elog(ERROR, "enum value %u not found in cache for enum %s",
2721 arg1, format_type_be(tcache->type_id));
2722 if (item2 == NULL)
2723 elog(ERROR, "enum value %u not found in cache for enum %s",
2724 arg2, format_type_be(tcache->type_id));
2725 }
2726
2727 if (item1->sort_order < item2->sort_order)
2728 return -1;
2729 else if (item1->sort_order > item2->sort_order)
2730 return 1;
2731 else
2732 return 0;
2733}
#define elog(elevel,...)
Definition elog.h:226
struct TypeCacheEnumData * enumData
Definition typcache.h:131
static void load_enum_cache_data(TypeCacheEntry *tcache)
Definition typcache.c:2739
static EnumItem * find_enumitem(TypeCacheEnumData *enumdata, Oid arg)
Definition typcache.c:2894
static bool enum_known_sorted(TypeCacheEnumData *enumdata, Oid arg)
Definition typcache.c:2637

References elog, enum_known_sorted(), TypeCacheEntry::enumData, ERROR, fb(), find_enumitem(), format_type_be(), load_enum_cache_data(), and TypeCacheEntry::type_id.

Referenced by enum_cmp_internal().

◆ DomainHasConstraints()

bool DomainHasConstraints ( Oid  type_id)
extern

Definition at line 1491 of file typcache.c.

1492{
1493 TypeCacheEntry *typentry;
1494
1495 /*
1496 * Note: a side effect is to cause the typcache's domain data to become
1497 * valid. This is fine since we'll likely need it soon if there is any.
1498 */
1500
1501 return (typentry->domainData != NULL);
1502}
DomainConstraintCache * domainData
Definition typcache.h:122
#define TYPECACHE_DOMAIN_CONSTR_INFO
Definition typcache.h:151

References TypeCacheEntry::domainData, fb(), lookup_type_cache(), and TYPECACHE_DOMAIN_CONSTR_INFO.

Referenced by ATColumnChangeRequiresRewrite(), ATExecAddColumn(), eval_const_expressions_mutator(), ExecInitJsonCoercion(), and transformJsonFuncExpr().

◆ InitDomainConstraintRef()

void InitDomainConstraintRef ( Oid  type_id,
DomainConstraintRef ref,
MemoryContext  refctx,
bool  need_exprstate 
)
extern

Definition at line 1404 of file typcache.c.

1406{
1407 /* Look up the typcache entry --- we assume it survives indefinitely */
1409 ref->need_exprstate = need_exprstate;
1410 /* For safety, establish the callback before acquiring a refcount */
1411 ref->refctx = refctx;
1412 ref->dcc = NULL;
1413 ref->callback.func = dccref_deletion_callback;
1414 ref->callback.arg = ref;
1415 MemoryContextRegisterResetCallback(refctx, &ref->callback);
1416 /* Acquire refcount if there are constraints, and set up exported list */
1417 if (ref->tcache->domainData)
1418 {
1419 ref->dcc = ref->tcache->domainData;
1420 ref->dcc->dccRefCount++;
1421 if (ref->need_exprstate)
1422 ref->constraints = prep_domain_constraints(ref->dcc->constraints,
1423 ref->refctx);
1424 else
1425 ref->constraints = ref->dcc->constraints;
1426 }
1427 else
1428 ref->constraints = NIL;
1429}
void MemoryContextRegisterResetCallback(MemoryContext context, MemoryContextCallback *cb)
Definition mcxt.c:582
#define NIL
Definition pg_list.h:68
static List * prep_domain_constraints(List *constraints, MemoryContext execctx)
Definition typcache.c:1366
static void dccref_deletion_callback(void *arg)
Definition typcache.c:1345

References dccref_deletion_callback(), fb(), lookup_type_cache(), MemoryContextRegisterResetCallback(), NIL, prep_domain_constraints(), and TYPECACHE_DOMAIN_CONSTR_INFO.

Referenced by domain_state_setup(), and ExecInitCoerceToDomain().

◆ lookup_rowtype_tupdesc()

◆ lookup_rowtype_tupdesc_copy()

TupleDesc lookup_rowtype_tupdesc_copy ( Oid  type_id,
int32  typmod 
)
extern

Definition at line 1958 of file typcache.c.

1959{
1960 TupleDesc tmp;
1961
1962 tmp = lookup_rowtype_tupdesc_internal(type_id, typmod, false);
1963 return CreateTupleDescCopyConstr(tmp);
1964}
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
Definition tupdesc.c:323

References CreateTupleDescCopyConstr(), and lookup_rowtype_tupdesc_internal().

Referenced by ExecInitExprRec(), ExecMakeTableFunctionResult(), get_expr_result_type(), internal_get_result_type(), and TypeGetTupleDesc().

◆ lookup_rowtype_tupdesc_domain()

TupleDesc lookup_rowtype_tupdesc_domain ( Oid  type_id,
int32  typmod,
bool  noError 
)
extern

Definition at line 1980 of file typcache.c.

1981{
1982 TupleDesc tupDesc;
1983
1984 if (type_id != RECORDOID)
1985 {
1986 /*
1987 * Check for domain or named composite type. We might as well load
1988 * whichever data is needed.
1989 */
1990 TypeCacheEntry *typentry;
1991
1992 typentry = lookup_type_cache(type_id,
1995 if (typentry->typtype == TYPTYPE_DOMAIN)
1997 typentry->domainBaseTypmod,
1998 noError);
1999 if (typentry->tupDesc == NULL && !noError)
2000 ereport(ERROR,
2002 errmsg("type %s is not composite",
2003 format_type_be(type_id))));
2004 tupDesc = typentry->tupDesc;
2005 }
2006 else
2007 tupDesc = lookup_rowtype_tupdesc_internal(type_id, typmod, noError);
2008 if (tupDesc != NULL)
2009 PinTupleDesc(tupDesc);
2010 return tupDesc;
2011}
int32 domainBaseTypmod
Definition typcache.h:116
TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError)
Definition typcache.c:1941
#define TYPECACHE_DOMAIN_BASE_INFO
Definition typcache.h:150

References TypeCacheEntry::domainBaseType, TypeCacheEntry::domainBaseTypmod, ereport, errcode(), errmsg(), ERROR, fb(), format_type_be(), lookup_rowtype_tupdesc_internal(), lookup_rowtype_tupdesc_noerror(), lookup_type_cache(), PinTupleDesc, TypeCacheEntry::tupDesc, TYPECACHE_DOMAIN_BASE_INFO, TYPECACHE_TUPDESC, and TypeCacheEntry::typtype.

Referenced by ExecEvalWholeRowVar(), hstore_from_record(), hstore_populate_record(), plperl_sv_to_datum(), and rowtype_field_matches().

◆ lookup_rowtype_tupdesc_noerror()

TupleDesc lookup_rowtype_tupdesc_noerror ( Oid  type_id,
int32  typmod,
bool  noError 
)
extern

Definition at line 1941 of file typcache.c.

1942{
1943 TupleDesc tupDesc;
1944
1945 tupDesc = lookup_rowtype_tupdesc_internal(type_id, typmod, noError);
1946 if (tupDesc != NULL)
1947 PinTupleDesc(tupDesc);
1948 return tupDesc;
1949}

References fb(), lookup_rowtype_tupdesc_internal(), and PinTupleDesc.

Referenced by lookup_rowtype_tupdesc_domain().

◆ lookup_type_cache()

TypeCacheEntry * lookup_type_cache ( Oid  type_id,
int  flags 
)
extern

Definition at line 389 of file typcache.c.

390{
391 TypeCacheEntry *typentry;
392 bool found;
394
395 if (TypeCacheHash == NULL)
396 {
397 /* First time through: initialize the hash table */
398 HASHCTL ctl;
399 int allocsize;
400
401 ctl.keysize = sizeof(Oid);
402 ctl.entrysize = sizeof(TypeCacheEntry);
403
404 /*
405 * TypeCacheEntry takes hash value from the system cache. For
406 * TypeCacheHash we use the same hash in order to speedup search by
407 * hash value. This is used by hash_seq_init_with_hash_value().
408 */
409 ctl.hash = type_cache_syshash;
410
411 TypeCacheHash = hash_create("Type information cache", 64,
413
415
416 ctl.keysize = sizeof(Oid);
417 ctl.entrysize = sizeof(RelIdToTypeIdCacheEntry);
418 RelIdToTypeIdCacheHash = hash_create("Map from relid to OID of cached composite type", 64,
420
421 /* Also set up callbacks for SI invalidations */
426
427 /* Also make sure CacheMemoryContext exists */
430
431 /*
432 * reserve enough in_progress_list slots for many cases
433 */
434 allocsize = 4;
437 allocsize * sizeof(*in_progress_list));
438 in_progress_list_maxlen = allocsize;
439 }
440
442
443 /* Register to catch invalidation messages */
445 {
446 int allocsize;
447
448 allocsize = in_progress_list_maxlen * 2;
450 allocsize * sizeof(*in_progress_list));
451 in_progress_list_maxlen = allocsize;
452 }
455
456 /* Try to look up an existing entry */
458 &type_id,
459 HASH_FIND, NULL);
460 if (typentry == NULL)
461 {
462 /*
463 * If we didn't find one, we want to make one. But first look up the
464 * pg_type row, just to make sure we don't make a cache entry for an
465 * invalid type OID. If the type OID is not valid, present a
466 * user-facing error, since some code paths such as domain_in() allow
467 * this function to be reached with a user-supplied OID.
468 */
469 HeapTuple tp;
471
473 if (!HeapTupleIsValid(tp))
476 errmsg("type with OID %u does not exist", type_id)));
478 if (!typtup->typisdefined)
481 errmsg("type \"%s\" is only a shell",
482 NameStr(typtup->typname))));
483
484 /* Now make the typcache entry */
486 &type_id,
487 HASH_ENTER, &found);
488 Assert(!found); /* it wasn't there a moment ago */
489
490 MemSet(typentry, 0, sizeof(TypeCacheEntry));
491
492 /* These fields can never change, by definition */
493 typentry->type_id = type_id;
494 typentry->type_id_hash = get_hash_value(TypeCacheHash, &type_id);
495
496 /* Keep this part in sync with the code below */
497 typentry->typlen = typtup->typlen;
498 typentry->typbyval = typtup->typbyval;
499 typentry->typalign = typtup->typalign;
500 typentry->typstorage = typtup->typstorage;
501 typentry->typtype = typtup->typtype;
502 typentry->typrelid = typtup->typrelid;
503 typentry->typsubscript = typtup->typsubscript;
504 typentry->typelem = typtup->typelem;
505 typentry->typarray = typtup->typarray;
506 typentry->typcollation = typtup->typcollation;
507 typentry->flags |= TCFLAGS_HAVE_PG_TYPE_DATA;
508
509 /* If it's a domain, immediately thread it into the domain cache list */
510 if (typentry->typtype == TYPTYPE_DOMAIN)
511 {
513 firstDomainTypeEntry = typentry;
514 }
515
516 ReleaseSysCache(tp);
517 }
518 else if (!(typentry->flags & TCFLAGS_HAVE_PG_TYPE_DATA))
519 {
520 /*
521 * We have an entry, but its pg_type row got changed, so reload the
522 * data obtained directly from pg_type.
523 */
524 HeapTuple tp;
526
528 if (!HeapTupleIsValid(tp))
531 errmsg("type with OID %u does not exist", type_id)));
533 if (!typtup->typisdefined)
536 errmsg("type \"%s\" is only a shell",
537 NameStr(typtup->typname))));
538
539 /*
540 * Keep this part in sync with the code above. Many of these fields
541 * shouldn't ever change, particularly typtype, but copy 'em anyway.
542 */
543 typentry->typlen = typtup->typlen;
544 typentry->typbyval = typtup->typbyval;
545 typentry->typalign = typtup->typalign;
546 typentry->typstorage = typtup->typstorage;
547 typentry->typtype = typtup->typtype;
548 typentry->typrelid = typtup->typrelid;
549 typentry->typsubscript = typtup->typsubscript;
550 typentry->typelem = typtup->typelem;
551 typentry->typarray = typtup->typarray;
552 typentry->typcollation = typtup->typcollation;
553 typentry->flags |= TCFLAGS_HAVE_PG_TYPE_DATA;
554
555 ReleaseSysCache(tp);
556 }
557
558 /*
559 * Look up opclasses if we haven't already and any dependent info is
560 * requested.
561 */
567 {
568 Oid opclass;
569
570 opclass = GetDefaultOpClass(type_id, BTREE_AM_OID);
571 if (OidIsValid(opclass))
572 {
573 typentry->btree_opf = get_opclass_family(opclass);
574 typentry->btree_opintype = get_opclass_input_type(opclass);
575 }
576 else
577 {
578 typentry->btree_opf = typentry->btree_opintype = InvalidOid;
579 }
580
581 /*
582 * Reset information derived from btree opclass. Note in particular
583 * that we'll redetermine the eq_opr even if we previously found one;
584 * this matters in case a btree opclass has been added to a type that
585 * previously had only a hash opclass.
586 */
587 typentry->flags &= ~(TCFLAGS_CHECKED_EQ_OPR |
592 }
593
594 /*
595 * If we need to look up equality operator, and there's no btree opclass,
596 * force lookup of hash opclass.
597 */
598 if ((flags & (TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO)) &&
599 !(typentry->flags & TCFLAGS_CHECKED_EQ_OPR) &&
600 typentry->btree_opf == InvalidOid)
602
607 !(typentry->flags & TCFLAGS_CHECKED_HASH_OPCLASS))
608 {
609 Oid opclass;
610
611 opclass = GetDefaultOpClass(type_id, HASH_AM_OID);
612 if (OidIsValid(opclass))
613 {
614 typentry->hash_opf = get_opclass_family(opclass);
615 typentry->hash_opintype = get_opclass_input_type(opclass);
616 }
617 else
618 {
619 typentry->hash_opf = typentry->hash_opintype = InvalidOid;
620 }
621
622 /*
623 * Reset information derived from hash opclass. We do *not* reset the
624 * eq_opr; if we already found one from the btree opclass, that
625 * decision is still good.
626 */
627 typentry->flags &= ~(TCFLAGS_CHECKED_HASH_PROC |
630 }
631
632 /*
633 * Look for requested operators and functions, if we haven't already.
634 */
635 if ((flags & (TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO)) &&
636 !(typentry->flags & TCFLAGS_CHECKED_EQ_OPR))
637 {
638 Oid eq_opr = InvalidOid;
639
640 if (typentry->btree_opf != InvalidOid)
641 eq_opr = get_opfamily_member(typentry->btree_opf,
642 typentry->btree_opintype,
643 typentry->btree_opintype,
645 if (eq_opr == InvalidOid &&
646 typentry->hash_opf != InvalidOid)
647 eq_opr = get_opfamily_member(typentry->hash_opf,
648 typentry->hash_opintype,
649 typentry->hash_opintype,
651
652 /*
653 * If the proposed equality operator is array_eq or record_eq, check
654 * to see if the element type or column types support equality. If
655 * not, array_eq or record_eq would fail at runtime, so we don't want
656 * to report that the type has equality. (We can omit similar
657 * checking for ranges and multiranges because ranges can't be created
658 * in the first place unless their subtypes support equality.)
659 */
660 if (eq_opr == ARRAY_EQ_OP &&
662 eq_opr = InvalidOid;
663 else if (eq_opr == RECORD_EQ_OP &&
665 eq_opr = InvalidOid;
666
667 /* Force update of eq_opr_finfo only if we're changing state */
668 if (typentry->eq_opr != eq_opr)
669 typentry->eq_opr_finfo.fn_oid = InvalidOid;
670
671 typentry->eq_opr = eq_opr;
672
673 /*
674 * Reset info about hash functions whenever we pick up new info about
675 * equality operator. This is so we can ensure that the hash
676 * functions match the operator.
677 */
678 typentry->flags &= ~(TCFLAGS_CHECKED_HASH_PROC |
680 typentry->flags |= TCFLAGS_CHECKED_EQ_OPR;
681 }
682 if ((flags & TYPECACHE_LT_OPR) &&
683 !(typentry->flags & TCFLAGS_CHECKED_LT_OPR))
684 {
685 Oid lt_opr = InvalidOid;
686
687 if (typentry->btree_opf != InvalidOid)
688 lt_opr = get_opfamily_member(typentry->btree_opf,
689 typentry->btree_opintype,
690 typentry->btree_opintype,
692
693 /*
694 * As above, make sure array_cmp or record_cmp will succeed; but again
695 * we need no special check for ranges or multiranges.
696 */
697 if (lt_opr == ARRAY_LT_OP &&
698 !array_element_has_compare(typentry))
699 lt_opr = InvalidOid;
700 else if (lt_opr == RECORD_LT_OP &&
702 lt_opr = InvalidOid;
703
704 typentry->lt_opr = lt_opr;
705 typentry->flags |= TCFLAGS_CHECKED_LT_OPR;
706 }
707 if ((flags & TYPECACHE_GT_OPR) &&
708 !(typentry->flags & TCFLAGS_CHECKED_GT_OPR))
709 {
710 Oid gt_opr = InvalidOid;
711
712 if (typentry->btree_opf != InvalidOid)
713 gt_opr = get_opfamily_member(typentry->btree_opf,
714 typentry->btree_opintype,
715 typentry->btree_opintype,
717
718 /*
719 * As above, make sure array_cmp or record_cmp will succeed; but again
720 * we need no special check for ranges or multiranges.
721 */
722 if (gt_opr == ARRAY_GT_OP &&
723 !array_element_has_compare(typentry))
724 gt_opr = InvalidOid;
725 else if (gt_opr == RECORD_GT_OP &&
727 gt_opr = InvalidOid;
728
729 typentry->gt_opr = gt_opr;
730 typentry->flags |= TCFLAGS_CHECKED_GT_OPR;
731 }
733 !(typentry->flags & TCFLAGS_CHECKED_CMP_PROC))
734 {
735 Oid cmp_proc = InvalidOid;
736
737 if (typentry->btree_opf != InvalidOid)
738 cmp_proc = get_opfamily_proc(typentry->btree_opf,
739 typentry->btree_opintype,
740 typentry->btree_opintype,
742
743 /*
744 * As above, make sure array_cmp or record_cmp will succeed; but again
745 * we need no special check for ranges or multiranges.
746 */
747 if (cmp_proc == F_BTARRAYCMP &&
748 !array_element_has_compare(typentry))
749 cmp_proc = InvalidOid;
750 else if (cmp_proc == F_BTRECORDCMP &&
752 cmp_proc = InvalidOid;
753
754 /* Force update of cmp_proc_finfo only if we're changing state */
755 if (typentry->cmp_proc != cmp_proc)
756 typentry->cmp_proc_finfo.fn_oid = InvalidOid;
757
758 typentry->cmp_proc = cmp_proc;
759 typentry->flags |= TCFLAGS_CHECKED_CMP_PROC;
760 }
762 !(typentry->flags & TCFLAGS_CHECKED_HASH_PROC))
763 {
764 Oid hash_proc = InvalidOid;
765
766 /*
767 * We insist that the eq_opr, if one has been determined, match the
768 * hash opclass; else report there is no hash function.
769 */
770 if (typentry->hash_opf != InvalidOid &&
771 (!OidIsValid(typentry->eq_opr) ||
772 typentry->eq_opr == get_opfamily_member(typentry->hash_opf,
773 typentry->hash_opintype,
774 typentry->hash_opintype,
776 hash_proc = get_opfamily_proc(typentry->hash_opf,
777 typentry->hash_opintype,
778 typentry->hash_opintype,
780
781 /*
782 * As above, make sure hash_array, hash_record, or hash_range will
783 * succeed.
784 */
785 if (hash_proc == F_HASH_ARRAY &&
786 !array_element_has_hashing(typentry))
787 hash_proc = InvalidOid;
788 else if (hash_proc == F_HASH_RECORD &&
790 hash_proc = InvalidOid;
791 else if (hash_proc == F_HASH_RANGE &&
792 !range_element_has_hashing(typentry))
793 hash_proc = InvalidOid;
794
795 /*
796 * Likewise for hash_multirange.
797 */
798 if (hash_proc == F_HASH_MULTIRANGE &&
800 hash_proc = InvalidOid;
801
802 /* Force update of hash_proc_finfo only if we're changing state */
803 if (typentry->hash_proc != hash_proc)
805
806 typentry->hash_proc = hash_proc;
807 typentry->flags |= TCFLAGS_CHECKED_HASH_PROC;
808 }
809 if ((flags & (TYPECACHE_HASH_EXTENDED_PROC |
812 {
813 Oid hash_extended_proc = InvalidOid;
814
815 /*
816 * We insist that the eq_opr, if one has been determined, match the
817 * hash opclass; else report there is no hash function.
818 */
819 if (typentry->hash_opf != InvalidOid &&
820 (!OidIsValid(typentry->eq_opr) ||
821 typentry->eq_opr == get_opfamily_member(typentry->hash_opf,
822 typentry->hash_opintype,
823 typentry->hash_opintype,
825 hash_extended_proc = get_opfamily_proc(typentry->hash_opf,
826 typentry->hash_opintype,
827 typentry->hash_opintype,
829
830 /*
831 * As above, make sure hash_array_extended, hash_record_extended, or
832 * hash_range_extended will succeed.
833 */
834 if (hash_extended_proc == F_HASH_ARRAY_EXTENDED &&
836 hash_extended_proc = InvalidOid;
837 else if (hash_extended_proc == F_HASH_RECORD_EXTENDED &&
839 hash_extended_proc = InvalidOid;
840 else if (hash_extended_proc == F_HASH_RANGE_EXTENDED &&
842 hash_extended_proc = InvalidOid;
843
844 /*
845 * Likewise for hash_multirange_extended.
846 */
847 if (hash_extended_proc == F_HASH_MULTIRANGE_EXTENDED &&
849 hash_extended_proc = InvalidOid;
850
851 /* Force update of proc finfo only if we're changing state */
852 if (typentry->hash_extended_proc != hash_extended_proc)
854
855 typentry->hash_extended_proc = hash_extended_proc;
857 }
858
859 /*
860 * Set up fmgr lookup info as requested
861 *
862 * Note: we tell fmgr the finfo structures live in CacheMemoryContext,
863 * which is not quite right (they're really in the hash table's private
864 * memory context) but this will do for our purposes.
865 *
866 * Note: the code above avoids invalidating the finfo structs unless the
867 * referenced operator/function OID actually changes. This is to prevent
868 * unnecessary leakage of any subsidiary data attached to an finfo, since
869 * that would cause session-lifespan memory leaks.
870 */
871 if ((flags & TYPECACHE_EQ_OPR_FINFO) &&
872 typentry->eq_opr_finfo.fn_oid == InvalidOid &&
873 typentry->eq_opr != InvalidOid)
874 {
876
877 eq_opr_func = get_opcode(typentry->eq_opr);
878 if (eq_opr_func != InvalidOid)
881 }
882 if ((flags & TYPECACHE_CMP_PROC_FINFO) &&
883 typentry->cmp_proc_finfo.fn_oid == InvalidOid &&
884 typentry->cmp_proc != InvalidOid)
885 {
886 fmgr_info_cxt(typentry->cmp_proc, &typentry->cmp_proc_finfo,
888 }
889 if ((flags & TYPECACHE_HASH_PROC_FINFO) &&
890 typentry->hash_proc_finfo.fn_oid == InvalidOid &&
891 typentry->hash_proc != InvalidOid)
892 {
893 fmgr_info_cxt(typentry->hash_proc, &typentry->hash_proc_finfo,
895 }
898 typentry->hash_extended_proc != InvalidOid)
899 {
901 &typentry->hash_extended_proc_finfo,
903 }
904
905 /*
906 * If it's a composite type (row type), get tupdesc if requested
907 */
908 if ((flags & TYPECACHE_TUPDESC) &&
909 typentry->tupDesc == NULL &&
910 typentry->typtype == TYPTYPE_COMPOSITE)
911 {
912 load_typcache_tupdesc(typentry);
913 }
914
915 /*
916 * If requested, get information about a range type
917 *
918 * This includes making sure that the basic info about the range element
919 * type is up-to-date.
920 */
921 if ((flags & TYPECACHE_RANGE_INFO) &&
922 typentry->typtype == TYPTYPE_RANGE)
923 {
924 if (typentry->rngelemtype == NULL)
925 load_rangetype_info(typentry);
926 else if (!(typentry->rngelemtype->flags & TCFLAGS_HAVE_PG_TYPE_DATA))
927 (void) lookup_type_cache(typentry->rngelemtype->type_id, 0);
928 }
929
930 /*
931 * If requested, get information about a multirange type
932 */
933 if ((flags & TYPECACHE_MULTIRANGE_INFO) &&
934 typentry->rngtype == NULL &&
935 typentry->typtype == TYPTYPE_MULTIRANGE)
936 {
937 load_multirangetype_info(typentry);
938 }
939
940 /*
941 * If requested, get information about a domain type
942 */
943 if ((flags & TYPECACHE_DOMAIN_BASE_INFO) &&
944 typentry->domainBaseType == InvalidOid &&
945 typentry->typtype == TYPTYPE_DOMAIN)
946 {
947 typentry->domainBaseTypmod = -1;
948 typentry->domainBaseType =
949 getBaseTypeAndTypmod(type_id, &typentry->domainBaseTypmod);
950 }
951 if ((flags & TYPECACHE_DOMAIN_CONSTR_INFO) &&
952 (typentry->flags & TCFLAGS_CHECKED_DOMAIN_CONSTRAINTS) == 0 &&
953 typentry->typtype == TYPTYPE_DOMAIN)
954 {
955 load_domaintype_info(typentry);
956 }
957
958 INJECTION_POINT("typecache-before-rel-type-cache-insert", NULL);
959
962
964
965 return typentry;
966}
#define NameStr(name)
Definition c.h:765
#define MemSet(start, val, len)
Definition c.h:1023
#define OidIsValid(objectId)
Definition c.h:788
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
Definition dynahash.c:908
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition fmgr.c:138
#define HASHSTANDARD_PROC
Definition hash.h:355
#define HASHEXTENDED_PROC
Definition hash.h:356
#define HASH_BLOBS
Definition hsearch.h:97
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
Definition indexcmds.c:2368
#define INJECTION_POINT(name, arg)
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1816
void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg)
Definition inval.c:1858
Oid get_opclass_input_type(Oid opclass)
Definition lsyscache.c:1314
Oid get_opclass_family(Oid opclass)
Definition lsyscache.c:1292
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition lsyscache.c:872
RegProcedure get_opcode(Oid opno)
Definition lsyscache.c:1435
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition lsyscache.c:168
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition lsyscache.c:2690
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1632
#define BTORDER_PROC
Definition nbtree.h:717
FormData_pg_type * Form_pg_type
Definition pg_type.h:261
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
uint64_t Datum
Definition postgres.h:70
#define InvalidOid
unsigned int Oid
#define BTGreaterStrategyNumber
Definition stratnum.h:33
#define HTEqualStrategyNumber
Definition stratnum.h:41
#define BTLessStrategyNumber
Definition stratnum.h:29
#define BTEqualStrategyNumber
Definition stratnum.h:31
Oid fn_oid
Definition fmgr.h:59
uint32 type_id_hash
Definition typcache.h:36
FmgrInfo hash_proc_finfo
Definition typcache.h:78
Oid hash_extended_proc
Definition typcache.h:67
FmgrInfo cmp_proc_finfo
Definition typcache.h:77
struct TypeCacheEntry * rngelemtype
Definition typcache.h:99
FmgrInfo hash_extended_proc_finfo
Definition typcache.h:79
struct TypeCacheEntry * rngtype
Definition typcache.h:109
FmgrInfo eq_opr_finfo
Definition typcache.h:76
Oid btree_opintype
Definition typcache.h:59
struct TypeCacheEntry * nextDomain
Definition typcache.h:134
Oid hash_opintype
Definition typcache.h:61
char typstorage
Definition typcache.h:42
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220
#define TCFLAGS_CHECKED_BTREE_OPCLASS
Definition typcache.c:100
#define TCFLAGS_CHECKED_HASH_OPCLASS
Definition typcache.c:101
static bool range_element_has_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1717
static void insert_rel_type_cache_if_needed(TypeCacheEntry *typentry)
Definition typcache.c:3077
static void TypeCacheOpcCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition typcache.c:2575
static bool record_fields_have_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1596
static HTAB * RelIdToTypeIdCacheHash
Definition typcache.c:87
static bool record_fields_have_extended_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1604
static int in_progress_list_maxlen
Definition typcache.c:228
static Oid * in_progress_list
Definition typcache.c:226
#define TCFLAGS_CHECKED_GT_OPR
Definition typcache.c:104
static bool multirange_element_has_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1757
static bool record_fields_have_equality(TypeCacheEntry *typentry)
Definition typcache.c:1580
#define TCFLAGS_CHECKED_LT_OPR
Definition typcache.c:103
#define TCFLAGS_CHECKED_HASH_PROC
Definition typcache.c:106
static bool array_element_has_extended_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1542
static bool array_element_has_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1534
static void load_multirangetype_info(TypeCacheEntry *typentry)
Definition typcache.c:1064
static uint32 type_cache_syshash(const void *key, Size keysize)
Definition typcache.c:362
#define TCFLAGS_CHECKED_CMP_PROC
Definition typcache.c:105
static bool multirange_element_has_extended_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1765
static int in_progress_list_len
Definition typcache.c:227
static bool array_element_has_equality(TypeCacheEntry *typentry)
Definition typcache.c:1518
static void load_rangetype_info(TypeCacheEntry *typentry)
Definition typcache.c:1006
static bool range_element_has_extended_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1725
static TypeCacheEntry * firstDomainTypeEntry
Definition typcache.c:96
#define TCFLAGS_CHECKED_HASH_EXTENDED_PROC
Definition typcache.c:107
static void load_domaintype_info(TypeCacheEntry *typentry)
Definition typcache.c:1086
static void TypeCacheRelCallback(Datum arg, Oid relid)
Definition typcache.c:2422
static void TypeCacheTypCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition typcache.c:2518
static void TypeCacheConstrCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition typcache.c:2613
static bool array_element_has_compare(TypeCacheEntry *typentry)
Definition typcache.c:1526
#define TCFLAGS_HAVE_PG_TYPE_DATA
Definition typcache.c:99
#define TCFLAGS_CHECKED_DOMAIN_CONSTRAINTS
Definition typcache.c:118
static HTAB * TypeCacheHash
Definition typcache.c:79
static bool record_fields_have_compare(TypeCacheEntry *typentry)
Definition typcache.c:1588
#define TCFLAGS_CHECKED_EQ_OPR
Definition typcache.c:102
static void load_typcache_tupdesc(TypeCacheEntry *typentry)
Definition typcache.c:972
#define TYPECACHE_HASH_PROC_FINFO
Definition typcache.h:145
#define TYPECACHE_EQ_OPR
Definition typcache.h:138
#define TYPECACHE_HASH_OPFAMILY
Definition typcache.h:148
#define TYPECACHE_MULTIRANGE_INFO
Definition typcache.h:154
#define TYPECACHE_EQ_OPR_FINFO
Definition typcache.h:143
#define TYPECACHE_HASH_EXTENDED_PROC
Definition typcache.h:152
#define TYPECACHE_BTREE_OPFAMILY
Definition typcache.h:147
#define TYPECACHE_RANGE_INFO
Definition typcache.h:149
#define TYPECACHE_GT_OPR
Definition typcache.h:140
#define TYPECACHE_CMP_PROC
Definition typcache.h:141
#define TYPECACHE_LT_OPR
Definition typcache.h:139
#define TYPECACHE_HASH_EXTENDED_PROC_FINFO
Definition typcache.h:153
#define TYPECACHE_CMP_PROC_FINFO
Definition typcache.h:144
#define TYPECACHE_HASH_PROC
Definition typcache.h:142

References array_element_has_compare(), array_element_has_equality(), array_element_has_extended_hashing(), array_element_has_hashing(), Assert, BTEqualStrategyNumber, BTGreaterStrategyNumber, BTLessStrategyNumber, BTORDER_PROC, TypeCacheEntry::btree_opf, TypeCacheEntry::btree_opintype, CacheMemoryContext, CacheRegisterRelcacheCallback(), CacheRegisterSyscacheCallback(), TypeCacheEntry::cmp_proc, TypeCacheEntry::cmp_proc_finfo, CreateCacheMemoryContext(), ctl, TypeCacheEntry::domainBaseType, TypeCacheEntry::domainBaseTypmod, TypeCacheEntry::eq_opr, TypeCacheEntry::eq_opr_finfo, ereport, errcode(), errmsg(), ERROR, fb(), firstDomainTypeEntry, TypeCacheEntry::flags, fmgr_info_cxt(), FmgrInfo::fn_oid, get_hash_value(), get_opclass_family(), get_opclass_input_type(), get_opcode(), get_opfamily_member(), get_opfamily_proc(), getBaseTypeAndTypmod(), GetDefaultOpClass(), GETSTRUCT(), TypeCacheEntry::gt_opr, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, TypeCacheEntry::hash_extended_proc, TypeCacheEntry::hash_extended_proc_finfo, HASH_FIND, HASH_FUNCTION, TypeCacheEntry::hash_opf, TypeCacheEntry::hash_opintype, TypeCacheEntry::hash_proc, TypeCacheEntry::hash_proc_finfo, hash_search(), HASHEXTENDED_PROC, HASHSTANDARD_PROC, HeapTupleIsValid, HTEqualStrategyNumber, in_progress_list, in_progress_list_len, in_progress_list_maxlen, INJECTION_POINT, insert_rel_type_cache_if_needed(), InvalidOid, HASHCTL::keysize, load_domaintype_info(), load_multirangetype_info(), load_rangetype_info(), load_typcache_tupdesc(), lookup_type_cache(), TypeCacheEntry::lt_opr, MemoryContextAlloc(), MemSet, multirange_element_has_extended_hashing(), multirange_element_has_hashing(), NameStr, TypeCacheEntry::nextDomain, ObjectIdGetDatum(), OidIsValid, range_element_has_extended_hashing(), range_element_has_hashing(), record_fields_have_compare(), record_fields_have_equality(), record_fields_have_extended_hashing(), record_fields_have_hashing(), ReleaseSysCache(), RelIdToTypeIdCacheHash, repalloc(), TypeCacheEntry::rngelemtype, TypeCacheEntry::rngtype, SearchSysCache1(), TCFLAGS_CHECKED_BTREE_OPCLASS, TCFLAGS_CHECKED_CMP_PROC, TCFLAGS_CHECKED_DOMAIN_CONSTRAINTS, TCFLAGS_CHECKED_EQ_OPR, TCFLAGS_CHECKED_GT_OPR, TCFLAGS_CHECKED_HASH_EXTENDED_PROC, TCFLAGS_CHECKED_HASH_OPCLASS, TCFLAGS_CHECKED_HASH_PROC, TCFLAGS_CHECKED_LT_OPR, TCFLAGS_HAVE_PG_TYPE_DATA, TypeCacheEntry::tupDesc, TypeCacheEntry::typalign, TypeCacheEntry::typarray, TypeCacheEntry::typbyval, TypeCacheEntry::typcollation, type_cache_syshash(), TypeCacheEntry::type_id, TypeCacheEntry::type_id_hash, TYPECACHE_BTREE_OPFAMILY, TYPECACHE_CMP_PROC, TYPECACHE_CMP_PROC_FINFO, TYPECACHE_DOMAIN_BASE_INFO, TYPECACHE_DOMAIN_CONSTR_INFO, TYPECACHE_EQ_OPR, TYPECACHE_EQ_OPR_FINFO, TYPECACHE_GT_OPR, TYPECACHE_HASH_EXTENDED_PROC, TYPECACHE_HASH_EXTENDED_PROC_FINFO, TYPECACHE_HASH_OPFAMILY, TYPECACHE_HASH_PROC, TYPECACHE_HASH_PROC_FINFO, TYPECACHE_LT_OPR, TYPECACHE_MULTIRANGE_INFO, TYPECACHE_RANGE_INFO, TYPECACHE_TUPDESC, TypeCacheConstrCallback(), TypeCacheHash, TypeCacheOpcCallback(), TypeCacheRelCallback(), TypeCacheTypCallback(), TypeCacheEntry::typelem, TypeCacheEntry::typlen, TypeCacheEntry::typrelid, TypeCacheEntry::typstorage, TypeCacheEntry::typsubscript, and TypeCacheEntry::typtype.

Referenced by analyzeCTE(), appendOrderBySuffix(), array_cmp(), array_contain_compare(), array_eq(), array_position_common(), array_positions(), array_replace_internal(), array_reverse(), array_sample(), array_shuffle(), array_sort_internal(), array_typanalyze(), assign_record_type_identifier(), brin_bloom_opcinfo(), brin_inclusion_opcinfo(), brin_minmax_multi_opcinfo(), brin_minmax_opcinfo(), build_datatype(), build_mss(), cache_array_element_properties(), cache_multirange_element_properties(), cache_range_element_properties(), cache_record_field_properties(), calc_arraycontsel(), check_exclusion_or_unique_constraint(), check_memoizable(), contain_leaked_vars_walker(), create_grouping_expr_infos(), CreateStatistics(), dependency_degree(), domain_state_setup(), DomainHasConstraints(), enum_cmp_internal(), ExecInitExprRec(), find_simplified_clause(), foreign_expr_walker(), get_cached_rowtype(), get_multirange_io_data(), get_range_io_data(), get_rule_orderby(), get_sort_group_operators(), GinBufferInit(), hash_array(), hash_array_extended(), hash_multirange(), hash_multirange_extended(), hash_range(), hash_range_extended(), hash_record(), hash_record_extended(), init_grouping_targets(), InitDomainConstraintRef(), initGinState(), IsIndexUsableForReplicaIdentityFull(), load_multirangetype_info(), load_rangetype_info(), lookup_rowtype_tupdesc_domain(), lookup_rowtype_tupdesc_internal(), lookup_type_cache(), make_expanded_record_from_tupdesc(), make_expanded_record_from_typeid(), multirange_get_typcache(), multirange_minus_multi(), multirange_unnest(), ndistinct_for_combination(), op_hashjoinable(), op_mergejoinable(), paraminfo_get_equal_hashops(), PLy_input_setup_func(), PLy_output_setup_func(), range_fast_cmp(), range_get_typcache(), range_minus_multi(), record_cmp(), record_eq(), revalidate_rectypeid(), scalararraysel(), scalararraysel_containment(), show_sortorder_options(), statatt_get_elem_type(), statatt_get_type(), statext_mcv_serialize(), tuples_equal(), tuplesort_begin_index_gin(), and width_bucket_array().

◆ SharedRecordTypmodRegistryAttach()

void SharedRecordTypmodRegistryAttach ( SharedRecordTypmodRegistry registry)
extern

Definition at line 2298 of file typcache.c.

2299{
2303
2305
2306 /* We can't already be attached to a shared registry. */
2313
2314 /*
2315 * We can't already have typmods in our local cache, because they'd clash
2316 * with those imported by SharedRecordTypmodRegistryInit. This should be
2317 * a freshly started parallel worker. If we ever support worker
2318 * recycling, a worker would need to zap its local cache in between
2319 * servicing different queries, in order to be able to call this and
2320 * synchronize typmods with a new leader; but that's problematic because
2321 * we can't be very sure that record-typmod-related state hasn't escaped
2322 * to anywhere else in the process.
2323 */
2325
2327
2328 /* Attach to the two hash tables. */
2331 registry->record_table_handle,
2335 registry->typmod_table_handle,
2336 NULL);
2337
2339
2340 /*
2341 * Set up detach hook to run at worker exit. Currently this is the same
2342 * as the leader's detach hook, but in future they might need to be
2343 * different.
2344 */
2348
2349 /*
2350 * Set up the session state that will tell assign_record_type_typmod and
2351 * lookup_rowtype_tupdesc_internal about the shared registry.
2352 */
2356}
dshash_table * dshash_attach(dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg)
Definition dshash.c:272
void on_dsm_detach(dsm_segment *seg, on_dsm_detach_callback function, Datum arg)
Definition dsm.c:1132
#define IsParallelWorker()
Definition parallel.h:60
MemoryContext TopMemoryContext
Definition mcxt.c:166
static Datum PointerGetDatum(const void *X)
Definition postgres.h:352
Session * CurrentSession
Definition session.c:48
dsm_segment * segment
Definition session.h:27
dshash_table * shared_record_table
Definition session.h:32
struct SharedRecordTypmodRegistry * shared_typmod_registry
Definition session.h:31
dsa_area * area
Definition session.h:28
dshash_table * shared_typmod_table
Definition session.h:33
static const dshash_parameters srtr_typmod_table_params
Definition typcache.c:285
static void shared_record_typmod_registry_detach(dsm_segment *segment, Datum datum)
Definition typcache.c:3057
static const dshash_parameters srtr_record_table_params
Definition typcache.c:275

References Session::area, Assert, CurrentSession, dshash_attach(), fb(), IsParallelWorker, MemoryContextSwitchTo(), NextRecordTypmod, on_dsm_detach(), PointerGetDatum(), Session::segment, Session::shared_record_table, shared_record_typmod_registry_detach(), Session::shared_typmod_registry, Session::shared_typmod_table, srtr_record_table_params, srtr_typmod_table_params, and TopMemoryContext.

Referenced by AttachSession().

◆ SharedRecordTypmodRegistryEstimate()

size_t SharedRecordTypmodRegistryEstimate ( void  )
extern

Definition at line 2177 of file typcache.c.

2178{
2179 return sizeof(SharedRecordTypmodRegistry);
2180}

Referenced by GetSessionDsmHandle().

◆ SharedRecordTypmodRegistryInit()

void SharedRecordTypmodRegistryInit ( SharedRecordTypmodRegistry registry,
dsm_segment segment,
dsa_area area 
)
extern

Definition at line 2199 of file typcache.c.

2202{
2206 int32 typmod;
2207
2209
2210 /* We can't already be attached to a shared registry. */
2214
2216
2217 /* Create the hash table of tuple descriptors indexed by themselves. */
2219
2220 /* Create the hash table of tuple descriptors indexed by typmod. */
2222
2224
2225 /* Initialize the SharedRecordTypmodRegistry. */
2226 registry->record_table_handle = dshash_get_hash_table_handle(record_table);
2227 registry->typmod_table_handle = dshash_get_hash_table_handle(typmod_table);
2229
2230 /*
2231 * Copy all entries from this backend's private registry into the shared
2232 * registry.
2233 */
2234 for (typmod = 0; typmod < NextRecordTypmod; ++typmod)
2235 {
2240 TupleDesc tupdesc;
2241 bool found;
2242
2243 tupdesc = RecordCacheArray[typmod].tupdesc;
2244 if (tupdesc == NULL)
2245 continue;
2246
2247 /* Copy the TupleDesc into shared memory. */
2248 shared_dp = share_tupledesc(area, tupdesc, typmod);
2249
2250 /* Insert into the typmod table. */
2252 &tupdesc->tdtypmod,
2253 &found);
2254 if (found)
2255 elog(ERROR, "cannot create duplicate shared record typmod");
2256 typmod_table_entry->typmod = tupdesc->tdtypmod;
2257 typmod_table_entry->shared_tupdesc = shared_dp;
2259
2260 /* Insert into the record table. */
2261 record_table_key.shared = false;
2262 record_table_key.u.local_tupdesc = tupdesc;
2265 &found);
2266 if (!found)
2267 {
2268 record_table_entry->key.shared = true;
2269 record_table_entry->key.u.shared_tupdesc = shared_dp;
2270 }
2272 }
2273
2274 /*
2275 * Set up the global state that will tell assign_record_type_typmod and
2276 * lookup_rowtype_tupdesc_internal about the shared registry.
2277 */
2281
2282 /*
2283 * We install a detach hook in the leader, but only to handle cleanup on
2284 * failure during GetSessionDsmHandle(). Once GetSessionDsmHandle() pins
2285 * the memory, the leader process will use a shared registry until it
2286 * exits.
2287 */
2289}
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:219
int32_t int32
Definition c.h:542
uint64 dsa_pointer
Definition dsa.h:62
void dshash_release_lock(dshash_table *hash_table, void *entry)
Definition dshash.c:560
dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table)
Definition dshash.c:369
void * dshash_find_or_insert(dshash_table *hash_table, const void *key, bool *found)
Definition dshash.c:435
dshash_table * dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
Definition dshash.c:208
static dsa_pointer share_tupledesc(dsa_area *area, TupleDesc tupdesc, uint32 typmod)
Definition typcache.c:2924

References Assert, CurrentSession, dshash_create(), dshash_find_or_insert(), dshash_get_hash_table_handle(), dshash_release_lock(), elog, ERROR, fb(), IsParallelWorker, MemoryContextSwitchTo(), NextRecordTypmod, on_dsm_detach(), pg_atomic_init_u32(), RecordCacheArray, share_tupledesc(), Session::shared_record_table, shared_record_typmod_registry_detach(), Session::shared_typmod_registry, Session::shared_typmod_table, srtr_record_table_params, srtr_typmod_table_params, TupleDescData::tdtypmod, TopMemoryContext, and RecordCacheArrayEntry::tupdesc.

Referenced by GetSessionDsmHandle().

◆ UpdateDomainConstraintRef()

void UpdateDomainConstraintRef ( DomainConstraintRef ref)
extern

Definition at line 1442 of file typcache.c.

1443{
1444 TypeCacheEntry *typentry = ref->tcache;
1445
1446 /* Make sure typcache entry's data is up to date */
1447 if ((typentry->flags & TCFLAGS_CHECKED_DOMAIN_CONSTRAINTS) == 0 &&
1448 typentry->typtype == TYPTYPE_DOMAIN)
1449 load_domaintype_info(typentry);
1450
1451 /* Transfer to ref object if there's new info, adjusting refcounts */
1452 if (ref->dcc != typentry->domainData)
1453 {
1454 /* Paranoia --- be sure link is nulled before trying to release */
1455 DomainConstraintCache *dcc = ref->dcc;
1456
1457 if (dcc)
1458 {
1459 /*
1460 * Note: we just leak the previous list of executable domain
1461 * constraints. Alternatively, we could keep those in a child
1462 * context of ref->refctx and free that context at this point.
1463 * However, in practice this code path will be taken so seldom
1464 * that the extra bookkeeping for a child context doesn't seem
1465 * worthwhile; we'll just allow a leak for the lifespan of refctx.
1466 */
1467 ref->constraints = NIL;
1468 ref->dcc = NULL;
1469 decr_dcc_refcount(dcc);
1470 }
1471 dcc = typentry->domainData;
1472 if (dcc)
1473 {
1474 ref->dcc = dcc;
1475 dcc->dccRefCount++;
1476 if (ref->need_exprstate)
1477 ref->constraints = prep_domain_constraints(dcc->constraints,
1478 ref->refctx);
1479 else
1480 ref->constraints = dcc->constraints;
1481 }
1482 }
1483}
static void decr_dcc_refcount(DomainConstraintCache *dcc)
Definition typcache.c:1334

References DomainConstraintCache::constraints, DomainConstraintCache::dccRefCount, decr_dcc_refcount(), TypeCacheEntry::domainData, fb(), TypeCacheEntry::flags, load_domaintype_info(), NIL, prep_domain_constraints(), TCFLAGS_CHECKED_DOMAIN_CONSTRAINTS, and TypeCacheEntry::typtype.

Referenced by domain_check_input().