@@ -273,10 +273,15 @@ static const dshash_parameters srtr_typmod_table_params = {
273
273
/* hashtable for recognizing registered record types */
274
274
static HTAB * RecordCacheHash = NULL ;
275
275
276
- /* arrays of info about registered record types, indexed by assigned typmod */
277
- static TupleDesc * RecordCacheArray = NULL ;
278
- static uint64 * RecordIdentifierArray = NULL ;
279
- static int32 RecordCacheArrayLen = 0 ; /* allocated length of above arrays */
276
+ typedef struct RecordCacheArrayEntry
277
+ {
278
+ uint64 id ;
279
+ TupleDesc tupdesc ;
280
+ } RecordCacheArrayEntry ;
281
+
282
+ /* array of info about registered record types, indexed by assigned typmod */
283
+ static RecordCacheArrayEntry * RecordCacheArray = NULL ;
284
+ static int32 RecordCacheArrayLen = 0 ; /* allocated length of above array */
280
285
static int32 NextRecordTypmod = 0 ; /* number of entries used */
281
286
282
287
/*
@@ -1703,19 +1708,20 @@ ensure_record_cache_typmod_slot_exists(int32 typmod)
1703
1708
{
1704
1709
if (RecordCacheArray == NULL )
1705
1710
{
1706
- RecordCacheArray = (TupleDesc * )
1707
- MemoryContextAllocZero (CacheMemoryContext , 64 * sizeof (TupleDesc ));
1708
- RecordIdentifierArray = (uint64 * )
1709
- MemoryContextAllocZero (CacheMemoryContext , 64 * sizeof (uint64 ));
1711
+ RecordCacheArray = (RecordCacheArrayEntry * )
1712
+ MemoryContextAllocZero (CacheMemoryContext ,
1713
+ 64 * sizeof (RecordCacheArrayEntry ));
1710
1714
RecordCacheArrayLen = 64 ;
1711
1715
}
1712
1716
1713
1717
if (typmod >= RecordCacheArrayLen )
1714
1718
{
1715
1719
int32 newlen = pg_nextpower2_32 (typmod + 1 );
1716
1720
1717
- RecordCacheArray = repalloc0_array (RecordCacheArray , TupleDesc , RecordCacheArrayLen , newlen );
1718
- RecordIdentifierArray = repalloc0_array (RecordIdentifierArray , uint64 , RecordCacheArrayLen , newlen );
1721
+ RecordCacheArray = repalloc0_array (RecordCacheArray ,
1722
+ RecordCacheArrayEntry ,
1723
+ RecordCacheArrayLen ,
1724
+ newlen );
1719
1725
RecordCacheArrayLen = newlen ;
1720
1726
}
1721
1727
}
@@ -1753,8 +1759,8 @@ lookup_rowtype_tupdesc_internal(Oid type_id, int32 typmod, bool noError)
1753
1759
{
1754
1760
/* It is already in our local cache? */
1755
1761
if (typmod < RecordCacheArrayLen &&
1756
- RecordCacheArray [typmod ] != NULL )
1757
- return RecordCacheArray [typmod ];
1762
+ RecordCacheArray [typmod ]. tupdesc != NULL )
1763
+ return RecordCacheArray [typmod ]. tupdesc ;
1758
1764
1759
1765
/* Are we attached to a shared record typmod registry? */
1760
1766
if (CurrentSession -> shared_typmod_registry != NULL )
@@ -1780,19 +1786,19 @@ lookup_rowtype_tupdesc_internal(Oid type_id, int32 typmod, bool noError)
1780
1786
* Our local array can now point directly to the TupleDesc
1781
1787
* in shared memory, which is non-reference-counted.
1782
1788
*/
1783
- RecordCacheArray [typmod ] = tupdesc ;
1789
+ RecordCacheArray [typmod ]. tupdesc = tupdesc ;
1784
1790
Assert (tupdesc -> tdrefcount == -1 );
1785
1791
1786
1792
/*
1787
1793
* We don't share tupdesc identifiers across processes, so
1788
1794
* assign one locally.
1789
1795
*/
1790
- RecordIdentifierArray [typmod ] = ++ tupledesc_id_counter ;
1796
+ RecordCacheArray [typmod ]. id = ++ tupledesc_id_counter ;
1791
1797
1792
1798
dshash_release_lock (CurrentSession -> shared_typmod_table ,
1793
1799
entry );
1794
1800
1795
- return RecordCacheArray [typmod ];
1801
+ return RecordCacheArray [typmod ]. tupdesc ;
1796
1802
}
1797
1803
}
1798
1804
}
@@ -2005,10 +2011,10 @@ assign_record_type_typmod(TupleDesc tupDesc)
2005
2011
ensure_record_cache_typmod_slot_exists (entDesc -> tdtypmod );
2006
2012
}
2007
2013
2008
- RecordCacheArray [entDesc -> tdtypmod ] = entDesc ;
2014
+ RecordCacheArray [entDesc -> tdtypmod ]. tupdesc = entDesc ;
2009
2015
2010
2016
/* Assign a unique tupdesc identifier, too. */
2011
- RecordIdentifierArray [entDesc -> tdtypmod ] = ++ tupledesc_id_counter ;
2017
+ RecordCacheArray [entDesc -> tdtypmod ]. id = ++ tupledesc_id_counter ;
2012
2018
2013
2019
/* Fully initialized; create the hash table entry */
2014
2020
recentry = (RecordCacheEntry * ) hash_search (RecordCacheHash ,
@@ -2057,10 +2063,10 @@ assign_record_type_identifier(Oid type_id, int32 typmod)
2057
2063
* It's a transient record type, so look in our record-type table.
2058
2064
*/
2059
2065
if (typmod >= 0 && typmod < RecordCacheArrayLen &&
2060
- RecordCacheArray [typmod ] != NULL )
2066
+ RecordCacheArray [typmod ]. tupdesc != NULL )
2061
2067
{
2062
- Assert (RecordIdentifierArray [typmod ] != 0 );
2063
- return RecordIdentifierArray [typmod ];
2068
+ Assert (RecordCacheArray [typmod ]. id != 0 );
2069
+ return RecordCacheArray [typmod ]. id ;
2064
2070
}
2065
2071
2066
2072
/* For anonymous or unrecognized record type, generate a new ID */
@@ -2140,7 +2146,7 @@ SharedRecordTypmodRegistryInit(SharedRecordTypmodRegistry *registry,
2140
2146
TupleDesc tupdesc ;
2141
2147
bool found ;
2142
2148
2143
- tupdesc = RecordCacheArray [typmod ];
2149
+ tupdesc = RecordCacheArray [typmod ]. tupdesc ;
2144
2150
if (tupdesc == NULL )
2145
2151
continue ;
2146
2152
0 commit comments