PostgreSQL Source Code git master
Loading...
Searching...
No Matches
amvalidate.c File Reference
#include "postgres.h"
#include "access/amvalidate.h"
#include "access/htup_details.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "parser/parse_coerce.h"
#include "utils/syscache.h"
Include dependency graph for amvalidate.c:

Go to the source code of this file.

Functions

Listidentify_opfamily_groups (CatCList *oprlist, CatCList *proclist)
 
bool check_amproc_signature (Oid funcid, Oid restype, bool exact, int minargs, int maxargs,...)
 
bool check_amoptsproc_signature (Oid funcid)
 
bool check_amop_signature (Oid opno, Oid restype, Oid lefttype, Oid righttype)
 
Oid opclass_for_family_datatype (Oid amoid, Oid opfamilyoid, Oid datatypeoid)
 
bool opfamily_can_sort_type (Oid opfamilyoid, Oid datatypeoid)
 

Function Documentation

◆ check_amop_signature()

bool check_amop_signature ( Oid  opno,
Oid  restype,
Oid  lefttype,
Oid  righttype 
)

Definition at line 206 of file amvalidate.c.

207{
208 bool result = true;
209 HeapTuple tp;
211
213 if (!HeapTupleIsValid(tp)) /* shouldn't happen */
214 elog(ERROR, "cache lookup failed for operator %u", opno);
216
217 if (opform->oprresult != restype || opform->oprkind != 'b' ||
218 opform->oprleft != lefttype || opform->oprright != righttype)
219 result = false;
220
221 ReleaseSysCache(tp);
222 return result;
223}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
FormData_pg_operator * Form_pg_operator
Definition pg_operator.h:83
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:262
static int fb(int x)
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition syscache.c:220

References elog, ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().

Referenced by blvalidate(), brinvalidate(), btvalidate(), ginvalidate(), gistvalidate(), hashvalidate(), and spgvalidate().

◆ check_amoptsproc_signature()

bool check_amoptsproc_signature ( Oid  funcid)

Definition at line 192 of file amvalidate.c.

193{
194 return check_amproc_signature(funcid, VOIDOID, true, 1, 1, INTERNALOID);
195}
bool check_amproc_signature(Oid funcid, Oid restype, bool exact, int minargs, int maxargs,...)
Definition amvalidate.c:152

References check_amproc_signature(), and fb().

Referenced by blvalidate(), brinvalidate(), btvalidate(), ginvalidate(), gistvalidate(), hashvalidate(), and spgvalidate().

◆ check_amproc_signature()

bool check_amproc_signature ( Oid  funcid,
Oid  restype,
bool  exact,
int  minargs,
int  maxargs,
  ... 
)

Definition at line 152 of file amvalidate.c.

