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, bool *has_volatile)
 
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 2161 of file typcache.c.

2162{
2163 if (type_id != RECORDOID)
2164 {
2165 /*
2166 * It's a named composite type, so use the regular typcache.
2167 */
2168 TypeCacheEntry *typentry;
2169
2170 typentry = lookup_type_cache(type_id, TYPECACHE_TUPDESC);
2171 if (typentry->tupDesc == NULL)
2172 ereport(ERROR,
2174 errmsg("type %s is not composite",
2175 format_type_be(type_id))));
2176 Assert(typentry->tupDesc_identifier != 0);
2177 return typentry->tupDesc_identifier;
2178 }
2179 else
2180 {
2181 /*
2182 * It's a transient record type, so look in our record-type table.
2183 */
2184 if (typmod >= 0 && typmod < RecordCacheArrayLen &&
2185 RecordCacheArray[typmod].tupdesc != NULL)
2186 {
2187 Assert(RecordCacheArray[typmod].id != 0);
2188 return RecordCacheArray[typmod].id;
2189 }
2190
2191 /* For anonymous or unrecognized record type, generate a new ID */
2192 return ++tupledesc_id_counter;
2193 }
2194}
#define Assert(condition)
Definition c.h:943
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
char * format_type_be(Oid type_oid)
static char * errmsg
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 2069 of file typcache.c.

2070{
2073 bool found;
2075
2076 Assert(tupDesc->tdtypeid == RECORDOID);
2077
2078 if (RecordCacheHash == NULL)
2079 {
2080 /* First time through: initialize the hash table */
2081 HASHCTL ctl;
2082
2083 ctl.keysize = sizeof(TupleDesc); /* just the pointer */
2084 ctl.entrysize = sizeof(RecordCacheEntry);
2087 RecordCacheHash = hash_create("Record information cache", 64,
2088 &ctl,
2090
2091 /* Also make sure CacheMemoryContext exists */
2092 if (!CacheMemoryContext)
2094 }
2095
2096 /*
2097 * Find a hashtable entry for this tuple descriptor. We don't use
2098 * HASH_ENTER yet, because if it's missing, we need to make sure that all
2099 * the allocations succeed before we create the new entry.
2100 */
2102 &tupDesc,
2103 HASH_FIND, &found);
2104 if (found && recentry->tupdesc != NULL)
2105 {
2106 tupDesc->tdtypmod = recentry->tupdesc->tdtypmod;
2107 return;
2108 }
2109
2110 /* Not present, so need to manufacture an entry */
2112
2113 /* Look in the SharedRecordTypmodRegistry, if attached */
2115 if (entDesc == NULL)
2116 {
2117 /*
2118 * Make sure we have room before we CreateTupleDescCopy() or advance
2119 * NextRecordTypmod.
2120 */
2122
2123 /* Reference-counted local cache only. */
2124 entDesc = CreateTupleDescCopy(tupDesc);
2125 entDesc->tdrefcount = 1;
2126 entDesc->tdtypmod = NextRecordTypmod++;
2127 }
2128 else
2129 {
2131 }
2132
2134
2135 /* Assign a unique tupdesc identifier, too. */
2137
2138 /* Fully initialized; create the hash table entry */
2140 &tupDesc,
2141 HASH_ENTER, NULL);
2142 recentry->tupdesc = entDesc;
2143
2144 /* Update the caller's tuple descriptor. */
2145 tupDesc->tdtypmod = entDesc->tdtypmod;
2146
2148}
void CreateCacheMemoryContext(void)
Definition catcache.c:726
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:889
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition dynahash.c:360
@ HASH_FIND
Definition hsearch.h:108
@ HASH_ENTER
Definition hsearch.h:109
#define HASH_ELEM
Definition hsearch.h:90
#define HASH_COMPARE
Definition hsearch.h:94
#define HASH_FUNCTION
Definition hsearch.h:93
MemoryContext CacheMemoryContext
Definition mcxt.c:170
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
tree ctl
Definition radixtree.h:1838
Size keysize
Definition hsearch.h:69
int32 tdtypmod
Definition tupdesc.h:152
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
Definition tupdesc.c:242
struct TupleDescData * TupleDesc
Definition tupdesc.h:163
static TupleDesc find_or_make_matching_shared_tupledesc(TupleDesc tupdesc)
Definition typcache.c:2970
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:2053
static void ensure_record_cache_typmod_slot_exists(int32 typmod)
Definition typcache.c:1826
static uint32 record_type_typmod_hash(const void *data, size_t size)
Definition typcache.c:2042

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 3225 of file typcache.c.

3226{
3228}
static void finalize_in_progress_typentries(void)
Definition typcache.c:3200

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 2691 of file typcache.c.

