* OpClassCacheLookup * Look up an existing opclass by name. * * Returns a syscache tuple reference, or NULL if not found. */
| 167 | * Returns a syscache tuple reference, or NULL if not found. |
| 168 | */ |
| 169 | static HeapTuple |
| 170 | OpClassCacheLookup(Oid amID, List *opclassname, bool missing_ok) |
| 171 | { |
| 172 | char *schemaname; |
| 173 | char *opcname; |
| 174 | HeapTuple htup; |
| 175 | |
| 176 | /* deconstruct the name list */ |
| 177 | DeconstructQualifiedName(opclassname, &schemaname, &opcname); |
| 178 | |
| 179 | if (schemaname) |
| 180 | { |
| 181 | /* Look in specific schema only */ |
| 182 | Oid namespaceId; |
| 183 | |
| 184 | namespaceId = LookupExplicitNamespace(schemaname, missing_ok); |
| 185 | if (!OidIsValid(namespaceId)) |
| 186 | htup = NULL; |
| 187 | else |
| 188 | htup = SearchSysCache3(CLAAMNAMENSP, |
| 189 | ObjectIdGetDatum(amID), |
| 190 | PointerGetDatum(opcname), |
| 191 | ObjectIdGetDatum(namespaceId)); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | /* Unqualified opclass name, so search the search path */ |
| 196 | Oid opcID = OpclassnameGetOpcid(amID, opcname); |
| 197 | |
| 198 | if (!OidIsValid(opcID)) |
| 199 | htup = NULL; |
| 200 | else |
| 201 | htup = SearchSysCache1(CLAOID, ObjectIdGetDatum(opcID)); |
| 202 | } |
| 203 | |
| 204 | if (!HeapTupleIsValid(htup) && !missing_ok) |
| 205 | { |
| 206 | HeapTuple amtup; |
| 207 | |
| 208 | amtup = SearchSysCache1(AMOID, ObjectIdGetDatum(amID)); |
| 209 | if (!HeapTupleIsValid(amtup)) |
| 210 | elog(ERROR, "cache lookup failed for access method %u", amID); |
| 211 | ereport(ERROR, |
| 212 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 213 | errmsg("operator class \"%s\" does not exist for access method \"%s\"", |
| 214 | NameListToString(opclassname), |
| 215 | NameStr(((Form_pg_am) GETSTRUCT(amtup))->amname)))); |
| 216 | } |
| 217 | |
| 218 | return htup; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * get_opclass_oid |
no test coverage detected