154{
155 bool result = true;
156 HeapTuple tp;
158 va_list ap;
159 int i;
160
162 if (!HeapTupleIsValid(tp))
163 elog(ERROR, "cache lookup failed for function %u", funcid);
165
166 if (procform->prorettype != restype || procform->proretset ||
167 procform->pronargs < minargs || procform->pronargs > maxargs)
168 result = false;
169
171 for (i = 0; i < maxargs; i++)
172 {
173 Oid argtype = va_arg(ap, Oid);
174
175 if (i >= procform->pronargs)
176 continue;
177 if (exact ? (argtype != procform->proargtypes.values[i]) :
179 result = false;
180 }
181 va_end(ap);
182
183 ReleaseSysCache(tp);
184 return result;
185}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define false
int i
Definition isn.c:77
bool IsBinaryCoercible(Oid srctype, Oid targettype)
FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:136
unsigned int Oid

References elog, ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, i, IsBinaryCoercible(), ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().

Referenced by blvalidate(), brinvalidate(), btvalidate(), check_amoptsproc_signature(), ginvalidate(), gistvalidate(), hashvalidate(), and spgvalidate().

◆ identify_opfamily_groups()

List * identify_opfamily_groups ( CatCList oprlist,
CatCList proclist 
)

Definition at line 43 of file amvalidate.c.

44{
45 List *result = NIL;
49 int io,
50 ip;
51
52 /* We need the lists to be ordered; should be true in normal operation */
53 if (!oprlist->ordered || !proclist->ordered)
54 elog(ERROR, "cannot validate operator family without ordered data");
55
56 /*
57 * Advance through the lists concurrently. Thanks to the ordering, we
58 * should see all operators and functions of a given datatype pair
59 * consecutively.
60 */
62 io = ip = 0;
63 if (io < oprlist->n_members)
64 {
65 oprform = (Form_pg_amop) GETSTRUCT(&oprlist->members[io]->tuple);
66 io++;
67 }
68 else
69 oprform = NULL;
70 if (ip < proclist->n_members)
71 {
72 procform = (Form_pg_amproc) GETSTRUCT(&proclist->members[ip]->tuple);
73 ip++;
74 }
75 else
76 procform = NULL;
77
78 while (oprform || procform)
79 {
80 if (oprform && thisgroup &&
81 oprform->amoplefttype == thisgroup->lefttype &&
82 oprform->amoprighttype == thisgroup->righttype)
83 {
84 /* Operator belongs to current group; include it and advance */
85
86 /* Ignore strategy numbers outside supported range */
87 if (oprform->amopstrategy > 0 && oprform->amopstrategy < 64)
88 thisgroup->operatorset |= ((uint64) 1) << oprform->amopstrategy;
89
90 if (io < oprlist->n_members)
91 {
92 oprform = (Form_pg_amop) GETSTRUCT(&oprlist->members[io]->tuple);
93 io++;
94 }
95 else
96 oprform = NULL;
97 continue;
98 }
99
100 if (procform && thisgroup &&
101 procform->amproclefttype == thisgroup->lefttype &&
102 procform->amprocrighttype == thisgroup->righttype)
103 {
104 /* Procedure belongs to current group; include it and advance */
105
106 /* Ignore function numbers outside supported range */
107 if (procform->amprocnum > 0 && procform->amprocnum < 64)
108 thisgroup->functionset |= ((uint64) 1) << procform->amprocnum;
109
110 if (ip < proclist->n_members)
111 {
112 procform = (Form_pg_amproc) GETSTRUCT(&proclist->members[ip]->tuple);
113 ip++;
114 }
115 else
116 procform = NULL;
117 continue;
118 }
119
120 /* Time for a new group */
122 if (oprform &&
123 (!procform ||
124 (oprform->amoplefttype < procform->amproclefttype ||
125 (oprform->amoplefttype == procform->amproclefttype &&
126 oprform->amoprighttype < procform->amprocrighttype))))
127 {
128 thisgroup->lefttype = oprform->amoplefttype;
129 thisgroup->righttype = oprform->amoprighttype;
130 }
131 else
132 {
133 thisgroup->lefttype = procform->amproclefttype;
134 thisgroup->righttype = procform->amprocrighttype;
135 }
136 thisgroup->operatorset = thisgroup->functionset = 0;
137 result = lappend(result, thisgroup);
138 }
139
140 return result;
141}
uint64_t uint64
Definition c.h:547
#define palloc_object(type)
Definition fe_memutils.h:74
List * lappend(List *list, void *datum)
Definition list.c:339
FormData_pg_amop * Form_pg_amop
Definition pg_amop.h:88
FormData_pg_amproc * Form_pg_amproc
Definition pg_amproc.h:68
#define NIL
Definition pg_list.h:68
Definition pg_list.h:54

References elog, ERROR, fb(), GETSTRUCT(), lappend(), NIL, and palloc_object.

Referenced by blvalidate(), brinvalidate(), btvalidate(), ginvalidate(), gistvalidate(), hashvalidate(), and spgvalidate().

◆ opclass_for_family_datatype()

Oid opclass_for_family_datatype ( Oid  amoid,
Oid  opfamilyoid,
Oid  datatypeoid 
)

Definition at line 236 of file amvalidate.c.

237{
238 Oid result = InvalidOid;
240 int i;
241
242 /*
243 * We search through all the AM's opclasses to see if one matches. This
244 * is a bit inefficient but there is no better index available. It also
245 * saves making an explicit check that the opfamily belongs to the AM.
246 */
248
249 for (i = 0; i < opclist->n_members; i++)
250 {
251 HeapTuple classtup = &opclist->members[i]->tuple;
253
254 if (classform->opcfamily == opfamilyoid &&
255 classform->opcintype == datatypeoid)
256 {
257 result = classform->oid;
258 break;
259 }
260 }
261
263
264 return result;
265}
void ReleaseCatCacheList(CatCList *list)
Definition catcache.c:2114
FormData_pg_opclass * Form_pg_opclass
Definition pg_opclass.h:83
#define InvalidOid
#define SearchSysCacheList1(cacheId, key1)
Definition syscache.h:127

References fb(), GETSTRUCT(), i, InvalidOid, ObjectIdGetDatum(), ReleaseCatCacheList(), and SearchSysCacheList1.

Referenced by btadjustmembers(), hashadjustmembers(), and opfamily_can_sort_type().

◆ opfamily_can_sort_type()

bool opfamily_can_sort_type ( Oid  opfamilyoid,
Oid  datatypeoid 
)

Definition at line 271 of file amvalidate.c.

272{
275 datatypeoid));
276}
Oid opclass_for_family_datatype(Oid amoid, Oid opfamilyoid, Oid datatypeoid)
Definition amvalidate.c:236
#define OidIsValid(objectId)
Definition c.h:788

References fb(), OidIsValid, and opclass_for_family_datatype().

Referenced by gistvalidate(), spgproperty(), and spgvalidate().