2692{
2694 EnumItem *item1;
2695 EnumItem *item2;
2696
2697 /*
2698 * Equal OIDs are certainly equal --- this case was probably handled by
2699 * our caller, but we may as well check.
2700 */
2701 if (arg1 == arg2)
2702 return 0;
2703
2704 /* Load up the cache if first time through */
2705 if (tcache->enumData == NULL)
2706 load_enum_cache_data(tcache);
2707 enumdata = tcache->enumData;
2708
2709 /*
2710 * If both OIDs are known-sorted, we can just compare them directly.
2711 */
2714 {
2715 if (arg1 < arg2)
2716 return -1;
2717 else
2718 return 1;
2719 }
2720
2721 /*
2722 * Slow path: we have to identify their actual sort-order positions.
2723 */
2726
2727 if (item1 == NULL || item2 == NULL)
2728 {
2729 /*
2730 * We couldn't find one or both values. That means the enum has
2731 * changed under us, so re-initialize the cache and try again. We
2732 * don't bother retrying the known-sorted case in this path.
2733 */
2734 load_enum_cache_data(tcache);
2735 enumdata = tcache->enumData;
2736
2739
2740 /*
2741 * If we still can't find the values, complain: we must have corrupt
2742 * data.
2743 */
2744 if (item1 == NULL)
2745 elog(ERROR, "enum value %u not found in cache for enum %s",
2746 arg1, format_type_be(tcache->type_id));
2747 if (item2 == NULL)
2748 elog(ERROR, "enum value %u not found in cache for enum %s",
2749 arg2, format_type_be(tcache->type_id));
2750 }
2751
2752 if (item1->sort_order < item2->sort_order)
2753 return -1;
2754 else if (item1->sort_order > item2->sort_order)
2755 return 1;
2756 else
2757 return 0;
2758}
#define elog(elevel,...)
Definition elog.h:228
struct TypeCacheEnumData * enumData
Definition typcache.h:131
static void load_enum_cache_data(TypeCacheEntry *tcache)
Definition typcache.c:2764
static EnumItem * find_enumitem(TypeCacheEnumData *enumdata, Oid arg)
Definition typcache.c:2919
static bool enum_known_sorted(TypeCacheEnumData *enumdata, Oid arg)
Definition typcache.c:2662

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,
bool has_volatile 
)
extern

Definition at line 1497 of file typcache.c.

1498{
1499 TypeCacheEntry *typentry;
1500
1501 /*
1502 * Note: a side effect is to cause the typcache's domain data to become
1503 * valid. This is fine since we'll likely need it soon if there is any.
1504 */
1506
1507 if (typentry->domainData == NULL)
1508 return false;
1509
1510 if (has_volatile)
1511 {
1512 *has_volatile = false;
1513
1515 typentry->domainData->constraints)
1516 {
1517 if (constrstate->constrainttype == DOM_CONSTRAINT_CHECK &&
1519 {
1520 *has_volatile = true;
1521 break;
1522 }
1523 }
1524 }
1525
1526 return true;
1527}
bool contain_volatile_functions(Node *clause)
Definition clauses.c:551
@ DOM_CONSTRAINT_CHECK
Definition execnodes.h:1087
#define foreach_node(type, var, lst)
Definition pg_list.h:528
Definition nodes.h:133
DomainConstraintCache * domainData
Definition typcache.h:122
#define TYPECACHE_DOMAIN_CONSTR_INFO
Definition typcache.h:151

References DomainConstraintCache::constraints, contain_volatile_functions(), DOM_CONSTRAINT_CHECK, TypeCacheEntry::domainData, fb(), foreach_node, lookup_type_cache(), and TYPECACHE_DOMAIN_CONSTR_INFO.

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

◆ InitDomainConstraintRef()

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

Definition at line 1406 of file typcache.c.

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

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 1983 of file typcache.c.

1984{
1985 TupleDesc tmp;
1986
1987 tmp = lookup_rowtype_tupdesc_internal(type_id, typmod, false);
1988 return CreateTupleDescCopyConstr(tmp);
1989}
TupleDesc CreateTupleDescCopyConstr(TupleDesc tupdesc)
Definition tupdesc.c:336

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 2005 of file typcache.c.

