1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <catalog/pg_type.h>
#include <catalog/pg_collation_d.h>
#include "pg_query_pg_type.c"
HeapTuple
SearchSysCache1(int cacheId,
Datum key1)
{
/*Assert(cacheId >= 0 && cacheId < SysCacheSize &&
PointerIsValid(SysCache[cacheId]));
Assert(SysCache[cacheId]->cc_nkeys == 1);
return SearchCatCache1(SysCache[cacheId], key1);*/
HeapTuple tuple;
HeapTupleHeader td;
Form_pg_type t = palloc0(sizeof(FormData_pg_type));
const PgQueryBuiltinType *bt;
Size len,
data_len;
int hoff;
if (cacheId != TYPEOID)
elog(ERROR, "Not implemented (SearchSysCache1 only supports TYPEOID cache (%d), got cache %d)", TYPEOID, cacheId);
bt = pg_query_builtin_type_by_oid(DatumGetObjectId(key1));
if (bt == NULL)
elog(ERROR, "Not implemented (SearchSysCache1 got TYPEOID cache request for type OID %d)", DatumGetObjectId(key1));
strlcpy(NameStr(t->typname), bt->typname, NAMEDATALEN);
t->typlen = bt->typlen;
t->typbyval = bt->typbyval;
t->typtype = bt->typtype;
t->typcategory = bt->typcategory;
t->typalign = bt->typalign;
t->typarray = bt->typarray;
t->typcollation = bt->typcollation;
t->oid = DatumGetObjectId(key1);
t->typisdefined = true;
// The following logic is copied from heap_form_tuple, but pretends there are no nulls, and copies t_data directly
/*
* Determine total space needed
*/
len = offsetof(HeapTupleHeaderData, t_bits);
//if (hasnull)
// len += BITMAPLEN(numberOfAttributes);
hoff = len = MAXALIGN(len); /* align user data safely */
//data_len = heap_compute_data_size(tupleDescriptor, values, isnull);
data_len = MAXALIGN(sizeof(FormData_pg_type));
len += data_len;
/*
* Allocate and zero the space needed. Note that the tuple body and
* HeapTupleData management structure are allocated in one chunk.
*/
tuple = (HeapTuple) palloc0(HEAPTUPLESIZE + len);
tuple->t_data = td = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
/*
* And fill in the information. Note we fill the Datum fields even though
* this tuple may never become a Datum. This lets HeapTupleHeaderGetDatum
* identify the tuple type if needed.
*/
tuple->t_len = len;
ItemPointerSetInvalid(&(tuple->t_self));
tuple->t_tableOid = InvalidOid;
HeapTupleHeaderSetDatumLength(td, len);
//HeapTupleHeaderSetTypeId(td, tupleDescriptor->tdtypeid);
//HeapTupleHeaderSetTypMod(td, tupleDescriptor->tdtypmod);
/* We also make sure that t_ctid is invalid unless explicitly set */
ItemPointerSetInvalid(&(td->t_ctid));
HeapTupleHeaderSetNatts(td, Natts_pg_type);
td->t_hoff = hoff;
/*heap_fill_tuple(tupleDescriptor,
values,
isnull,
(char *) td + hoff,
data_len,
&td->t_infomask,
(hasnull ? td->t_bits : NULL));*/
memcpy((char *) td + hoff, t, sizeof(FormData_pg_type));
return tuple;
}