2006{
2007 TupleDesc tupDesc;
2008
2009 if (type_id != RECORDOID)
2010 {
2011 /*
2012 * Check for domain or named composite type. We might as well load
2013 * whichever data is needed.
2014 */
2015 TypeCacheEntry *typentry;
2016
2017 typentry = lookup_type_cache(type_id,
2020 if (typentry->typtype == TYPTYPE_DOMAIN)
2022 typentry->domainBaseTypmod,
2023 noError);
2024 if (typentry->tupDesc == NULL && !noError)
2025 ereport(ERROR,
2027 errmsg("type %s is not composite",
2028 format_type_be(type_id))));
2029 tupDesc = typentry->tupDesc;
2030 }
2031 else
2032 tupDesc = lookup_rowtype_tupdesc_internal(type_id, typmod, noError);
2033 if (tupDesc != NULL)
2034 PinTupleDesc(tupDesc);
2035 return tupDesc;
2036}
int32 domainBaseTypmod
Definition typcache.h:116
TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod, bool noError)
Definition typcache.c:1966
#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 1966 of file typcache.c.

1967{
1968 TupleDesc tupDesc;
1969
1970 tupDesc = lookup_rowtype_tupdesc_internal(type_id, typmod, noError);
1971 if (tupDesc != NULL)
1972 PinTupleDesc(tupDesc);
1973 return tupDesc;
1974}

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 (in_progress_list == NULL)
396 {
397 /* First time through: initialize the hash table */
398 HASHCTL ctl;
399 int allocsize;
400
401 if (TypeCacheHash == NULL)
402 {
403 ctl.keysize = sizeof(Oid);
404 ctl.entrysize = sizeof(TypeCacheEntry);
405
406 /*
407 * TypeCacheEntry takes hash value from the system cache. For
408 * TypeCacheHash we use the same hash in order to speedup search
409 * by hash value. This is used by hash_seq_init_with_hash_value().
410 */
411 ctl.hash = type_cache_syshash;
412
413 TypeCacheHash = hash_create("Type information cache", 64,
415 }
416
418 {
419 ctl.keysize = sizeof(Oid);
420 ctl.entrysize = sizeof(RelIdToTypeIdCacheEntry);
421 RelIdToTypeIdCacheHash = hash_create("Map from relid to OID of cached composite type", 64,
423 }
424
425 /* Also make sure CacheMemoryContext exists */
428
429 /*
430 * Reserve enough in_progress_list slots for many cases. This is the
431 * last allocation on purpose, done after the two others.
432 */
433 allocsize = 4;
436 allocsize * sizeof(*in_progress_list));
437 in_progress_list_maxlen = allocsize;
438
439 /*
440 * Set up callbacks for SI invalidations. These steps are done last,
441 * once all the other initializations are done, and can fail only with
442 * a FATAL error.
443 */
448 }
449
451
452 /* Register to catch invalidation messages */
454 {
455 int allocsize;
456
457 allocsize = in_progress_list_maxlen * 2;
459 allocsize * sizeof(*in_progress_list));
460 in_progress_list_maxlen = allocsize;
461 }
464
465 /* Try to look up an existing entry */
467 &type_id,
468 HASH_FIND, NULL);
469 if (typentry == NULL)
470 {
471 /*
472 * If we didn't find one, we want to make one. But first look up the
473 * pg_type row, just to make sure we don't make a cache entry for an
474 * invalid type OID. If the type OID is not valid, present a
475 * user-facing error, since some code paths such as domain_in() allow
476 * this function to be reached with a user-supplied OID.
477 */
478 HeapTuple tp;
480
482 if (!HeapTupleIsValid(tp))
485 errmsg("type with OID %u does not exist", type_id)));
487 if (!typtup->typisdefined)
490 errmsg("type \"%s\" is only a shell",
491 NameStr(typtup->typname))));
492
493 /* Now make the typcache entry */
495 &type_id,
496 HASH_ENTER, &found);
497 Assert(!found); /* it wasn't there a moment ago */
498
499 MemSet(typentry, 0, sizeof(TypeCacheEntry));
500
501 /* These fields can never change, by definition */
502 typentry->type_id = type_id;
503 typentry->type_id_hash = get_hash_value(TypeCacheHash, &type_id);
504
505 /* Keep this part in sync with the code below */
506 typentry->typlen = typtup->typlen;
507 typentry->typbyval = typtup->typbyval;
508 typentry->typalign = typtup->typalign;
509 typentry->typstorage = typtup->typstorage;
510 typentry->typtype = typtup->typtype;
511 typentry->typrelid = typtup->typrelid;
512 typentry->typsubscript = typtup->typsubscript;
513 typentry->typelem = typtup->typelem;
514 typentry->typarray = typtup->typarray;
515 typentry->typcollation = typtup->typcollation;
516 typentry->flags |= TCFLAGS_HAVE_PG_TYPE_DATA;
517
518 /* If it's a domain, immediately thread it into the domain cache list */
519 if (typentry->typtype == TYPTYPE_DOMAIN)
520 {
522 firstDomainTypeEntry = typentry;
523 }
524
525 ReleaseSysCache(tp);
526 }
527 else if (!(typentry->flags & TCFLAGS_HAVE_PG_TYPE_DATA))
528 {
529 /*
530 * We have an entry, but its pg_type row got changed, so reload the
531 * data obtained directly from pg_type.
532 */
533 HeapTuple tp;
535
537 if (!HeapTupleIsValid(tp))
540 errmsg("type with OID %u does not exist", type_id)));
542 if (!typtup->typisdefined)
545 errmsg("type \"%s\" is only a shell",
546 NameStr(typtup->typname))));
547
548 /*
549 * Keep this part in sync with the code above. Many of these fields
550 * shouldn't ever change, particularly typtype, but copy 'em anyway.
551 */
552 typentry->typlen = typtup->typlen;
553 typentry->typbyval = typtup->typbyval;
554 typentry->typalign = typtup->typalign;
555 typentry->typstorage = typtup->typstorage;
556 typentry->typtype = typtup->typtype;
557 typentry->typrelid = typtup->typrelid;
558 typentry->typsubscript = typtup->typsubscript;
559 typentry->typelem = typtup->typelem;
560 typentry->typarray = typtup->typarray;
561 typentry->typcollation = typtup->typcollation;
562 typentry->flags |= TCFLAGS_HAVE_PG_TYPE_DATA;
563
564 ReleaseSysCache(tp);
565 }
566
567 /*
568 * Look up opclasses if we haven't already and any dependent info is
569 * requested.
570 */
576 {
577 Oid opclass;
578
579 opclass = GetDefaultOpClass(type_id, BTREE_AM_OID);
580 if (OidIsValid(opclass))
581 {
582 typentry->btree_opf = get_opclass_family(opclass);
583 typentry->btree_opintype = get_opclass_input_type(opclass);
584 }
585 else
586 {
587 typentry->btree_opf = typentry->btree_opintype = InvalidOid;
588 }
589
590 /*
591 * Reset information derived from btree opclass. Note in particular
592 * that we'll redetermine the eq_opr even if we previously found one;
593 * this matters in case a btree opclass has been added to a type that
594 * previously had only a hash opclass.
595 */
596 typentry->flags &= ~(TCFLAGS_CHECKED_EQ_OPR |
601 }
602
603 /*
604 * If we need to look up equality operator, and there's no btree opclass,
605 * force lookup of hash opclass.
606 */
607 if ((flags & (TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO)) &&
608 !(typentry->flags & TCFLAGS_CHECKED_EQ_OPR) &&
609 typentry->btree_opf == InvalidOid)
611
616 !(typentry->flags & TCFLAGS_CHECKED_HASH_OPCLASS))
617 {
618 Oid opclass;
619
620 opclass = GetDefaultOpClass(type_id, HASH_AM_OID);
621 if (OidIsValid(opclass))
622 {
623 typentry->hash_opf = get_opclass_family(opclass);
624 typentry->hash_opintype = get_opclass_input_type(opclass);
625 }
626 else
627 {
628 typentry->hash_opf = typentry->hash_opintype = InvalidOid;
629 }
630
631 /*
632 * Reset information derived from hash opclass. We do *not* reset the
633 * eq_opr; if we already found one from the btree opclass, that
634 * decision is still good.
635 */
636 typentry->flags &= ~(TCFLAGS_CHECKED_HASH_PROC |
639 }
640
641 /*
642 * Look for requested operators and functions, if we haven't already.
643 */
644 if ((flags & (TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO)) &&
645 !(typentry->flags & TCFLAGS_CHECKED_EQ_OPR))
646 {
647 Oid eq_opr = InvalidOid;
648
649 if (typentry->btree_opf != InvalidOid)
650 eq_opr = get_opfamily_member(typentry->btree_opf,
651 typentry->btree_opintype,
652 typentry->btree_opintype,
654 if (eq_opr == InvalidOid &&
655 typentry->hash_opf != InvalidOid)
656 eq_opr = get_opfamily_member(typentry->hash_opf,
657 typentry->hash_opintype,
658 typentry->hash_opintype,
660
661 /*
662 * If the proposed equality operator is array_eq or record_eq, check
663 * to see if the element type or column types support equality. If
664 * not, array_eq or record_eq would fail at runtime, so we don't want
665 * to report that the type has equality. (We can omit similar
666 * checking for ranges and multiranges because ranges can't be created
667 * in the first place unless their subtypes support equality.)
668 */
669 if (eq_opr == ARRAY_EQ_OP &&
671 eq_opr = InvalidOid;
672 else if (eq_opr == RECORD_EQ_OP &&
674 eq_opr = InvalidOid;
675
676 /* Force update of eq_opr_finfo only if we're changing state */
677 if (typentry->eq_opr != eq_opr)
678 typentry->eq_opr_finfo.fn_oid = InvalidOid;
679
680 typentry->eq_opr = eq_opr;
681
682 /*
683 * Reset info about hash functions whenever we pick up new info about
684 * equality operator. This is so we can ensure that the hash
685 * functions match the operator.
686 */
687 typentry->flags &= ~(TCFLAGS_CHECKED_HASH_PROC |
689 typentry->flags |= TCFLAGS_CHECKED_EQ_OPR;
690 }
691 if ((flags & TYPECACHE_LT_OPR) &&
692 !(typentry->flags & TCFLAGS_CHECKED_LT_OPR))
693 {
694 Oid lt_opr = InvalidOid;
695
696 if (typentry->btree_opf != InvalidOid)
697 lt_opr = get_opfamily_member(typentry->btree_opf,
698 typentry->btree_opintype,
699 typentry->btree_opintype,
701
702 /*
703 * As above, make sure array_cmp or record_cmp will succeed; but again
704 * we need no special check for ranges or multiranges.
705 */
706 if (lt_opr == ARRAY_LT_OP &&
707 !array_element_has_compare(typentry))
708 lt_opr = InvalidOid;
709 else if (lt_opr == RECORD_LT_OP &&
711 lt_opr = InvalidOid;
712
713 typentry->lt_opr = lt_opr;
714 typentry->flags |= TCFLAGS_CHECKED_LT_OPR;
715 }
716 if ((flags & TYPECACHE_GT_OPR) &&
717 !(typentry->flags & TCFLAGS_CHECKED_GT_OPR))
718 {
719 Oid gt_opr = InvalidOid;
720
721 if (typentry->btree_opf != InvalidOid)
722 gt_opr = get_opfamily_member(typentry->btree_opf,
723 typentry->btree_opintype,
724 typentry->btree_opintype,
726
727 /*
728 * As above, make sure array_cmp or record_cmp will succeed; but again
729 * we need no special check for ranges or multiranges.
730 */
731 if (gt_opr == ARRAY_GT_OP &&
732 !array_element_has_compare(typentry))
733 gt_opr = InvalidOid;
734 else if (gt_opr == RECORD_GT_OP &&
736 gt_opr = InvalidOid;
737
738 typentry->gt_opr = gt_opr;
739 typentry->flags |= TCFLAGS_CHECKED_GT_OPR;
740 }
742 !(typentry->flags & TCFLAGS_CHECKED_CMP_PROC))
743 {
744 Oid cmp_proc = InvalidOid;
745
746 if (typentry->btree_opf != InvalidOid)
747 cmp_proc = get_opfamily_proc(typentry->btree_opf,
748 typentry->btree_opintype,
749 typentry->btree_opintype,
751
752 /*
753 * As above, make sure array_cmp or record_cmp will succeed; but again
754 * we need no special check for ranges or multiranges.
755 */
756 if (cmp_proc == F_BTARRAYCMP &&
757 !array_element_has_compare(typentry))
758 cmp_proc = InvalidOid;
759 else if (cmp_proc == F_BTRECORDCMP &&
761 cmp_proc = InvalidOid;
762
763 /* Force update of cmp_proc_finfo only if we're changing state */
764 if (typentry->cmp_proc != cmp_proc)
765 typentry->cmp_proc_finfo.fn_oid = InvalidOid;
766
767 typentry->cmp_proc = cmp_proc;
768 typentry->flags |= TCFLAGS_CHECKED_CMP_PROC;
769 }
771 !(typentry->flags & TCFLAGS_CHECKED_HASH_PROC))
772 {
773 Oid hash_proc = InvalidOid;
774
775 /*
776 * We insist that the eq_opr, if one has been determined, match the
777 * hash opclass; else report there is no hash function.
778 */
779 if (typentry->hash_opf != InvalidOid &&
780 (!OidIsValid(typentry->eq_opr) ||
781 typentry->eq_opr == get_opfamily_member(typentry->hash_opf,
782 typentry->hash_opintype,
783 typentry->hash_opintype,
785 hash_proc = get_opfamily_proc(typentry->hash_opf,
786 typentry->hash_opintype,
787 typentry->hash_opintype,
789
790 /*
791 * As above, make sure hash_array, hash_record, hash_range, or
792 * hash_multirange will succeed. Here we do need to check the range
793 * cases.
794 */
795 if (hash_proc == F_HASH_ARRAY &&
796 !array_element_has_hashing(typentry))
797 hash_proc = InvalidOid;
798 else if (hash_proc == F_HASH_RECORD &&
800 hash_proc = InvalidOid;
801 else if (hash_proc == F_HASH_RANGE &&
802 !range_element_has_hashing(typentry))
803 hash_proc = InvalidOid;
804 else if (hash_proc == F_HASH_MULTIRANGE &&
806 hash_proc = InvalidOid;
807
808 /* Force update of hash_proc_finfo only if we're changing state */
809 if (typentry->hash_proc != hash_proc)
811
812 typentry->hash_proc = hash_proc;
813 typentry->flags |= TCFLAGS_CHECKED_HASH_PROC;
814 }
815 if ((flags & (TYPECACHE_HASH_EXTENDED_PROC |
818 {
819 Oid hash_extended_proc = InvalidOid;
820
821 /*
822 * We insist that the eq_opr, if one has been determined, match the
823 * hash opclass; else report there is no hash function.
824 */
825 if (typentry->hash_opf != InvalidOid &&
826 (!OidIsValid(typentry->eq_opr) ||
827 typentry->eq_opr == get_opfamily_member(typentry->hash_opf,
828 typentry->hash_opintype,
829 typentry->hash_opintype,
831 hash_extended_proc = get_opfamily_proc(typentry->hash_opf,
832 typentry->hash_opintype,
833 typentry->hash_opintype,
835
836 /*
837 * As above, make sure hash_array_extended, hash_record_extended,
838 * hash_range_extended, or hash_multirange_extended will succeed.
839 */
840 if (hash_extended_proc == F_HASH_ARRAY_EXTENDED &&
842 hash_extended_proc = InvalidOid;
843 else if (hash_extended_proc == F_HASH_RECORD_EXTENDED &&
845 hash_extended_proc = InvalidOid;
846 else if (hash_extended_proc == F_HASH_RANGE_EXTENDED &&
848 hash_extended_proc = InvalidOid;
849 else if (hash_extended_proc == F_HASH_MULTIRANGE_EXTENDED &&
851 hash_extended_proc = InvalidOid;
852
853 /* Force update of proc finfo only if we're changing state */
854 if (typentry->hash_extended_proc != hash_extended_proc)
856
857 typentry->hash_extended_proc = hash_extended_proc;
859 }
860
861 /*
862 * Set up fmgr lookup info as requested
863 *
864 * Note: we tell fmgr the finfo structures live in CacheMemoryContext,
865 * which is not quite right (they're really in the hash table's private
866 * memory context) but this will do for our purposes.
867 *
868 * Note: the code above avoids invalidating the finfo structs unless the
869 * referenced operator/function OID actually changes. This is to prevent
870 * unnecessary leakage of any subsidiary data attached to an finfo, since
871 * that would cause session-lifespan memory leaks.
872 */
873 if ((flags & TYPECACHE_EQ_OPR_FINFO) &&
874 typentry->eq_opr_finfo.fn_oid == InvalidOid &&
875 typentry->eq_opr != InvalidOid)
876 {
878
879 eq_opr_func = get_opcode(typentry->eq_opr);
880 if (eq_opr_func != InvalidOid)
883 }
884 if ((flags & TYPECACHE_CMP_PROC_FINFO) &&
885 typentry->cmp_proc_finfo.fn_oid == InvalidOid &&
886 typentry->cmp_proc != InvalidOid)
887 {
888 fmgr_info_cxt(typentry->cmp_proc, &typentry->cmp_proc_finfo,
890 }
891 if ((flags & TYPECACHE_HASH_PROC_FINFO) &&
892 typentry->hash_proc_finfo.fn_oid == InvalidOid &&
893 typentry->hash_proc != InvalidOid)
894 {
895 fmgr_info_cxt(typentry->hash_proc, &typentry->hash_proc_finfo,
897 }
900 typentry->hash_extended_proc != InvalidOid)
901 {
903 &typentry->hash_extended_proc_finfo,
905 }
906
907 /*
908 * If it's a composite type (row type), get tupdesc if requested
909 */
910 if ((flags & TYPECACHE_TUPDESC) &&
911 typentry->tupDesc == NULL &&
912 typentry->typtype == TYPTYPE_COMPOSITE)
913 {
914 load_typcache_tupdesc(typentry);
915 }
916
917 /*
918 * If requested, get information about a range type
919 *
920 * This includes making sure that the basic info about the range element
921 * type is up-to-date.
922 */
923 if ((flags & TYPECACHE_RANGE_INFO) &&
924 typentry->typtype == TYPTYPE_RANGE)
925 {
926 if (typentry->rngelemtype == NULL)
927 load_rangetype_info(typentry);
928 else if (!(typentry->rngelemtype->flags & TCFLAGS_HAVE_PG_TYPE_DATA))
929 (void) lookup_type_cache(typentry->rngelemtype->type_id, 0);
930 }
931
932 /*
933 * If requested, get information about a multirange type
934 */
935 if ((flags & TYPECACHE_MULTIRANGE_INFO) &&
936 typentry->rngtype == NULL &&
937 typentry->typtype == TYPTYPE_MULTIRANGE)
938 {
939 load_multirangetype_info(typentry);
940 }
941
942 /*
943 * If requested, get information about a domain type
944 */
945 if ((flags & TYPECACHE_DOMAIN_BASE_INFO) &&
946 typentry->domainBaseType == InvalidOid &&
947 typentry->typtype == TYPTYPE_DOMAIN)
948 {
949 typentry->domainBaseTypmod = -1;
950 typentry->domainBaseType =
951 getBaseTypeAndTypmod(type_id, &typentry->domainBaseTypmod);
952 }
953 if ((flags & TYPECACHE_DOMAIN_CONSTR_INFO) &&
954 (typentry->flags & TCFLAGS_CHECKED_DOMAIN_CONSTRAINTS) == 0 &&
955 typentry->typtype == TYPTYPE_DOMAIN)
956 {
957 load_domaintype_info(typentry);
958 }
959
960 INJECTION_POINT("typecache-before-rel-type-cache-insert", NULL);
961
964
966
967 return typentry;
968}
#define NameStr(name)
Definition c.h:835
#define MemSet(start, val, len)
Definition c.h:1107
#define OidIsValid(objectId)
Definition c.h:858
uint32 get_hash_value(HTAB *hashp, const void *keyPtr)
Definition dynahash.c:845
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Definition fmgr.c:139
#define HASHSTANDARD_PROC
Definition hash.h:355
#define HASHEXTENDED_PROC
Definition hash.h:356
#define HASH_BLOBS
Definition hsearch.h:92
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
Definition indexcmds.c:2371
#define INJECTION_POINT(name, arg)
void CacheRegisterSyscacheCallback(SysCacheIdentifier cacheid, SyscacheCallbackFunction func, Datum arg)
Definition inval.c:1813
void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg)
Definition inval.c:1855
Oid get_opclass_input_type(Oid opclass)
Definition lsyscache.c:1456
Oid get_opclass_family(Oid opclass)
Definition lsyscache.c:1434
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Definition lsyscache.c:1014
RegProcedure get_opcode(Oid opno)
Definition lsyscache.c:1577
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition lsyscache.c:170
Oid getBaseTypeAndTypmod(Oid typid, int32 *typmod)
Definition lsyscache.c:2846
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1235
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1635
#define BTORDER_PROC
Definition nbtree.h:717
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
Definition pg_type.h:265
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
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:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
#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:1742
static void insert_rel_type_cache_if_needed(TypeCacheEntry *typentry)
Definition typcache.c:3102
static void TypeCacheOpcCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition typcache.c:2600
static bool record_fields_have_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1621
static HTAB * RelIdToTypeIdCacheHash
Definition typcache.c:87
static bool record_fields_have_extended_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1629
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:1782
static bool record_fields_have_equality(TypeCacheEntry *typentry)
Definition typcache.c:1605
#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:1567
static bool array_element_has_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1559
static void load_multirangetype_info(TypeCacheEntry *typentry)
Definition typcache.c:1066
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:1790
static int in_progress_list_len
Definition typcache.c:227
static bool array_element_has_equality(TypeCacheEntry *typentry)
Definition typcache.c:1543
static void load_rangetype_info(TypeCacheEntry *typentry)
Definition typcache.c:1008
static bool range_element_has_extended_hashing(TypeCacheEntry *typentry)
Definition typcache.c:1750
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:1088
static void TypeCacheRelCallback(Datum arg, Oid relid)
Definition typcache.c:2447
static void TypeCacheTypCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition typcache.c:2543
static void TypeCacheConstrCallback(Datum arg, SysCacheIdentifier cacheid, uint32 hashvalue)
Definition typcache.c:2638
static bool array_element_has_compare(TypeCacheEntry *typentry)
Definition typcache.c:1551
#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:1613
#define TCFLAGS_CHECKED_EQ_OPR
Definition typcache.c:102
static void load_typcache_tupdesc(TypeCacheEntry *typentry)
Definition typcache.c:974
#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, Form_pg_type, 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(), ExecForPortionOfLeftovers(), ExecInitExprRec(), find_simplified_clause(), foreign_expr_walker(), get_cached_rowtype(), get_multirange_io_data(), get_op_hash_functions_ext(), 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(), import_pg_statistic(), 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 2323 of file typcache.c.

2324{
2328
2330
2331 /* We can't already be attached to a shared registry. */
2338
2339 /*
2340 * We can't already have typmods in our local cache, because they'd clash
2341 * with those imported by SharedRecordTypmodRegistryInit. This should be
2342 * a freshly started parallel worker. If we ever support worker
2343 * recycling, a worker would need to zap its local cache in between
2344 * servicing different queries, in order to be able to call this and
2345 * synchronize typmods with a new leader; but that's problematic because
2346 * we can't be very sure that record-typmod-related state hasn't escaped
2347 * to anywhere else in the process.
2348 */
2350
2352
2353 /* Attach to the two hash tables. */
2356 registry->record_table_handle,
2360 registry->typmod_table_handle,
2361 NULL);
2362
2364
2365 /*
2366 * Set up detach hook to run at worker exit. Currently this is the same
2367 * as the leader's detach hook, but in future they might need to be
2368 * different.
2369 */
2373
2374 /*
2375 * Set up the session state that will tell assign_record_type_typmod and
2376 * lookup_rowtype_tupdesc_internal about the shared registry.
2377 */
2381}
dshash_table * dshash_attach(dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg)
Definition dshash.c:274
void on_dsm_detach(dsm_segment *seg, on_dsm_detach_callback function, Datum arg)
Definition dsm.c:1140
#define IsParallelWorker()
Definition parallel.h:62
MemoryContext TopMemoryContext
Definition mcxt.c:167
#define PointerGetDatum(X)
Definition postgres.h:354
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:3082
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 2202 of file typcache.c.

2203{
2204 return sizeof(SharedRecordTypmodRegistry);
2205}

Referenced by GetSessionDsmHandle().

◆ SharedRecordTypmodRegistryInit()

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

Definition at line 2224 of file typcache.c.

2227{
2231 int32 typmod;
2232
2234
2235 /* We can't already be attached to a shared registry. */
2239
2241
2242 /* Create the hash table of tuple descriptors indexed by themselves. */
2244
2245 /* Create the hash table of tuple descriptors indexed by typmod. */
2247
2249
2250 /* Initialize the SharedRecordTypmodRegistry. */
2251 registry->record_table_handle = dshash_get_hash_table_handle(record_table);
2252 registry->typmod_table_handle = dshash_get_hash_table_handle(typmod_table);
2254
2255 /*
2256 * Copy all entries from this backend's private registry into the shared
2257 * registry.
2258 */
2259 for (typmod = 0; typmod < NextRecordTypmod; ++typmod)
2260 {
2265 TupleDesc tupdesc;
2266 bool found;
2267
2268 tupdesc = RecordCacheArray[typmod].tupdesc;
2269 if (tupdesc == NULL)
2270 continue;
2271
2272 /* Copy the TupleDesc into shared memory. */
2273 shared_dp = share_tupledesc(area, tupdesc, typmod);
2274
2275 /* Insert into the typmod table. */
2277 &tupdesc->tdtypmod,
2278 &found);
2279 if (found)
2280 elog(ERROR, "cannot create duplicate shared record typmod");
2281 typmod_table_entry->typmod = tupdesc->tdtypmod;
2282 typmod_table_entry->shared_tupdesc = shared_dp;
2284
2285 /* Insert into the record table. */
2286 record_table_key.shared = false;
2287 record_table_key.u.local_tupdesc = tupdesc;
2290 &found);
2291 if (!found)
2292 {
2293 record_table_entry->key.shared = true;
2294 record_table_entry->key.u.shared_tupdesc = shared_dp;
2295 }
2297 }
2298
2299 /*
2300 * Set up the global state that will tell assign_record_type_typmod and
2301 * lookup_rowtype_tupdesc_internal about the shared registry.
2302 */
2306
2307 /*
2308 * We install a detach hook in the leader, but only to handle cleanup on
2309 * failure during GetSessionDsmHandle(). Once GetSessionDsmHandle() pins
2310 * the memory, the leader process will use a shared registry until it
2311 * exits.
2312 */
2314}
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition atomics.h:219
int32_t int32
Definition c.h:620
uint64 dsa_pointer
Definition dsa.h:62
void dshash_release_lock(dshash_table *hash_table, void *entry)
Definition dshash.c:579
dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table)
Definition dshash.c:371
dshash_table * dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
Definition dshash.c:210
#define dshash_find_or_insert(hash_table, key, found)
Definition dshash.h:109
static dsa_pointer share_tupledesc(dsa_area *area, TupleDesc tupdesc, uint32 typmod)
Definition typcache.c:2949

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 1444 of file typcache.c.

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

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().