Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * objectaddress.c
4 : : * functions for working with ObjectAddresses
5 : : *
6 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 : : * Portions Copyright (c) 1994, Regents of the University of California
8 : : *
9 : : *
10 : : * IDENTIFICATION
11 : : * src/backend/catalog/objectaddress.c
12 : : *
13 : : *-------------------------------------------------------------------------
14 : : */
15 : :
16 : : #include "postgres.h"
17 : :
18 : : #include "access/genam.h"
19 : : #include "access/htup_details.h"
20 : : #include "access/relation.h"
21 : : #include "access/table.h"
22 : : #include "catalog/catalog.h"
23 : : #include "catalog/objectaddress.h"
24 : : #include "catalog/pg_am.h"
25 : : #include "catalog/pg_amop.h"
26 : : #include "catalog/pg_amproc.h"
27 : : #include "catalog/pg_attrdef.h"
28 : : #include "catalog/pg_authid.h"
29 : : #include "catalog/pg_auth_members.h"
30 : : #include "catalog/pg_cast.h"
31 : : #include "catalog/pg_collation.h"
32 : : #include "catalog/pg_constraint.h"
33 : : #include "catalog/pg_conversion.h"
34 : : #include "catalog/pg_database.h"
35 : : #include "catalog/pg_default_acl.h"
36 : : #include "catalog/pg_event_trigger.h"
37 : : #include "catalog/pg_extension.h"
38 : : #include "catalog/pg_foreign_data_wrapper.h"
39 : : #include "catalog/pg_foreign_server.h"
40 : : #include "catalog/pg_language.h"
41 : : #include "catalog/pg_largeobject.h"
42 : : #include "catalog/pg_largeobject_metadata.h"
43 : : #include "catalog/pg_namespace.h"
44 : : #include "catalog/pg_opclass.h"
45 : : #include "catalog/pg_operator.h"
46 : : #include "catalog/pg_opfamily.h"
47 : : #include "catalog/pg_parameter_acl.h"
48 : : #include "catalog/pg_policy.h"
49 : : #include "catalog/pg_proc.h"
50 : : #include "catalog/pg_propgraph_element.h"
51 : : #include "catalog/pg_propgraph_element_label.h"
52 : : #include "catalog/pg_propgraph_label.h"
53 : : #include "catalog/pg_propgraph_label_property.h"
54 : : #include "catalog/pg_propgraph_property.h"
55 : : #include "catalog/pg_publication.h"
56 : : #include "catalog/pg_publication_namespace.h"
57 : : #include "catalog/pg_publication_rel.h"
58 : : #include "catalog/pg_rewrite.h"
59 : : #include "catalog/pg_statistic_ext.h"
60 : : #include "catalog/pg_subscription.h"
61 : : #include "catalog/pg_tablespace.h"
62 : : #include "catalog/pg_transform.h"
63 : : #include "catalog/pg_trigger.h"
64 : : #include "catalog/pg_ts_config.h"
65 : : #include "catalog/pg_ts_dict.h"
66 : : #include "catalog/pg_ts_parser.h"
67 : : #include "catalog/pg_ts_template.h"
68 : : #include "catalog/pg_type.h"
69 : : #include "catalog/pg_user_mapping.h"
70 : : #include "commands/defrem.h"
71 : : #include "commands/event_trigger.h"
72 : : #include "commands/extension.h"
73 : : #include "commands/policy.h"
74 : : #include "commands/proclang.h"
75 : : #include "commands/tablespace.h"
76 : : #include "commands/trigger.h"
77 : : #include "foreign/foreign.h"
78 : : #include "funcapi.h"
79 : : #include "miscadmin.h"
80 : : #include "parser/parse_func.h"
81 : : #include "parser/parse_oper.h"
82 : : #include "parser/parse_type.h"
83 : : #include "rewrite/rewriteSupport.h"
84 : : #include "storage/large_object.h"
85 : : #include "storage/lmgr.h"
86 : : #include "storage/sinval.h"
87 : : #include "utils/acl.h"
88 : : #include "utils/builtins.h"
89 : : #include "utils/fmgroids.h"
90 : : #include "utils/lsyscache.h"
91 : : #include "utils/memutils.h"
92 : : #include "utils/regproc.h"
93 : : #include "utils/syscache.h"
94 : :
95 : : /*
96 : : * ObjectProperty
97 : : *
98 : : * This array provides a common part of system object structure; to help
99 : : * consolidate routines to handle various kind of object classes.
100 : : */
101 : : typedef struct
102 : : {
103 : : const char *class_descr; /* string describing the catalog, for internal
104 : : * error messages */
105 : : Oid class_oid; /* oid of catalog */
106 : : Oid oid_index_oid; /* oid of index on system oid column */
107 : : SysCacheIdentifier oid_catcache_id; /* id of catcache on system oid column */
108 : : SysCacheIdentifier name_catcache_id; /* id of catcache on
109 : : * (name,namespace), or (name) if
110 : : * the object does not live in a
111 : : * namespace */
112 : : AttrNumber attnum_oid; /* attribute number of oid column */
113 : : AttrNumber attnum_name; /* attnum of name field */
114 : : AttrNumber attnum_namespace; /* attnum of namespace field */
115 : : AttrNumber attnum_owner; /* attnum of owner field */
116 : : AttrNumber attnum_acl; /* attnum of acl field */
117 : : ObjectType objtype; /* OBJECT_* of this object type */
118 : : bool is_nsp_name_unique; /* can the nsp/name combination (or name
119 : : * alone, if there's no namespace) be
120 : : * considered a unique identifier for an
121 : : * object of this class? */
122 : : } ObjectPropertyType;
123 : :
124 : : static const ObjectPropertyType ObjectProperty[] =
125 : : {
126 : : {
127 : : "access method",
128 : : AccessMethodRelationId,
129 : : AmOidIndexId,
130 : : AMOID,
131 : : AMNAME,
132 : : Anum_pg_am_oid,
133 : : Anum_pg_am_amname,
134 : : InvalidAttrNumber,
135 : : InvalidAttrNumber,
136 : : InvalidAttrNumber,
137 : : OBJECT_ACCESS_METHOD,
138 : : true
139 : : },
140 : : {
141 : : "access method operator",
142 : : AccessMethodOperatorRelationId,
143 : : AccessMethodOperatorOidIndexId,
144 : : SYSCACHEID_INVALID,
145 : : SYSCACHEID_INVALID,
146 : : Anum_pg_amop_oid,
147 : : InvalidAttrNumber,
148 : : InvalidAttrNumber,
149 : : InvalidAttrNumber,
150 : : InvalidAttrNumber,
151 : : OBJECT_AMOP,
152 : : false
153 : : },
154 : : {
155 : : "access method procedure",
156 : : AccessMethodProcedureRelationId,
157 : : AccessMethodProcedureOidIndexId,
158 : : SYSCACHEID_INVALID,
159 : : SYSCACHEID_INVALID,
160 : : Anum_pg_amproc_oid,
161 : : InvalidAttrNumber,
162 : : InvalidAttrNumber,
163 : : InvalidAttrNumber,
164 : : InvalidAttrNumber,
165 : : OBJECT_AMPROC,
166 : : false
167 : : },
168 : : {
169 : : "cast",
170 : : CastRelationId,
171 : : CastOidIndexId,
172 : : SYSCACHEID_INVALID,
173 : : SYSCACHEID_INVALID,
174 : : Anum_pg_cast_oid,
175 : : InvalidAttrNumber,
176 : : InvalidAttrNumber,
177 : : InvalidAttrNumber,
178 : : InvalidAttrNumber,
179 : : OBJECT_CAST,
180 : : false
181 : : },
182 : : {
183 : : "collation",
184 : : CollationRelationId,
185 : : CollationOidIndexId,
186 : : COLLOID,
187 : : SYSCACHEID_INVALID, /* COLLNAMEENCNSP also takes encoding */
188 : : Anum_pg_collation_oid,
189 : : Anum_pg_collation_collname,
190 : : Anum_pg_collation_collnamespace,
191 : : Anum_pg_collation_collowner,
192 : : InvalidAttrNumber,
193 : : OBJECT_COLLATION,
194 : : true
195 : : },
196 : : {
197 : : "constraint",
198 : : ConstraintRelationId,
199 : : ConstraintOidIndexId,
200 : : CONSTROID,
201 : : SYSCACHEID_INVALID,
202 : : Anum_pg_constraint_oid,
203 : : Anum_pg_constraint_conname,
204 : : Anum_pg_constraint_connamespace,
205 : : InvalidAttrNumber,
206 : : InvalidAttrNumber,
207 : : -1,
208 : : false
209 : : },
210 : : {
211 : : "conversion",
212 : : ConversionRelationId,
213 : : ConversionOidIndexId,
214 : : CONVOID,
215 : : CONNAMENSP,
216 : : Anum_pg_conversion_oid,
217 : : Anum_pg_conversion_conname,
218 : : Anum_pg_conversion_connamespace,
219 : : Anum_pg_conversion_conowner,
220 : : InvalidAttrNumber,
221 : : OBJECT_CONVERSION,
222 : : true
223 : : },
224 : : {
225 : : "database",
226 : : DatabaseRelationId,
227 : : DatabaseOidIndexId,
228 : : DATABASEOID,
229 : : SYSCACHEID_INVALID,
230 : : Anum_pg_database_oid,
231 : : Anum_pg_database_datname,
232 : : InvalidAttrNumber,
233 : : Anum_pg_database_datdba,
234 : : Anum_pg_database_datacl,
235 : : OBJECT_DATABASE,
236 : : true
237 : : },
238 : : {
239 : : "default ACL",
240 : : DefaultAclRelationId,
241 : : DefaultAclOidIndexId,
242 : : SYSCACHEID_INVALID,
243 : : SYSCACHEID_INVALID,
244 : : Anum_pg_default_acl_oid,
245 : : InvalidAttrNumber,
246 : : InvalidAttrNumber,
247 : : InvalidAttrNumber,
248 : : InvalidAttrNumber,
249 : : OBJECT_DEFACL,
250 : : false
251 : : },
252 : : {
253 : : "extension",
254 : : ExtensionRelationId,
255 : : ExtensionOidIndexId,
256 : : SYSCACHEID_INVALID,
257 : : SYSCACHEID_INVALID,
258 : : Anum_pg_extension_oid,
259 : : Anum_pg_extension_extname,
260 : : InvalidAttrNumber, /* extension doesn't belong to extnamespace */
261 : : Anum_pg_extension_extowner,
262 : : InvalidAttrNumber,
263 : : OBJECT_EXTENSION,
264 : : true
265 : : },
266 : : {
267 : : "foreign-data wrapper",
268 : : ForeignDataWrapperRelationId,
269 : : ForeignDataWrapperOidIndexId,
270 : : FOREIGNDATAWRAPPEROID,
271 : : FOREIGNDATAWRAPPERNAME,
272 : : Anum_pg_foreign_data_wrapper_oid,
273 : : Anum_pg_foreign_data_wrapper_fdwname,
274 : : InvalidAttrNumber,
275 : : Anum_pg_foreign_data_wrapper_fdwowner,
276 : : Anum_pg_foreign_data_wrapper_fdwacl,
277 : : OBJECT_FDW,
278 : : true
279 : : },
280 : : {
281 : : "foreign server",
282 : : ForeignServerRelationId,
283 : : ForeignServerOidIndexId,
284 : : FOREIGNSERVEROID,
285 : : FOREIGNSERVERNAME,
286 : : Anum_pg_foreign_server_oid,
287 : : Anum_pg_foreign_server_srvname,
288 : : InvalidAttrNumber,
289 : : Anum_pg_foreign_server_srvowner,
290 : : Anum_pg_foreign_server_srvacl,
291 : : OBJECT_FOREIGN_SERVER,
292 : : true
293 : : },
294 : : {
295 : : "function",
296 : : ProcedureRelationId,
297 : : ProcedureOidIndexId,
298 : : PROCOID,
299 : : SYSCACHEID_INVALID, /* PROCNAMEARGSNSP also takes argument types */
300 : : Anum_pg_proc_oid,
301 : : Anum_pg_proc_proname,
302 : : Anum_pg_proc_pronamespace,
303 : : Anum_pg_proc_proowner,
304 : : Anum_pg_proc_proacl,
305 : : OBJECT_FUNCTION,
306 : : false
307 : : },
308 : : {
309 : : "language",
310 : : LanguageRelationId,
311 : : LanguageOidIndexId,
312 : : LANGOID,
313 : : LANGNAME,
314 : : Anum_pg_language_oid,
315 : : Anum_pg_language_lanname,
316 : : InvalidAttrNumber,
317 : : Anum_pg_language_lanowner,
318 : : Anum_pg_language_lanacl,
319 : : OBJECT_LANGUAGE,
320 : : true
321 : : },
322 : : {
323 : : "large object metadata",
324 : : LargeObjectMetadataRelationId,
325 : : LargeObjectMetadataOidIndexId,
326 : : SYSCACHEID_INVALID,
327 : : SYSCACHEID_INVALID,
328 : : Anum_pg_largeobject_metadata_oid,
329 : : InvalidAttrNumber,
330 : : InvalidAttrNumber,
331 : : Anum_pg_largeobject_metadata_lomowner,
332 : : Anum_pg_largeobject_metadata_lomacl,
333 : : OBJECT_LARGEOBJECT,
334 : : false
335 : : },
336 : : {
337 : : "operator class",
338 : : OperatorClassRelationId,
339 : : OpclassOidIndexId,
340 : : CLAOID,
341 : : SYSCACHEID_INVALID, /* CLAAMNAMENSP also takes opcmethod */
342 : : Anum_pg_opclass_oid,
343 : : Anum_pg_opclass_opcname,
344 : : Anum_pg_opclass_opcnamespace,
345 : : Anum_pg_opclass_opcowner,
346 : : InvalidAttrNumber,
347 : : OBJECT_OPCLASS,
348 : : true
349 : : },
350 : : {
351 : : "operator",
352 : : OperatorRelationId,
353 : : OperatorOidIndexId,
354 : : OPEROID,
355 : : SYSCACHEID_INVALID, /* OPERNAMENSP also takes left and right type */
356 : : Anum_pg_operator_oid,
357 : : Anum_pg_operator_oprname,
358 : : Anum_pg_operator_oprnamespace,
359 : : Anum_pg_operator_oprowner,
360 : : InvalidAttrNumber,
361 : : OBJECT_OPERATOR,
362 : : false
363 : : },
364 : : {
365 : : "operator family",
366 : : OperatorFamilyRelationId,
367 : : OpfamilyOidIndexId,
368 : : OPFAMILYOID,
369 : : SYSCACHEID_INVALID, /* OPFAMILYAMNAMENSP also takes opfmethod */
370 : : Anum_pg_opfamily_oid,
371 : : Anum_pg_opfamily_opfname,
372 : : Anum_pg_opfamily_opfnamespace,
373 : : Anum_pg_opfamily_opfowner,
374 : : InvalidAttrNumber,
375 : : OBJECT_OPFAMILY,
376 : : true
377 : : },
378 : : {
379 : : "property graph element",
380 : : PropgraphElementRelationId,
381 : : PropgraphElementObjectIndexId,
382 : : PROPGRAPHELOID,
383 : : PROPGRAPHELALIAS,
384 : : Anum_pg_propgraph_element_oid,
385 : : Anum_pg_propgraph_element_pgealias,
386 : : InvalidAttrNumber,
387 : : InvalidAttrNumber,
388 : : InvalidAttrNumber,
389 : : -1,
390 : : false
391 : : },
392 : : {
393 : : "property graph element label",
394 : : PropgraphElementLabelRelationId,
395 : : PropgraphElementLabelObjectIndexId,
396 : : -1,
397 : : -1,
398 : : Anum_pg_propgraph_element_label_oid,
399 : : InvalidAttrNumber,
400 : : InvalidAttrNumber,
401 : : InvalidAttrNumber,
402 : : InvalidAttrNumber,
403 : : -1,
404 : : false
405 : : },
406 : : {
407 : : "property graph label",
408 : : PropgraphLabelRelationId,
409 : : PropgraphLabelObjectIndexId,
410 : : PROPGRAPHLABELOID,
411 : : PROPGRAPHLABELNAME,
412 : : Anum_pg_propgraph_label_oid,
413 : : Anum_pg_propgraph_label_pgllabel,
414 : : InvalidAttrNumber,
415 : : InvalidAttrNumber,
416 : : InvalidAttrNumber,
417 : : -1,
418 : : false
419 : : },
420 : : {
421 : : "property graph label property",
422 : : PropgraphLabelPropertyRelationId,
423 : : PropgraphLabelPropertyObjectIndexId,
424 : : -1,
425 : : -1,
426 : : Anum_pg_propgraph_label_property_oid,
427 : : InvalidAttrNumber,
428 : : InvalidAttrNumber,
429 : : InvalidAttrNumber,
430 : : InvalidAttrNumber,
431 : : -1,
432 : : false
433 : : },
434 : : {
435 : : "property graph property",
436 : : PropgraphPropertyRelationId,
437 : : PropgraphPropertyObjectIndexId,
438 : : -1,
439 : : PROPGRAPHPROPNAME,
440 : : Anum_pg_propgraph_property_oid,
441 : : Anum_pg_propgraph_property_pgpname,
442 : : InvalidAttrNumber,
443 : : InvalidAttrNumber,
444 : : InvalidAttrNumber,
445 : : -1,
446 : : false
447 : : },
448 : : {
449 : : "role",
450 : : AuthIdRelationId,
451 : : AuthIdOidIndexId,
452 : : AUTHOID,
453 : : AUTHNAME,
454 : : Anum_pg_authid_oid,
455 : : Anum_pg_authid_rolname,
456 : : InvalidAttrNumber,
457 : : InvalidAttrNumber,
458 : : InvalidAttrNumber,
459 : : OBJECT_ROLE,
460 : : true
461 : : },
462 : : {
463 : : "role membership",
464 : : AuthMemRelationId,
465 : : AuthMemOidIndexId,
466 : : SYSCACHEID_INVALID,
467 : : SYSCACHEID_INVALID,
468 : : Anum_pg_auth_members_oid,
469 : : InvalidAttrNumber,
470 : : InvalidAttrNumber,
471 : : Anum_pg_auth_members_grantor,
472 : : InvalidAttrNumber,
473 : : -1,
474 : : true
475 : : },
476 : : {
477 : : "rule",
478 : : RewriteRelationId,
479 : : RewriteOidIndexId,
480 : : SYSCACHEID_INVALID,
481 : : SYSCACHEID_INVALID,
482 : : Anum_pg_rewrite_oid,
483 : : Anum_pg_rewrite_rulename,
484 : : InvalidAttrNumber,
485 : : InvalidAttrNumber,
486 : : InvalidAttrNumber,
487 : : OBJECT_RULE,
488 : : false
489 : : },
490 : : {
491 : : "schema",
492 : : NamespaceRelationId,
493 : : NamespaceOidIndexId,
494 : : NAMESPACEOID,
495 : : NAMESPACENAME,
496 : : Anum_pg_namespace_oid,
497 : : Anum_pg_namespace_nspname,
498 : : InvalidAttrNumber,
499 : : Anum_pg_namespace_nspowner,
500 : : Anum_pg_namespace_nspacl,
501 : : OBJECT_SCHEMA,
502 : : true
503 : : },
504 : : {
505 : : "relation",
506 : : RelationRelationId,
507 : : ClassOidIndexId,
508 : : RELOID,
509 : : RELNAMENSP,
510 : : Anum_pg_class_oid,
511 : : Anum_pg_class_relname,
512 : : Anum_pg_class_relnamespace,
513 : : Anum_pg_class_relowner,
514 : : Anum_pg_class_relacl,
515 : : OBJECT_TABLE,
516 : : true
517 : : },
518 : : {
519 : : "tablespace",
520 : : TableSpaceRelationId,
521 : : TablespaceOidIndexId,
522 : : TABLESPACEOID,
523 : : SYSCACHEID_INVALID,
524 : : Anum_pg_tablespace_oid,
525 : : Anum_pg_tablespace_spcname,
526 : : InvalidAttrNumber,
527 : : Anum_pg_tablespace_spcowner,
528 : : Anum_pg_tablespace_spcacl,
529 : : OBJECT_TABLESPACE,
530 : : true
531 : : },
532 : : {
533 : : "transform",
534 : : TransformRelationId,
535 : : TransformOidIndexId,
536 : : TRFOID,
537 : : SYSCACHEID_INVALID,
538 : : Anum_pg_transform_oid,
539 : : InvalidAttrNumber,
540 : : InvalidAttrNumber,
541 : : InvalidAttrNumber,
542 : : InvalidAttrNumber,
543 : : OBJECT_TRANSFORM,
544 : : false
545 : : },
546 : : {
547 : : "trigger",
548 : : TriggerRelationId,
549 : : TriggerOidIndexId,
550 : : SYSCACHEID_INVALID,
551 : : SYSCACHEID_INVALID,
552 : : Anum_pg_trigger_oid,
553 : : Anum_pg_trigger_tgname,
554 : : InvalidAttrNumber,
555 : : InvalidAttrNumber,
556 : : InvalidAttrNumber,
557 : : OBJECT_TRIGGER,
558 : : false
559 : : },
560 : : {
561 : : "policy",
562 : : PolicyRelationId,
563 : : PolicyOidIndexId,
564 : : SYSCACHEID_INVALID,
565 : : SYSCACHEID_INVALID,
566 : : Anum_pg_policy_oid,
567 : : Anum_pg_policy_polname,
568 : : InvalidAttrNumber,
569 : : InvalidAttrNumber,
570 : : InvalidAttrNumber,
571 : : OBJECT_POLICY,
572 : : false
573 : : },
574 : : {
575 : : "event trigger",
576 : : EventTriggerRelationId,
577 : : EventTriggerOidIndexId,
578 : : EVENTTRIGGEROID,
579 : : EVENTTRIGGERNAME,
580 : : Anum_pg_event_trigger_oid,
581 : : Anum_pg_event_trigger_evtname,
582 : : InvalidAttrNumber,
583 : : Anum_pg_event_trigger_evtowner,
584 : : InvalidAttrNumber,
585 : : OBJECT_EVENT_TRIGGER,
586 : : true
587 : : },
588 : : {
589 : : "text search configuration",
590 : : TSConfigRelationId,
591 : : TSConfigOidIndexId,
592 : : TSCONFIGOID,
593 : : TSCONFIGNAMENSP,
594 : : Anum_pg_ts_config_oid,
595 : : Anum_pg_ts_config_cfgname,
596 : : Anum_pg_ts_config_cfgnamespace,
597 : : Anum_pg_ts_config_cfgowner,
598 : : InvalidAttrNumber,
599 : : OBJECT_TSCONFIGURATION,
600 : : true
601 : : },
602 : : {
603 : : "text search dictionary",
604 : : TSDictionaryRelationId,
605 : : TSDictionaryOidIndexId,
606 : : TSDICTOID,
607 : : TSDICTNAMENSP,
608 : : Anum_pg_ts_dict_oid,
609 : : Anum_pg_ts_dict_dictname,
610 : : Anum_pg_ts_dict_dictnamespace,
611 : : Anum_pg_ts_dict_dictowner,
612 : : InvalidAttrNumber,
613 : : OBJECT_TSDICTIONARY,
614 : : true
615 : : },
616 : : {
617 : : "text search parser",
618 : : TSParserRelationId,
619 : : TSParserOidIndexId,
620 : : TSPARSEROID,
621 : : TSPARSERNAMENSP,
622 : : Anum_pg_ts_parser_oid,
623 : : Anum_pg_ts_parser_prsname,
624 : : Anum_pg_ts_parser_prsnamespace,
625 : : InvalidAttrNumber,
626 : : InvalidAttrNumber,
627 : : OBJECT_TSPARSER,
628 : : true
629 : : },
630 : : {
631 : : "text search template",
632 : : TSTemplateRelationId,
633 : : TSTemplateOidIndexId,
634 : : TSTEMPLATEOID,
635 : : TSTEMPLATENAMENSP,
636 : : Anum_pg_ts_template_oid,
637 : : Anum_pg_ts_template_tmplname,
638 : : Anum_pg_ts_template_tmplnamespace,
639 : : InvalidAttrNumber,
640 : : InvalidAttrNumber,
641 : : OBJECT_TSTEMPLATE,
642 : : true,
643 : : },
644 : : {
645 : : "type",
646 : : TypeRelationId,
647 : : TypeOidIndexId,
648 : : TYPEOID,
649 : : TYPENAMENSP,
650 : : Anum_pg_type_oid,
651 : : Anum_pg_type_typname,
652 : : Anum_pg_type_typnamespace,
653 : : Anum_pg_type_typowner,
654 : : Anum_pg_type_typacl,
655 : : OBJECT_TYPE,
656 : : true
657 : : },
658 : : {
659 : : "publication",
660 : : PublicationRelationId,
661 : : PublicationObjectIndexId,
662 : : PUBLICATIONOID,
663 : : PUBLICATIONNAME,
664 : : Anum_pg_publication_oid,
665 : : Anum_pg_publication_pubname,
666 : : InvalidAttrNumber,
667 : : Anum_pg_publication_pubowner,
668 : : InvalidAttrNumber,
669 : : OBJECT_PUBLICATION,
670 : : true
671 : : },
672 : : {
673 : : "subscription",
674 : : SubscriptionRelationId,
675 : : SubscriptionObjectIndexId,
676 : : SUBSCRIPTIONOID,
677 : : SUBSCRIPTIONNAME,
678 : : Anum_pg_subscription_oid,
679 : : Anum_pg_subscription_subname,
680 : : InvalidAttrNumber,
681 : : Anum_pg_subscription_subowner,
682 : : InvalidAttrNumber,
683 : : OBJECT_SUBSCRIPTION,
684 : : true
685 : : },
686 : : {
687 : : "extended statistics",
688 : : StatisticExtRelationId,
689 : : StatisticExtOidIndexId,
690 : : STATEXTOID,
691 : : STATEXTNAMENSP,
692 : : Anum_pg_statistic_ext_oid,
693 : : Anum_pg_statistic_ext_stxname,
694 : : Anum_pg_statistic_ext_stxnamespace,
695 : : Anum_pg_statistic_ext_stxowner,
696 : : InvalidAttrNumber, /* no ACL (same as relation) */
697 : : OBJECT_STATISTIC_EXT,
698 : : true
699 : : },
700 : : {
701 : : "user mapping",
702 : : UserMappingRelationId,
703 : : UserMappingOidIndexId,
704 : : USERMAPPINGOID,
705 : : SYSCACHEID_INVALID,
706 : : Anum_pg_user_mapping_oid,
707 : : InvalidAttrNumber,
708 : : InvalidAttrNumber,
709 : : InvalidAttrNumber,
710 : : InvalidAttrNumber,
711 : : OBJECT_USER_MAPPING,
712 : : false
713 : : },
714 : : };
715 : :
716 : : /*
717 : : * This struct maps the string object types as returned by
718 : : * getObjectTypeDescription into ObjectType enum values. Note that some enum
719 : : * values can be obtained by different names, and that some string object types
720 : : * do not have corresponding values in the output enum. The user of this map
721 : : * must be careful to test for invalid values being returned.
722 : : *
723 : : * To ease maintenance, this follows the order of getObjectTypeDescription.
724 : : */
725 : : static const struct object_type_map
726 : : {
727 : : const char *tm_name;
728 : : ObjectType tm_type;
729 : : }
730 : :
731 : : ObjectTypeMap[] =
732 : : {
733 : : {
734 : : "table", OBJECT_TABLE
735 : : },
736 : : {
737 : : "index", OBJECT_INDEX
738 : : },
739 : : {
740 : : "sequence", OBJECT_SEQUENCE
741 : : },
742 : : {
743 : : "toast table", -1
744 : : }, /* unmapped */
745 : : {
746 : : "view", OBJECT_VIEW
747 : : },
748 : : {
749 : : "materialized view", OBJECT_MATVIEW
750 : : },
751 : : {
752 : : "composite type", -1
753 : : }, /* unmapped */
754 : : {
755 : : "foreign table", OBJECT_FOREIGN_TABLE
756 : : },
757 : : {
758 : : "property graph", OBJECT_PROPGRAPH
759 : : },
760 : : {
761 : : "table column", OBJECT_COLUMN
762 : : },
763 : : {
764 : : "index column", -1
765 : : }, /* unmapped */
766 : : {
767 : : "sequence column", -1
768 : : }, /* unmapped */
769 : : {
770 : : "toast table column", -1
771 : : }, /* unmapped */
772 : : {
773 : : "view column", -1
774 : : }, /* unmapped */
775 : : {
776 : : "materialized view column", -1
777 : : }, /* unmapped */
778 : : {
779 : : "composite type column", -1
780 : : }, /* unmapped */
781 : : {
782 : : "foreign table column", OBJECT_COLUMN
783 : : },
784 : : {
785 : : "aggregate", OBJECT_AGGREGATE
786 : : },
787 : : {
788 : : "function", OBJECT_FUNCTION
789 : : },
790 : : {
791 : : "procedure", OBJECT_PROCEDURE
792 : : },
793 : : {
794 : : "type", OBJECT_TYPE
795 : : },
796 : : {
797 : : "cast", OBJECT_CAST
798 : : },
799 : : {
800 : : "collation", OBJECT_COLLATION
801 : : },
802 : : {
803 : : "table constraint", OBJECT_TABCONSTRAINT
804 : : },
805 : : {
806 : : "domain constraint", OBJECT_DOMCONSTRAINT
807 : : },
808 : : {
809 : : "conversion", OBJECT_CONVERSION
810 : : },
811 : : {
812 : : "default value", OBJECT_DEFAULT
813 : : },
814 : : {
815 : : "language", OBJECT_LANGUAGE
816 : : },
817 : : {
818 : : "large object", OBJECT_LARGEOBJECT
819 : : },
820 : : {
821 : : "operator", OBJECT_OPERATOR
822 : : },
823 : : {
824 : : "operator class", OBJECT_OPCLASS
825 : : },
826 : : {
827 : : "operator family", OBJECT_OPFAMILY
828 : : },
829 : : {
830 : : "access method", OBJECT_ACCESS_METHOD
831 : : },
832 : : {
833 : : "operator of access method", OBJECT_AMOP
834 : : },
835 : : {
836 : : "function of access method", OBJECT_AMPROC
837 : : },
838 : : {
839 : : "rule", OBJECT_RULE
840 : : },
841 : : {
842 : : "trigger", OBJECT_TRIGGER
843 : : },
844 : : {
845 : : "schema", OBJECT_SCHEMA
846 : : },
847 : : {
848 : : "text search parser", OBJECT_TSPARSER
849 : : },
850 : : {
851 : : "text search dictionary", OBJECT_TSDICTIONARY
852 : : },
853 : : {
854 : : "text search template", OBJECT_TSTEMPLATE
855 : : },
856 : : {
857 : : "text search configuration", OBJECT_TSCONFIGURATION
858 : : },
859 : : {
860 : : "role", OBJECT_ROLE
861 : : },
862 : : {
863 : : "role membership", -1 /* unmapped */
864 : : },
865 : : {
866 : : "database", OBJECT_DATABASE
867 : : },
868 : : {
869 : : "tablespace", OBJECT_TABLESPACE
870 : : },
871 : : {
872 : : "foreign-data wrapper", OBJECT_FDW
873 : : },
874 : : {
875 : : "server", OBJECT_FOREIGN_SERVER
876 : : },
877 : : {
878 : : "user mapping", OBJECT_USER_MAPPING
879 : : },
880 : : {
881 : : "default acl", OBJECT_DEFACL
882 : : },
883 : : {
884 : : "extension", OBJECT_EXTENSION
885 : : },
886 : : {
887 : : "event trigger", OBJECT_EVENT_TRIGGER
888 : : },
889 : : {
890 : : "parameter ACL", OBJECT_PARAMETER_ACL
891 : : },
892 : : {
893 : : "policy", OBJECT_POLICY
894 : : },
895 : : {
896 : : "property graph element", -1
897 : : },
898 : : {
899 : : "property graph label", -1
900 : : },
901 : : {
902 : : "property graph property", -1
903 : : },
904 : : {
905 : : "publication", OBJECT_PUBLICATION
906 : : },
907 : : {
908 : : "publication namespace", OBJECT_PUBLICATION_NAMESPACE
909 : : },
910 : : {
911 : : "publication relation", OBJECT_PUBLICATION_REL
912 : : },
913 : : {
914 : : "subscription", OBJECT_SUBSCRIPTION
915 : : },
916 : : {
917 : : "transform", OBJECT_TRANSFORM
918 : : },
919 : : {
920 : : "statistics object", OBJECT_STATISTIC_EXT
921 : : }
922 : : };
923 : :
924 : : const ObjectAddress InvalidObjectAddress =
925 : : {
926 : : InvalidOid,
927 : : InvalidOid,
928 : : 0
929 : : };
930 : :
931 : : static ObjectAddress get_object_address_unqualified(ObjectType objtype,
932 : : String *strval, bool missing_ok);
933 : : static ObjectAddress get_relation_by_qualified_name(ObjectType objtype,
934 : : List *object, Relation *relp,
935 : : LOCKMODE lockmode, bool missing_ok);
936 : : static ObjectAddress get_object_address_relobject(ObjectType objtype,
937 : : List *object, Relation *relp, bool missing_ok);
938 : : static ObjectAddress get_object_address_attribute(ObjectType objtype,
939 : : List *object, Relation *relp,
940 : : LOCKMODE lockmode, bool missing_ok);
941 : : static ObjectAddress get_object_address_attrdef(ObjectType objtype,
942 : : List *object, Relation *relp, LOCKMODE lockmode,
943 : : bool missing_ok);
944 : : static ObjectAddress get_object_address_type(ObjectType objtype,
945 : : TypeName *typename, bool missing_ok);
946 : : static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object,
947 : : bool missing_ok);
948 : : static ObjectAddress get_object_address_opf_member(ObjectType objtype,
949 : : List *object, bool missing_ok);
950 : :
951 : : static ObjectAddress get_object_address_usermapping(List *object,
952 : : bool missing_ok);
953 : : static ObjectAddress get_object_address_publication_rel(List *object,
954 : : Relation *relp,
955 : : bool missing_ok);
956 : : static ObjectAddress get_object_address_publication_schema(List *object,
957 : : bool missing_ok);
958 : : static ObjectAddress get_object_address_defacl(List *object,
959 : : bool missing_ok);
960 : : static const ObjectPropertyType *get_object_property_data(Oid class_id);
961 : :
962 : : static void getRelationDescription(StringInfo buffer, Oid relid,
963 : : bool missing_ok);
964 : : static void getOpFamilyDescription(StringInfo buffer, Oid opfid,
965 : : bool missing_ok);
966 : : static void getRelationTypeDescription(StringInfo buffer, Oid relid,
967 : : int32 objectSubId, bool missing_ok);
968 : : static void getProcedureTypeDescription(StringInfo buffer, Oid procid,
969 : : bool missing_ok);
970 : : static void getConstraintTypeDescription(StringInfo buffer, Oid constroid,
971 : : bool missing_ok);
972 : : static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object,
973 : : bool missing_ok);
974 : : static void getRelationIdentity(StringInfo buffer, Oid relid, List **object,
975 : : bool missing_ok);
976 : :
977 : : /*
978 : : * Translate an object name and arguments (as passed by the parser) to an
979 : : * ObjectAddress.
980 : : *
981 : : * The returned object will be locked using the specified lockmode. If a
982 : : * sub-object is looked up, the parent object will be locked instead.
983 : : *
984 : : * If the object is a relation or a child object of a relation (e.g. an
985 : : * attribute or constraint), the relation is also opened and *relp receives
986 : : * the open relcache entry pointer; otherwise, *relp is set to NULL.
987 : : * (relp can be NULL if the caller never passes a relation-related object.) This
988 : : * is a bit grotty but it makes life simpler, since the caller will
989 : : * typically need the relcache entry too. Caller must close the relcache
990 : : * entry when done with it. The relation is locked with the specified lockmode
991 : : * if the target object is the relation itself or an attribute, but for other
992 : : * child objects, only AccessShareLock is acquired on the relation.
993 : : *
994 : : * If the object is not found, an error is thrown, unless missing_ok is
995 : : * true. In this case, no lock is acquired, relp is set to NULL, and the
996 : : * returned address has objectId set to InvalidOid.
997 : : *
998 : : * We don't currently provide a function to release the locks acquired here;
999 : : * typically, the lock must be held until commit to guard against a concurrent
1000 : : * drop operation.
1001 : : *
1002 : : * Note: If the object is not found, we don't give any indication of the
1003 : : * reason. (It might have been a missing schema if the name was qualified, or
1004 : : * a nonexistent type name in case of a cast, function or operator; etc).
1005 : : * Currently there is only one caller that might be interested in such info, so
1006 : : * we don't spend much effort here. If more callers start to care, it might be
1007 : : * better to add some support for that in this function.
1008 : : */
1009 : : ObjectAddress
3486 peter_e@gmx.net 1010 :CBC 15072 : get_object_address(ObjectType objtype, Node *object,
1011 : : Relation *relp, LOCKMODE lockmode, bool missing_ok)
1012 : : {
1290 peter@eisentraut.org 1013 : 15072 : ObjectAddress address = {InvalidOid, InvalidOid, 0};
5308 rhaas@postgresql.org 1014 : 15072 : ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
5529 bruce@momjian.us 1015 : 15072 : Relation relation = NULL;
1016 : : uint64 inval_count;
1017 : :
1018 : : /* Some kind of lock must be taken. */
5755 rhaas@postgresql.org 1019 [ + - ]: 15072 : Assert(lockmode != NoLock);
1020 : :
1021 : : for (;;)
1022 : : {
1023 : : /*
1024 : : * Remember this value, so that, after looking up the object name and
1025 : : * locking it, we can check whether any invalidation messages have
1026 : : * been processed that might require a do-over.
1027 : : */
5308 1028 : 15206 : inval_count = SharedInvalidMessageCounter;
1029 : :
1030 : : /* Look up object address. */
1031 : 15206 : switch (objtype)
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ - ]
1032 : : {
1033 : 473 : case OBJECT_INDEX:
1034 : : case OBJECT_SEQUENCE:
1035 : : case OBJECT_TABLE:
1036 : : case OBJECT_VIEW:
1037 : : case OBJECT_MATVIEW:
1038 : : case OBJECT_FOREIGN_TABLE:
1039 : : case OBJECT_PROPGRAPH:
1040 : : address =
3486 peter_e@gmx.net 1041 : 473 : get_relation_by_qualified_name(objtype, castNode(List, object),
1042 : : &relation, lockmode,
1043 : : missing_ok);
5308 rhaas@postgresql.org 1044 : 284 : break;
1290 peter@eisentraut.org 1045 : 216 : case OBJECT_ATTRIBUTE:
1046 : : case OBJECT_COLUMN:
1047 : : address =
3486 peter_e@gmx.net 1048 : 216 : get_object_address_attribute(objtype, castNode(List, object),
1049 : : &relation, lockmode,
1050 : : missing_ok);
5308 rhaas@postgresql.org 1051 : 155 : break;
4176 alvherre@alvh.no-ip. 1052 : 32 : case OBJECT_DEFAULT:
1053 : : address =
3486 peter_e@gmx.net 1054 : 32 : get_object_address_attrdef(objtype, castNode(List, object),
1055 : : &relation, lockmode,
1056 : : missing_ok);
4176 alvherre@alvh.no-ip. 1057 : 8 : break;
5308 rhaas@postgresql.org 1058 : 1183 : case OBJECT_RULE:
1059 : : case OBJECT_TRIGGER:
1060 : : case OBJECT_TABCONSTRAINT:
1061 : : case OBJECT_POLICY:
3486 peter_e@gmx.net 1062 : 1183 : address = get_object_address_relobject(objtype, castNode(List, object),
1063 : : &relation, missing_ok);
5308 rhaas@postgresql.org 1064 : 1023 : break;
4176 alvherre@alvh.no-ip. 1065 : 48 : case OBJECT_DOMCONSTRAINT:
1066 : : {
1067 : : List *objlist;
1068 : : ObjectAddress domaddr;
1069 : : char *constrname;
1070 : :
3486 peter_e@gmx.net 1071 : 48 : objlist = castNode(List, object);
4093 alvherre@alvh.no-ip. 1072 : 48 : domaddr = get_object_address_type(OBJECT_DOMAIN,
3265 tgl@sss.pgh.pa.us 1073 : 48 : linitial_node(TypeName, objlist),
1074 : : missing_ok);
3486 peter_e@gmx.net 1075 : 40 : constrname = strVal(lsecond(objlist));
1076 : :
4176 alvherre@alvh.no-ip. 1077 : 40 : address.classId = ConstraintRelationId;
1078 : 40 : address.objectId = get_domain_constraint_oid(domaddr.objectId,
1079 : : constrname, missing_ok);
1080 : 36 : address.objectSubId = 0;
1081 : : }
1082 : 36 : break;
5308 rhaas@postgresql.org 1083 : 2858 : case OBJECT_DATABASE:
1084 : : case OBJECT_EXTENSION:
1085 : : case OBJECT_TABLESPACE:
1086 : : case OBJECT_ROLE:
1087 : : case OBJECT_SCHEMA:
1088 : : case OBJECT_LANGUAGE:
1089 : : case OBJECT_FDW:
1090 : : case OBJECT_FOREIGN_SERVER:
1091 : : case OBJECT_EVENT_TRIGGER:
1092 : : case OBJECT_PARAMETER_ACL:
1093 : : case OBJECT_ACCESS_METHOD:
1094 : : case OBJECT_PUBLICATION:
1095 : : case OBJECT_SUBSCRIPTION:
1096 : 2858 : address = get_object_address_unqualified(objtype,
1724 peter@eisentraut.org 1097 : 2858 : castNode(String, object), missing_ok);
5308 rhaas@postgresql.org 1098 : 2769 : break;
1099 : 1257 : case OBJECT_TYPE:
1100 : : case OBJECT_DOMAIN:
3486 peter_e@gmx.net 1101 : 1257 : address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
5308 rhaas@postgresql.org 1102 : 1209 : break;
1103 : 4065 : case OBJECT_AGGREGATE:
1104 : : case OBJECT_FUNCTION:
1105 : : case OBJECT_PROCEDURE:
1106 : : case OBJECT_ROUTINE:
3440 peter_e@gmx.net 1107 : 4065 : address.classId = ProcedureRelationId;
3103 1108 : 4065 : address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
3440 1109 : 3871 : address.objectSubId = 0;
1110 : 3871 : break;
5308 rhaas@postgresql.org 1111 : 215 : case OBJECT_OPERATOR:
3440 peter_e@gmx.net 1112 : 215 : address.classId = OperatorRelationId;
1113 : 215 : address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1114 : 175 : address.objectSubId = 0;
1115 : 175 : break;
5308 rhaas@postgresql.org 1116 : 103 : case OBJECT_COLLATION:
1117 : 103 : address.classId = CollationRelationId;
3486 peter_e@gmx.net 1118 : 103 : address.objectId = get_collation_oid(castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1119 : 95 : address.objectSubId = 0;
1120 : 95 : break;
1121 : 120 : case OBJECT_CONVERSION:
1122 : 120 : address.classId = ConversionRelationId;
3486 peter_e@gmx.net 1123 : 120 : address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1124 : 88 : address.objectSubId = 0;
1125 : 88 : break;
1126 : 297 : case OBJECT_OPCLASS:
1127 : : case OBJECT_OPFAMILY:
3486 peter_e@gmx.net 1128 : 297 : address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
4093 alvherre@alvh.no-ip. 1129 : 241 : break;
1130 : 32 : case OBJECT_AMOP:
1131 : : case OBJECT_AMPROC:
3486 peter_e@gmx.net 1132 : 32 : address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1133 : 16 : break;
1134 : 118 : case OBJECT_LARGEOBJECT:
1135 : 118 : address.classId = LargeObjectRelationId;
3486 peter_e@gmx.net 1136 : 118 : address.objectId = oidparse(object);
5308 rhaas@postgresql.org 1137 : 114 : address.objectSubId = 0;
1138 [ + + ]: 114 : if (!LargeObjectExists(address.objectId))
1139 : : {
1140 [ + + ]: 22 : if (!missing_ok)
5102 bruce@momjian.us 1141 [ + - ]: 12 : ereport(ERROR,
1142 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1143 : : errmsg("large object %u does not exist",
1144 : : address.objectId)));
1145 : : }
5308 rhaas@postgresql.org 1146 : 102 : break;
1147 : 54 : case OBJECT_CAST:
1148 : : {
3337 tgl@sss.pgh.pa.us 1149 : 54 : TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1150 : 54 : TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1151 : : Oid sourcetypeid;
1152 : : Oid targettypeid;
1153 : :
4510 alvherre@alvh.no-ip. 1154 : 54 : sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1155 : 50 : targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
5308 rhaas@postgresql.org 1156 : 50 : address.classId = CastRelationId;
1157 : 46 : address.objectId =
1158 : 50 : get_cast_oid(sourcetypeid, targettypeid, missing_ok);
1159 : 46 : address.objectSubId = 0;
1160 : : }
1161 : 46 : break;
4052 peter_e@gmx.net 1162 : 28 : case OBJECT_TRANSFORM:
1163 : : {
3337 tgl@sss.pgh.pa.us 1164 : 28 : TypeName *typename = linitial_node(TypeName, castNode(List, object));
3486 peter_e@gmx.net 1165 : 28 : char *langname = strVal(lsecond(castNode(List, object)));
4052 1166 : 28 : Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1167 : 23 : Oid lang_id = get_language_oid(langname, missing_ok);
1168 : :
1169 : 22 : address.classId = TransformRelationId;
1170 : 22 : address.objectId =
1171 : 22 : get_transform_oid(type_id, lang_id, missing_ok);
1172 : 22 : address.objectSubId = 0;
1173 : : }
1174 : 22 : break;
5308 rhaas@postgresql.org 1175 : 65 : case OBJECT_TSPARSER:
1176 : 65 : address.classId = TSParserRelationId;
3486 peter_e@gmx.net 1177 : 65 : address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1178 : 37 : address.objectSubId = 0;
1179 : 37 : break;
1180 : 1815 : case OBJECT_TSDICTIONARY:
1181 : 1815 : address.classId = TSDictionaryRelationId;
3486 peter_e@gmx.net 1182 : 1815 : address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1183 : 1787 : address.objectSubId = 0;
1184 : 1787 : break;
1185 : 121 : case OBJECT_TSTEMPLATE:
1186 : 121 : address.classId = TSTemplateRelationId;
3486 peter_e@gmx.net 1187 : 121 : address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1188 : 93 : address.objectSubId = 0;
1189 : 93 : break;
1190 : 1812 : case OBJECT_TSCONFIGURATION:
1191 : 1812 : address.classId = TSConfigRelationId;
3486 peter_e@gmx.net 1192 : 1812 : address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
5308 rhaas@postgresql.org 1193 : 1784 : address.objectSubId = 0;
1194 : 1784 : break;
4098 alvherre@alvh.no-ip. 1195 : 13 : case OBJECT_USER_MAPPING:
3486 peter_e@gmx.net 1196 : 13 : address = get_object_address_usermapping(castNode(List, object),
1197 : : missing_ok);
4098 alvherre@alvh.no-ip. 1198 : 9 : break;
1676 akapila@postgresql.o 1199 : 13 : case OBJECT_PUBLICATION_NAMESPACE:
1200 : 13 : address = get_object_address_publication_schema(castNode(List, object),
1201 : : missing_ok);
1202 : 9 : break;
3418 peter_e@gmx.net 1203 : 20 : case OBJECT_PUBLICATION_REL:
3486 1204 : 20 : address = get_object_address_publication_rel(castNode(List, object),
1205 : : &relation,
1206 : : missing_ok);
3415 1207 : 8 : break;
4098 alvherre@alvh.no-ip. 1208 : 28 : case OBJECT_DEFACL:
3486 peter_e@gmx.net 1209 : 28 : address = get_object_address_defacl(castNode(List, object),
1210 : : missing_ok);
4098 alvherre@alvh.no-ip. 1211 : 16 : break;
3354 1212 : 220 : case OBJECT_STATISTIC_EXT:
1213 : 220 : address.classId = StatisticExtRelationId;
3303 tgl@sss.pgh.pa.us 1214 : 220 : address.objectId = get_statistics_object_oid(castNode(List, object),
1215 : : missing_ok);
3354 alvherre@alvh.no-ip. 1216 : 216 : address.objectSubId = 0;
1217 : 216 : break;
1218 : : /* no default, to let compiler warn about missing case */
1219 : : }
1220 : :
1290 peter@eisentraut.org 1221 [ - + ]: 14099 : if (!address.classId)
1290 peter@eisentraut.org 1222 [ # # ]:UBC 0 : elog(ERROR, "unrecognized object type: %d", (int) objtype);
1223 : :
1224 : : /*
1225 : : * If we could not find the supplied object, return without locking.
1226 : : */
5308 rhaas@postgresql.org 1227 [ + + ]:CBC 14099 : if (!OidIsValid(address.objectId))
1228 : : {
1229 [ - + ]: 382 : Assert(missing_ok);
1230 : 382 : return address;
1231 : : }
1232 : :
1233 : : /*
1234 : : * If we're retrying, see if we got the same answer as last time. If
1235 : : * so, we're done; if not, we locked the wrong thing, so give up our
1236 : : * lock.
1237 : : */
1238 [ + + ]: 13717 : if (OidIsValid(old_address.classId))
1239 : : {
1240 [ + - ]: 134 : if (old_address.classId == address.classId
1241 [ + - ]: 134 : && old_address.objectId == address.objectId
1242 [ + - ]: 134 : && old_address.objectSubId == address.objectSubId)
1243 : 134 : break;
5308 rhaas@postgresql.org 1244 [ # # ]:UBC 0 : if (old_address.classId != RelationRelationId)
1245 : : {
1246 [ # # ]: 0 : if (IsSharedRelation(old_address.classId))
1247 : 0 : UnlockSharedObject(old_address.classId,
1248 : : old_address.objectId,
1249 : : 0, lockmode);
1250 : : else
1251 : 0 : UnlockDatabaseObject(old_address.classId,
1252 : : old_address.objectId,
1253 : : 0, lockmode);
1254 : : }
1255 : : }
1256 : :
1257 : : /*
1258 : : * If we're dealing with a relation or attribute, then the relation is
1259 : : * already locked. Otherwise, we lock it now.
1260 : : */
5308 rhaas@postgresql.org 1261 [ + + ]:CBC 13583 : if (address.classId != RelationRelationId)
1262 : : {
1263 [ + + ]: 13144 : if (IsSharedRelation(address.classId))
1264 : 428 : LockSharedObject(address.classId, address.objectId, 0,
1265 : : lockmode);
1266 : : else
1267 : 12716 : LockDatabaseObject(address.classId, address.objectId, 0,
1268 : : lockmode);
1269 : : }
1270 : :
1271 : : /*
1272 : : * At this point, we've resolved the name to an OID and locked the
1273 : : * corresponding database object. However, it's possible that by the
1274 : : * time we acquire the lock on the object, concurrent DDL has modified
1275 : : * the database in such a way that the name we originally looked up no
1276 : : * longer resolves to that OID.
1277 : : *
1278 : : * We can be certain that this isn't an issue if (a) no shared
1279 : : * invalidation messages have been processed or (b) we've locked a
1280 : : * relation somewhere along the line. All the relation name lookups
1281 : : * in this module ultimately use RangeVarGetRelid() to acquire a
1282 : : * relation lock, and that function protects against the same kinds of
1283 : : * races we're worried about here. Even when operating on a
1284 : : * constraint, rule, or trigger, we still acquire AccessShareLock on
1285 : : * the relation, which is enough to freeze out any concurrent DDL.
1286 : : *
1287 : : * In all other cases, however, it's possible that the name we looked
1288 : : * up no longer refers to the object we locked, so we retry the lookup
1289 : : * and see whether we get the same answer.
1290 : : */
5102 bruce@momjian.us 1291 [ + + + + ]: 13583 : if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1292 : : break;
1293 : 134 : old_address = address;
1294 : : }
1295 : :
1296 : : /* relp must be given if it's a relation */
561 peter@eisentraut.org 1297 [ + + - + ]: 13583 : Assert(!relation || relp);
1298 : :
1299 : : /* Return the object address and the relation. */
1300 [ + + ]: 13583 : if (relp)
1301 : 11040 : *relp = relation;
5755 rhaas@postgresql.org 1302 : 13583 : return address;
1303 : : }
1304 : :
1305 : : /*
1306 : : * Return an ObjectAddress based on a RangeVar and an object name. The
1307 : : * name of the relation identified by the RangeVar is prepended to the
1308 : : * (possibly empty) list passed in as object. This is useful to find
1309 : : * the ObjectAddress of objects that depend on a relation. All other
1310 : : * considerations are exactly as for get_object_address above.
1311 : : */
1312 : : ObjectAddress
3486 peter_e@gmx.net 1313 : 68 : get_object_address_rv(ObjectType objtype, RangeVar *rel, List *object,
1314 : : Relation *relp, LOCKMODE lockmode,
1315 : : bool missing_ok)
1316 : : {
3707 alvherre@alvh.no-ip. 1317 [ + + ]: 68 : if (rel)
1318 : : {
3486 peter_e@gmx.net 1319 : 62 : object = lcons(makeString(rel->relname), object);
3707 alvherre@alvh.no-ip. 1320 [ + + ]: 62 : if (rel->schemaname)
3486 peter_e@gmx.net 1321 : 15 : object = lcons(makeString(rel->schemaname), object);
3707 alvherre@alvh.no-ip. 1322 [ - + ]: 62 : if (rel->catalogname)
3486 peter_e@gmx.net 1323 :UBC 0 : object = lcons(makeString(rel->catalogname), object);
1324 : : }
1325 : :
3486 peter_e@gmx.net 1326 :CBC 68 : return get_object_address(objtype, (Node *) object,
1327 : : relp, lockmode, missing_ok);
1328 : : }
1329 : :
1330 : : /*
1331 : : * Find an ObjectAddress for a type of object that is identified by an
1332 : : * unqualified name.
1333 : : */
1334 : : static ObjectAddress
5451 rhaas@postgresql.org 1335 : 2858 : get_object_address_unqualified(ObjectType objtype,
1336 : : String *strval, bool missing_ok)
1337 : : {
1338 : : const char *name;
1339 : : ObjectAddress address;
1340 : :
3486 peter_e@gmx.net 1341 : 2858 : name = strVal(strval);
1342 : :
1343 : : /* Translate name to OID. */
5755 rhaas@postgresql.org 1344 : 2858 : switch (objtype)
[ + + + +
+ + + + +
+ + + +
- ]
1345 : : {
3720 alvherre@alvh.no-ip. 1346 : 49 : case OBJECT_ACCESS_METHOD:
1347 : 49 : address.classId = AccessMethodRelationId;
1348 : 49 : address.objectId = get_am_oid(name, missing_ok);
1349 : 41 : address.objectSubId = 0;
1350 : 41 : break;
5755 rhaas@postgresql.org 1351 : 352 : case OBJECT_DATABASE:
1352 : 352 : address.classId = DatabaseRelationId;
5451 1353 : 352 : address.objectId = get_database_oid(name, missing_ok);
5755 1354 : 348 : address.objectSubId = 0;
1355 : 348 : break;
5590 tgl@sss.pgh.pa.us 1356 : 277 : case OBJECT_EXTENSION:
1357 : 277 : address.classId = ExtensionRelationId;
5451 rhaas@postgresql.org 1358 : 277 : address.objectId = get_extension_oid(name, missing_ok);
5590 tgl@sss.pgh.pa.us 1359 : 269 : address.objectSubId = 0;
1360 : 269 : break;
5755 rhaas@postgresql.org 1361 : 11 : case OBJECT_TABLESPACE:
1362 : 11 : address.classId = TableSpaceRelationId;
5451 1363 : 11 : address.objectId = get_tablespace_oid(name, missing_ok);
5755 1364 : 7 : address.objectSubId = 0;
1365 : 7 : break;
1366 : 40 : case OBJECT_ROLE:
1367 : 40 : address.classId = AuthIdRelationId;
5451 1368 : 40 : address.objectId = get_role_oid(name, missing_ok);
5755 1369 : 35 : address.objectSubId = 0;
1370 : 35 : break;
1371 : 897 : case OBJECT_SCHEMA:
1372 : 897 : address.classId = NamespaceRelationId;
5451 1373 : 897 : address.objectId = get_namespace_oid(name, missing_ok);
5755 1374 : 885 : address.objectSubId = 0;
1375 : 885 : break;
1376 : 224 : case OBJECT_LANGUAGE:
1377 : 224 : address.classId = LanguageRelationId;
5451 1378 : 224 : address.objectId = get_language_oid(name, missing_ok);
5755 1379 : 216 : address.objectSubId = 0;
1380 : 216 : break;
5538 1381 : 215 : case OBJECT_FDW:
1382 : 215 : address.classId = ForeignDataWrapperRelationId;
5451 1383 : 215 : address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
5538 1384 : 203 : address.objectSubId = 0;
1385 : 203 : break;
1386 : 204 : case OBJECT_FOREIGN_SERVER:
1387 : 204 : address.classId = ForeignServerRelationId;
5451 1388 : 204 : address.objectId = get_foreign_server_oid(name, missing_ok);
5538 1389 : 192 : address.objectSubId = 0;
1390 : 192 : break;
5064 1391 : 112 : case OBJECT_EVENT_TRIGGER:
1392 : 112 : address.classId = EventTriggerRelationId;
1393 : 112 : address.objectId = get_event_trigger_oid(name, missing_ok);
1394 : 104 : address.objectSubId = 0;
1395 : 104 : break;
1515 tgl@sss.pgh.pa.us 1396 : 1 : case OBJECT_PARAMETER_ACL:
1397 : 1 : address.classId = ParameterAclRelationId;
1398 : 1 : address.objectId = ParameterAclLookup(name, missing_ok);
1399 : 1 : address.objectSubId = 0;
1400 : 1 : break;
3418 peter_e@gmx.net 1401 : 433 : case OBJECT_PUBLICATION:
1402 : 433 : address.classId = PublicationRelationId;
1403 : 433 : address.objectId = get_publication_oid(name, missing_ok);
1404 : 429 : address.objectSubId = 0;
1405 : 429 : break;
1406 : 43 : case OBJECT_SUBSCRIPTION:
1407 : 43 : address.classId = SubscriptionRelationId;
1408 : 43 : address.objectId = get_subscription_oid(name, missing_ok);
1409 : 39 : address.objectSubId = 0;
1410 : 39 : break;
5755 rhaas@postgresql.org 1411 :UBC 0 : default:
1299 peter@eisentraut.org 1412 [ # # ]: 0 : elog(ERROR, "unrecognized object type: %d", (int) objtype);
1413 : : /* placate compiler, which doesn't know elog won't return */
1414 : : address.classId = InvalidOid;
1415 : : address.objectId = InvalidOid;
1416 : : address.objectSubId = 0;
1417 : : }
1418 : :
5755 rhaas@postgresql.org 1419 :CBC 2769 : return address;
1420 : : }
1421 : :
1422 : : /*
1423 : : * Locate a relation by qualified name.
1424 : : */
1425 : : static ObjectAddress
3486 peter_e@gmx.net 1426 : 473 : get_relation_by_qualified_name(ObjectType objtype, List *object,
1427 : : Relation *relp, LOCKMODE lockmode,
1428 : : bool missing_ok)
1429 : : {
1430 : : Relation relation;
1431 : : ObjectAddress address;
1432 : :
5451 rhaas@postgresql.org 1433 : 473 : address.classId = RelationRelationId;
1434 : 473 : address.objectId = InvalidOid;
1435 : 473 : address.objectSubId = 0;
1436 : :
3486 peter_e@gmx.net 1437 : 473 : relation = relation_openrv_extended(makeRangeVarFromNameList(object),
1438 : : lockmode, missing_ok);
5451 rhaas@postgresql.org 1439 [ - + ]: 284 : if (!relation)
5451 rhaas@postgresql.org 1440 :UBC 0 : return address;
1441 : :
5755 rhaas@postgresql.org 1442 [ + + + + :CBC 284 : switch (objtype)
+ + - ][ +
+ + + + +
+ - ]
1443 : : {
1444 : 90 : case OBJECT_INDEX:
3053 alvherre@alvh.no-ip. 1445 [ + + ]: 90 : if (relation->rd_rel->relkind != RELKIND_INDEX &&
1446 [ - + ]: 12 : relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
5755 rhaas@postgresql.org 1447 [ # # ]:UBC 0 : ereport(ERROR,
1448 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1449 : : errmsg("\"%s\" is not an index",
1450 : : RelationGetRelationName(relation))));
5755 rhaas@postgresql.org 1451 :CBC 90 : break;
75 peter@eisentraut.org 1452 :GNC 45 : case OBJECT_PROPGRAPH:
1453 [ - + ]: 45 : if (relation->rd_rel->relkind != RELKIND_PROPGRAPH)
75 peter@eisentraut.org 1454 [ # # ]:UNC 0 : ereport(ERROR,
1455 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1456 : : errmsg("\"%s\" is not a property graph",
1457 : : RelationGetRelationName(relation))));
75 peter@eisentraut.org 1458 :GNC 45 : break;
5755 rhaas@postgresql.org 1459 :CBC 18 : case OBJECT_SEQUENCE:
1460 [ - + ]: 18 : if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
5755 rhaas@postgresql.org 1461 [ # # ]:UBC 0 : ereport(ERROR,
1462 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1463 : : errmsg("\"%s\" is not a sequence",
1464 : : RelationGetRelationName(relation))));
5755 rhaas@postgresql.org 1465 :CBC 18 : break;
1466 : 49 : case OBJECT_TABLE:
3461 1467 [ + + ]: 49 : if (relation->rd_rel->relkind != RELKIND_RELATION &&
1468 [ - + ]: 12 : relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
5755 rhaas@postgresql.org 1469 [ # # ]:UBC 0 : ereport(ERROR,
1470 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1471 : : errmsg("\"%s\" is not a table",
1472 : : RelationGetRelationName(relation))));
5755 rhaas@postgresql.org 1473 :CBC 49 : break;
1474 : 45 : case OBJECT_VIEW:
1475 [ - + ]: 45 : if (relation->rd_rel->relkind != RELKIND_VIEW)
5755 rhaas@postgresql.org 1476 [ # # ]:UBC 0 : ereport(ERROR,
1477 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1478 : : errmsg("\"%s\" is not a view",
1479 : : RelationGetRelationName(relation))));
5755 rhaas@postgresql.org 1480 :CBC 45 : break;
4836 kgrittn@postgresql.o 1481 : 15 : case OBJECT_MATVIEW:
1482 [ - + ]: 15 : if (relation->rd_rel->relkind != RELKIND_MATVIEW)
4836 kgrittn@postgresql.o 1483 [ # # ]:UBC 0 : ereport(ERROR,
1484 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1485 : : errmsg("\"%s\" is not a materialized view",
1486 : : RelationGetRelationName(relation))));
4836 kgrittn@postgresql.o 1487 :CBC 15 : break;
5628 rhaas@postgresql.org 1488 : 22 : case OBJECT_FOREIGN_TABLE:
1489 [ - + ]: 22 : if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
5628 rhaas@postgresql.org 1490 [ # # ]:UBC 0 : ereport(ERROR,
1491 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1492 : : errmsg("\"%s\" is not a foreign table",
1493 : : RelationGetRelationName(relation))));
5628 rhaas@postgresql.org 1494 :CBC 22 : break;
5755 rhaas@postgresql.org 1495 :UBC 0 : default:
1299 peter@eisentraut.org 1496 [ # # ]: 0 : elog(ERROR, "unrecognized object type: %d", (int) objtype);
1497 : : break;
1498 : : }
1499 : :
1500 : : /* Done. */
5451 rhaas@postgresql.org 1501 :CBC 284 : address.objectId = RelationGetRelid(relation);
1502 : 284 : *relp = relation;
1503 : :
1504 : 284 : return address;
1505 : : }
1506 : :
1507 : : /*
1508 : : * Find object address for an object that is attached to a relation.
1509 : : *
1510 : : * Note that we take only an AccessShareLock on the relation. We need not
1511 : : * pass down the LOCKMODE from get_object_address(), because that is the lock
1512 : : * mode for the object itself, not the relation to which it is attached.
1513 : : */
1514 : : static ObjectAddress
3486 peter_e@gmx.net 1515 : 1183 : get_object_address_relobject(ObjectType objtype, List *object,
1516 : : Relation *relp, bool missing_ok)
1517 : : {
1518 : : ObjectAddress address;
5755 rhaas@postgresql.org 1519 : 1183 : Relation relation = NULL;
1520 : : int nnames;
1521 : : const char *depname;
1522 : : List *relname;
1523 : : Oid reloid;
1524 : :
1525 : : /* Extract name of dependent object. */
3486 peter_e@gmx.net 1526 : 1183 : depname = strVal(llast(object));
1527 : :
1528 : : /* Separate relation name from dependent object name. */
1529 : 1183 : nnames = list_length(object);
5755 rhaas@postgresql.org 1530 [ + + ]: 1183 : if (nnames < 2)
3384 peter_e@gmx.net 1531 [ + - ]: 32 : ereport(ERROR,
1532 : : (errcode(ERRCODE_SYNTAX_ERROR),
1533 : : errmsg("must specify relation and object name")));
1534 : :
1535 : : /* Extract relation name and open relation. */
1417 drowley@postgresql.o 1536 : 1151 : relname = list_copy_head(object, nnames - 1);
2686 andres@anarazel.de 1537 : 1151 : relation = table_openrv_extended(makeRangeVarFromNameList(relname),
1538 : : AccessShareLock,
1539 : : missing_ok);
1540 : :
3384 peter_e@gmx.net 1541 [ + + ]: 1063 : reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1542 : :
1543 [ + + + + : 1063 : switch (objtype)
- ]
1544 : : {
1545 : 193 : case OBJECT_RULE:
1546 : 193 : address.classId = RewriteRelationId;
1547 : 185 : address.objectId = relation ?
1548 [ + + ]: 193 : get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1549 : 185 : address.objectSubId = 0;
1550 : 185 : break;
1551 : 523 : case OBJECT_TRIGGER:
1552 : 523 : address.classId = TriggerRelationId;
1553 : 507 : address.objectId = relation ?
1554 [ + + ]: 523 : get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1555 : 507 : address.objectSubId = 0;
1556 : 507 : break;
1557 : 181 : case OBJECT_TABCONSTRAINT:
1558 : 181 : address.classId = ConstraintRelationId;
1559 : 173 : address.objectId = relation ?
1560 [ + - ]: 181 : get_relation_constraint_oid(reloid, depname, missing_ok) :
1561 : : InvalidOid;
1562 : 173 : address.objectSubId = 0;
1563 : 173 : break;
1564 : 166 : case OBJECT_POLICY:
1565 : 166 : address.classId = PolicyRelationId;
1566 : 158 : address.objectId = relation ?
1567 [ + - ]: 166 : get_relation_policy_oid(reloid, depname, missing_ok) :
1568 : : InvalidOid;
1569 : 158 : address.objectSubId = 0;
1570 : 158 : break;
3384 peter_e@gmx.net 1571 :UBC 0 : default:
1299 peter@eisentraut.org 1572 [ # # ]: 0 : elog(ERROR, "unrecognized object type: %d", (int) objtype);
1573 : : }
1574 : :
1575 : : /* Avoid relcache leak when object not found. */
3384 peter_e@gmx.net 1576 [ + + ]:CBC 1023 : if (!OidIsValid(address.objectId))
1577 : : {
1578 [ + + ]: 32 : if (relation != NULL)
2686 andres@anarazel.de 1579 : 8 : table_close(relation, AccessShareLock);
1580 : :
3300 bruce@momjian.us 1581 : 32 : relation = NULL; /* department of accident prevention */
3384 peter_e@gmx.net 1582 : 32 : return address;
1583 : : }
1584 : :
1585 : : /* Done. */
5755 rhaas@postgresql.org 1586 : 991 : *relp = relation;
1587 : 991 : return address;
1588 : : }
1589 : :
1590 : : /*
1591 : : * Find the ObjectAddress for an attribute.
1592 : : */
1593 : : static ObjectAddress
3486 peter_e@gmx.net 1594 : 216 : get_object_address_attribute(ObjectType objtype, List *object,
1595 : : Relation *relp, LOCKMODE lockmode,
1596 : : bool missing_ok)
1597 : : {
1598 : : ObjectAddress address;
1599 : : List *relname;
1600 : : Oid reloid;
1601 : : Relation relation;
1602 : : const char *attname;
1603 : : AttrNumber attnum;
1604 : :
1605 : : /* Extract relation name and open relation. */
1606 [ + + ]: 216 : if (list_length(object) < 2)
5121 rhaas@postgresql.org 1607 [ + - ]: 17 : ereport(ERROR,
1608 : : (errcode(ERRCODE_SYNTAX_ERROR),
1609 : : errmsg("column name must be qualified")));
2071 tgl@sss.pgh.pa.us 1610 : 199 : attname = strVal(llast(object));
1417 drowley@postgresql.o 1611 : 199 : relname = list_copy_head(object, list_length(object) - 1);
1612 : : /* XXX no missing_ok support here */
5702 rhaas@postgresql.org 1613 : 199 : relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
5755 1614 : 167 : reloid = RelationGetRelid(relation);
1615 : :
1616 : : /* Look up attribute and construct return value. */
5451 1617 : 167 : attnum = get_attnum(reloid, attname);
1618 [ + + ]: 167 : if (attnum == InvalidAttrNumber)
1619 : : {
1620 [ + - ]: 12 : if (!missing_ok)
1621 [ + - ]: 12 : ereport(ERROR,
1622 : : (errcode(ERRCODE_UNDEFINED_COLUMN),
1623 : : errmsg("column \"%s\" of relation \"%s\" does not exist",
1624 : : attname, NameListToString(relname))));
1625 : :
5451 rhaas@postgresql.org 1626 :UBC 0 : address.classId = RelationRelationId;
1627 : 0 : address.objectId = InvalidOid;
1628 : 0 : address.objectSubId = InvalidAttrNumber;
4512 1629 : 0 : relation_close(relation, lockmode);
5451 1630 : 0 : return address;
1631 : : }
1632 : :
5755 rhaas@postgresql.org 1633 :CBC 155 : address.classId = RelationRelationId;
1634 : 155 : address.objectId = reloid;
5451 1635 : 155 : address.objectSubId = attnum;
1636 : :
5755 1637 : 155 : *relp = relation;
1638 : 155 : return address;
1639 : : }
1640 : :
1641 : : /*
1642 : : * Find the ObjectAddress for an attribute's default value.
1643 : : */
1644 : : static ObjectAddress
3486 peter_e@gmx.net 1645 : 32 : get_object_address_attrdef(ObjectType objtype, List *object,
1646 : : Relation *relp, LOCKMODE lockmode,
1647 : : bool missing_ok)
1648 : : {
1649 : : ObjectAddress address;
1650 : : List *relname;
1651 : : Oid reloid;
1652 : : Relation relation;
1653 : : const char *attname;
1654 : : AttrNumber attnum;
1655 : : TupleDesc tupdesc;
1656 : : Oid defoid;
1657 : :
1658 : : /* Extract relation name and open relation. */
1659 [ + + ]: 32 : if (list_length(object) < 2)
4176 alvherre@alvh.no-ip. 1660 [ + - ]: 8 : ereport(ERROR,
1661 : : (errcode(ERRCODE_SYNTAX_ERROR),
1662 : : errmsg("column name must be qualified")));
3486 peter_e@gmx.net 1663 : 24 : attname = strVal(llast(object));
1417 drowley@postgresql.o 1664 : 24 : relname = list_copy_head(object, list_length(object) - 1);
1665 : : /* XXX no missing_ok support here */
4176 alvherre@alvh.no-ip. 1666 : 24 : relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1667 : 8 : reloid = RelationGetRelid(relation);
1668 : :
1669 : 8 : tupdesc = RelationGetDescr(relation);
1670 : :
1671 : : /* Look up attribute number and fetch the pg_attrdef OID */
1672 : 8 : attnum = get_attnum(reloid, attname);
1673 : 8 : defoid = InvalidOid;
1674 [ + - + - ]: 8 : if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1531 tgl@sss.pgh.pa.us 1675 : 8 : defoid = GetAttrDefaultOid(reloid, attnum);
4176 alvherre@alvh.no-ip. 1676 [ - + ]: 8 : if (!OidIsValid(defoid))
1677 : : {
4176 alvherre@alvh.no-ip. 1678 [ # # ]:UBC 0 : if (!missing_ok)
1679 [ # # ]: 0 : ereport(ERROR,
1680 : : (errcode(ERRCODE_UNDEFINED_COLUMN),
1681 : : errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1682 : : attname, NameListToString(relname))));
1683 : :
1684 : 0 : address.classId = AttrDefaultRelationId;
1685 : 0 : address.objectId = InvalidOid;
1686 : 0 : address.objectSubId = InvalidAttrNumber;
1687 : 0 : relation_close(relation, lockmode);
1688 : 0 : return address;
1689 : : }
1690 : :
4176 alvherre@alvh.no-ip. 1691 :CBC 8 : address.classId = AttrDefaultRelationId;
1692 : 8 : address.objectId = defoid;
1693 : 8 : address.objectSubId = 0;
1694 : :
1695 : 8 : *relp = relation;
1696 : 8 : return address;
1697 : : }
1698 : :
1699 : : /*
1700 : : * Find the ObjectAddress for a type or domain
1701 : : */
1702 : : static ObjectAddress
3486 peter_e@gmx.net 1703 : 1369 : get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
1704 : : {
1705 : : ObjectAddress address;
1706 : : Type tup;
1707 : :
5451 rhaas@postgresql.org 1708 : 1369 : address.classId = TypeRelationId;
1709 : 1369 : address.objectId = InvalidOid;
1710 : 1369 : address.objectSubId = 0;
1711 : :
4510 alvherre@alvh.no-ip. 1712 : 1369 : tup = LookupTypeName(NULL, typename, NULL, missing_ok);
5451 rhaas@postgresql.org 1713 [ + + ]: 1369 : if (!HeapTupleIsValid(tup))
1714 : : {
1715 [ + + ]: 90 : if (!missing_ok)
1716 [ + - ]: 52 : ereport(ERROR,
1717 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1718 : : errmsg("type \"%s\" does not exist",
1719 : : TypeNameToString(typename))));
1720 : 38 : return address;
1721 : : }
1722 : 1279 : address.objectId = typeTypeId(tup);
1723 : :
1724 [ + + ]: 1279 : if (objtype == OBJECT_DOMAIN)
1725 : : {
1726 [ + + ]: 468 : if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1727 [ + - ]: 4 : ereport(ERROR,
1728 : : (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1729 : : errmsg("\"%s\" is not a domain",
1730 : : TypeNameToString(typename))));
1731 : : }
1732 : :
1733 : 1275 : ReleaseSysCache(tup);
1734 : :
1735 : 1275 : return address;
1736 : : }
1737 : :
1738 : : /*
1739 : : * Find the ObjectAddress for an opclass or opfamily.
1740 : : */
1741 : : static ObjectAddress
3486 peter_e@gmx.net 1742 : 329 : get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
1743 : : {
1744 : : Oid amoid;
1745 : : ObjectAddress address;
1746 : :
1747 : : /* XXX no missing_ok support here */
1748 : 329 : amoid = get_index_am_oid(strVal(linitial(object)), false);
1749 : 281 : object = list_copy_tail(object, 1);
1750 : :
5755 rhaas@postgresql.org 1751 [ + + - ]: 281 : switch (objtype)
1752 : : {
1753 : 107 : case OBJECT_OPCLASS:
1754 : 107 : address.classId = OperatorClassRelationId;
3486 peter_e@gmx.net 1755 : 107 : address.objectId = get_opclass_oid(amoid, object, missing_ok);
5755 rhaas@postgresql.org 1756 : 103 : address.objectSubId = 0;
1757 : 103 : break;
1758 : 174 : case OBJECT_OPFAMILY:
1759 : 174 : address.classId = OperatorFamilyRelationId;
3486 peter_e@gmx.net 1760 : 174 : address.objectId = get_opfamily_oid(amoid, object, missing_ok);
5755 rhaas@postgresql.org 1761 : 170 : address.objectSubId = 0;
1762 : 170 : break;
5755 rhaas@postgresql.org 1763 :UBC 0 : default:
1299 peter@eisentraut.org 1764 [ # # ]: 0 : elog(ERROR, "unrecognized object type: %d", (int) objtype);
1765 : : /* placate compiler, which doesn't know elog won't return */
1766 : : address.classId = InvalidOid;
1767 : : address.objectId = InvalidOid;
1768 : : address.objectSubId = 0;
1769 : : }
1770 : :
5755 rhaas@postgresql.org 1771 :CBC 273 : return address;
1772 : : }
1773 : :
1774 : : /*
1775 : : * Find the ObjectAddress for an opclass/opfamily member.
1776 : : *
1777 : : * (The returned address corresponds to a pg_amop/pg_amproc object).
1778 : : */
1779 : : static ObjectAddress
4093 alvherre@alvh.no-ip. 1780 : 32 : get_object_address_opf_member(ObjectType objtype,
1781 : : List *object, bool missing_ok)
1782 : : {
1783 : : ObjectAddress famaddr;
1784 : : ObjectAddress address;
1785 : : ListCell *cell;
1786 : : List *copy;
1787 : : TypeName *typenames[2];
1788 : : Oid typeoids[2];
1789 : : int membernum;
1790 : : int i;
1791 : :
1792 : : /*
1793 : : * The last element of the object list contains the strategy or procedure
1794 : : * number. We need to strip that out before getting the opclass/family
1795 : : * address. The rest can be used directly by get_object_address_opcf().
1796 : : */
3486 peter_e@gmx.net 1797 : 32 : membernum = atoi(strVal(llast(linitial(object))));
1417 drowley@postgresql.o 1798 : 32 : copy = list_copy_head(linitial(object), list_length(linitial(object)) - 1);
1799 : :
1800 : : /* no missing_ok support here */
4093 alvherre@alvh.no-ip. 1801 : 32 : famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1802 : :
1803 : : /* find out left/right type names and OIDs */
3027 tgl@sss.pgh.pa.us 1804 : 32 : typenames[0] = typenames[1] = NULL;
1805 : 32 : typeoids[0] = typeoids[1] = InvalidOid;
4093 alvherre@alvh.no-ip. 1806 : 32 : i = 0;
3486 peter_e@gmx.net 1807 [ + - + - : 64 : foreach(cell, lsecond(object))
+ - ]
1808 : : {
1809 : : ObjectAddress typaddr;
1810 : :
3337 tgl@sss.pgh.pa.us 1811 : 64 : typenames[i] = lfirst_node(TypeName, cell);
3362 alvherre@alvh.no-ip. 1812 : 64 : typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
4093 1813 : 64 : typeoids[i] = typaddr.objectId;
1814 [ + + ]: 64 : if (++i >= 2)
1815 : 32 : break;
1816 : : }
1817 : :
1818 [ + + - ]: 32 : switch (objtype)
1819 : : {
1820 : 16 : case OBJECT_AMOP:
1821 : : {
1822 : : HeapTuple tp;
1823 : :
1824 : 16 : ObjectAddressSet(address, AccessMethodOperatorRelationId,
1825 : : InvalidOid);
1826 : :
1827 : 16 : tp = SearchSysCache4(AMOPSTRATEGY,
1828 : : ObjectIdGetDatum(famaddr.objectId),
1829 : : ObjectIdGetDatum(typeoids[0]),
1830 : : ObjectIdGetDatum(typeoids[1]),
1831 : : Int16GetDatum(membernum));
1832 [ + + ]: 16 : if (!HeapTupleIsValid(tp))
1833 : : {
1834 [ + - ]: 8 : if (!missing_ok)
1835 [ + - ]: 8 : ereport(ERROR,
1836 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1837 : : errmsg("operator %d (%s, %s) of %s does not exist",
1838 : : membernum,
1839 : : TypeNameToString(typenames[0]),
1840 : : TypeNameToString(typenames[1]),
1841 : : getObjectDescription(&famaddr, false))));
1842 : : }
1843 : : else
1844 : : {
2748 andres@anarazel.de 1845 : 8 : address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
4093 alvherre@alvh.no-ip. 1846 : 8 : ReleaseSysCache(tp);
1847 : : }
1848 : : }
1849 : 8 : break;
1850 : :
1851 : 16 : case OBJECT_AMPROC:
1852 : : {
1853 : : HeapTuple tp;
1854 : :
1855 : 16 : ObjectAddressSet(address, AccessMethodProcedureRelationId,
1856 : : InvalidOid);
1857 : :
1858 : 16 : tp = SearchSysCache4(AMPROCNUM,
1859 : : ObjectIdGetDatum(famaddr.objectId),
1860 : : ObjectIdGetDatum(typeoids[0]),
1861 : : ObjectIdGetDatum(typeoids[1]),
1862 : : Int16GetDatum(membernum));
1863 [ + + ]: 16 : if (!HeapTupleIsValid(tp))
1864 : : {
1865 [ + - ]: 8 : if (!missing_ok)
1866 [ + - ]: 8 : ereport(ERROR,
1867 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1868 : : errmsg("function %d (%s, %s) of %s does not exist",
1869 : : membernum,
1870 : : TypeNameToString(typenames[0]),
1871 : : TypeNameToString(typenames[1]),
1872 : : getObjectDescription(&famaddr, false))));
1873 : : }
1874 : : else
1875 : : {
2748 andres@anarazel.de 1876 : 8 : address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
4093 alvherre@alvh.no-ip. 1877 : 8 : ReleaseSysCache(tp);
1878 : : }
1879 : : }
1880 : 8 : break;
4093 alvherre@alvh.no-ip. 1881 :UBC 0 : default:
1299 peter@eisentraut.org 1882 [ # # ]: 0 : elog(ERROR, "unrecognized object type: %d", (int) objtype);
1883 : : }
1884 : :
4093 alvherre@alvh.no-ip. 1885 :CBC 16 : return address;
1886 : : }
1887 : :
1888 : : /*
1889 : : * Find the ObjectAddress for a user mapping.
1890 : : */
1891 : : static ObjectAddress
3486 peter_e@gmx.net 1892 : 13 : get_object_address_usermapping(List *object, bool missing_ok)
1893 : : {
1894 : : ObjectAddress address;
1895 : : Oid userid;
1896 : : char *username;
1897 : : char *servername;
1898 : : ForeignServer *server;
1899 : : HeapTuple tp;
1900 : :
4098 alvherre@alvh.no-ip. 1901 : 13 : ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1902 : :
1903 : : /* fetch string names from input lists, for error messages */
3486 peter_e@gmx.net 1904 : 13 : username = strVal(linitial(object));
1905 : 13 : servername = strVal(lsecond(object));
1906 : :
1907 : : /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
4098 alvherre@alvh.no-ip. 1908 [ - + ]: 13 : if (strcmp(username, "public") == 0)
4098 alvherre@alvh.no-ip. 1909 :UBC 0 : userid = InvalidOid;
1910 : : else
1911 : : {
4098 alvherre@alvh.no-ip. 1912 :CBC 13 : tp = SearchSysCache1(AUTHNAME,
1913 : : CStringGetDatum(username));
1914 [ + + ]: 13 : if (!HeapTupleIsValid(tp))
1915 : : {
1916 [ + - ]: 4 : if (!missing_ok)
1917 [ + - ]: 4 : ereport(ERROR,
1918 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1919 : : errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1920 : : username, servername)));
4098 alvherre@alvh.no-ip. 1921 :UBC 0 : return address;
1922 : : }
2748 andres@anarazel.de 1923 :CBC 9 : userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
4098 alvherre@alvh.no-ip. 1924 : 9 : ReleaseSysCache(tp);
1925 : : }
1926 : :
1927 : : /* Now look up the pg_user_mapping tuple */
1928 : 9 : server = GetForeignServerByName(servername, true);
1929 [ - + ]: 9 : if (!server)
1930 : : {
4098 alvherre@alvh.no-ip. 1931 [ # # ]:UBC 0 : if (!missing_ok)
1932 [ # # ]: 0 : ereport(ERROR,
1933 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1934 : : errmsg("server \"%s\" does not exist", servername)));
1935 : 0 : return address;
1936 : : }
4098 alvherre@alvh.no-ip. 1937 :CBC 9 : tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1938 : : ObjectIdGetDatum(userid),
1939 : : ObjectIdGetDatum(server->serverid));
1940 [ - + ]: 9 : if (!HeapTupleIsValid(tp))
1941 : : {
4098 alvherre@alvh.no-ip. 1942 [ # # ]:UBC 0 : if (!missing_ok)
1943 [ # # ]: 0 : ereport(ERROR,
1944 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
1945 : : errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1946 : : username, servername)));
1947 : 0 : return address;
1948 : : }
1949 : :
2748 andres@anarazel.de 1950 :CBC 9 : address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1951 : :
4098 alvherre@alvh.no-ip. 1952 : 9 : ReleaseSysCache(tp);
1953 : :
1954 : 9 : return address;
1955 : : }
1956 : :
1957 : : /*
1958 : : * Find the ObjectAddress for a publication relation. The first element of
1959 : : * the object parameter is the relation name, the second is the
1960 : : * publication name.
1961 : : */
1962 : : static ObjectAddress
3486 peter_e@gmx.net 1963 : 20 : get_object_address_publication_rel(List *object,
1964 : : Relation *relp, bool missing_ok)
1965 : : {
1966 : : ObjectAddress address;
1967 : : Relation relation;
1968 : : List *relname;
1969 : : char *pubname;
1970 : : Publication *pub;
1971 : :
3418 1972 : 20 : ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1973 : :
3486 1974 : 20 : relname = linitial(object);
1975 : 20 : relation = relation_openrv_extended(makeRangeVarFromNameList(relname),
1976 : : AccessShareLock, missing_ok);
3418 1977 [ - + ]: 8 : if (!relation)
3418 peter_e@gmx.net 1978 :UBC 0 : return address;
1979 : :
1980 : : /* fetch publication name from input list */
3486 peter_e@gmx.net 1981 :CBC 8 : pubname = strVal(lsecond(object));
1982 : :
1983 : : /* Now look up the pg_publication tuple */
3418 1984 : 8 : pub = GetPublicationByName(pubname, missing_ok);
1985 [ - + ]: 8 : if (!pub)
1986 : : {
3399 peter_e@gmx.net 1987 :UBC 0 : relation_close(relation, AccessShareLock);
3418 1988 : 0 : return address;
1989 : : }
1990 : :
1991 : : /* Find the publication relation mapping in syscache. */
3418 peter_e@gmx.net 1992 :CBC 8 : address.objectId =
2748 andres@anarazel.de 1993 : 8 : GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1994 : : ObjectIdGetDatum(RelationGetRelid(relation)),
1995 : : ObjectIdGetDatum(pub->oid));
3418 peter_e@gmx.net 1996 [ - + ]: 8 : if (!OidIsValid(address.objectId))
1997 : : {
3418 peter_e@gmx.net 1998 [ # # ]:UBC 0 : if (!missing_ok)
1999 [ # # ]: 0 : ereport(ERROR,
2000 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
2001 : : errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
2002 : : RelationGetRelationName(relation), pubname)));
3399 2003 : 0 : relation_close(relation, AccessShareLock);
3418 2004 : 0 : return address;
2005 : : }
2006 : :
3414 peter_e@gmx.net 2007 :CBC 8 : *relp = relation;
3418 2008 : 8 : return address;
2009 : : }
2010 : :
2011 : : /*
2012 : : * Find the ObjectAddress for a publication schema. The first element of the
2013 : : * object parameter is the schema name, the second is the publication name.
2014 : : */
2015 : : static ObjectAddress
1676 akapila@postgresql.o 2016 : 13 : get_object_address_publication_schema(List *object, bool missing_ok)
2017 : : {
2018 : : ObjectAddress address;
2019 : : Publication *pub;
2020 : : char *pubname;
2021 : : char *schemaname;
2022 : : Oid schemaid;
2023 : :
2024 : 13 : ObjectAddressSet(address, PublicationNamespaceRelationId, InvalidOid);
2025 : :
2026 : : /* Fetch schema name and publication name from input list */
2027 : 13 : schemaname = strVal(linitial(object));
2028 : 13 : pubname = strVal(lsecond(object));
2029 : :
2030 : 13 : schemaid = get_namespace_oid(schemaname, missing_ok);
2031 [ - + ]: 9 : if (!OidIsValid(schemaid))
1676 akapila@postgresql.o 2032 :UBC 0 : return address;
2033 : :
2034 : : /* Now look up the pg_publication tuple */
1676 akapila@postgresql.o 2035 :CBC 9 : pub = GetPublicationByName(pubname, missing_ok);
2036 [ - + ]: 9 : if (!pub)
1676 akapila@postgresql.o 2037 :UBC 0 : return address;
2038 : :
2039 : : /* Find the publication schema mapping in syscache */
1676 akapila@postgresql.o 2040 :CBC 9 : address.objectId =
1514 tomas.vondra@postgre 2041 : 9 : GetSysCacheOid2(PUBLICATIONNAMESPACEMAP,
2042 : : Anum_pg_publication_namespace_oid,
2043 : : ObjectIdGetDatum(schemaid),
2044 : : ObjectIdGetDatum(pub->oid));
1676 akapila@postgresql.o 2045 [ - + - - ]: 9 : if (!OidIsValid(address.objectId) && !missing_ok)
1676 akapila@postgresql.o 2046 [ # # ]:UBC 0 : ereport(ERROR,
2047 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
2048 : : errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
2049 : : schemaname, pubname)));
2050 : :
1676 akapila@postgresql.o 2051 :CBC 9 : return address;
2052 : : }
2053 : :
2054 : : /*
2055 : : * Find the ObjectAddress for a default ACL.
2056 : : */
2057 : : static ObjectAddress
3486 peter_e@gmx.net 2058 : 28 : get_object_address_defacl(List *object, bool missing_ok)
2059 : : {
2060 : : HeapTuple tp;
2061 : : Oid userid;
2062 : : Oid schemaid;
2063 : : char *username;
2064 : : char *schema;
2065 : : char objtype;
2066 : : char *objtype_str;
2067 : : ObjectAddress address;
2068 : :
4098 alvherre@alvh.no-ip. 2069 : 28 : ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
2070 : :
2071 : : /*
2072 : : * First figure out the textual attributes so that they can be used for
2073 : : * error reporting.
2074 : : */
3486 peter_e@gmx.net 2075 : 28 : username = strVal(lsecond(object));
2076 [ + + ]: 28 : if (list_length(object) >= 3)
2077 : 16 : schema = (char *) strVal(lthird(object));
2078 : : else
4098 alvherre@alvh.no-ip. 2079 : 12 : schema = NULL;
2080 : :
2081 : : /*
2082 : : * Decode defaclobjtype. Only first char is considered; the rest of the
2083 : : * string, if any, is blissfully ignored.
2084 : : */
3486 peter_e@gmx.net 2085 : 28 : objtype = ((char *) strVal(linitial(object)))[0];
4098 alvherre@alvh.no-ip. 2086 [ + - - - : 28 : switch (objtype)
- - + ]
2087 : : {
2088 : 16 : case DEFACLOBJ_RELATION:
2089 : 16 : objtype_str = "tables";
2090 : 16 : break;
4098 alvherre@alvh.no-ip. 2091 :UBC 0 : case DEFACLOBJ_SEQUENCE:
2092 : 0 : objtype_str = "sequences";
2093 : 0 : break;
2094 : 0 : case DEFACLOBJ_FUNCTION:
2095 : 0 : objtype_str = "functions";
2096 : 0 : break;
2097 : 0 : case DEFACLOBJ_TYPE:
2098 : 0 : objtype_str = "types";
2099 : 0 : break;
3350 teodor@sigaev.ru 2100 : 0 : case DEFACLOBJ_NAMESPACE:
2101 : 0 : objtype_str = "schemas";
2102 : 0 : break;
421 fujii@postgresql.org 2103 : 0 : case DEFACLOBJ_LARGEOBJECT:
2104 : 0 : objtype_str = "large objects";
2105 : 0 : break;
4098 alvherre@alvh.no-ip. 2106 :CBC 12 : default:
2107 [ + - ]: 12 : ereport(ERROR,
2108 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2109 : : errmsg("unrecognized default ACL object type \"%c\"", objtype),
2110 : : errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2111 : : DEFACLOBJ_RELATION,
2112 : : DEFACLOBJ_SEQUENCE,
2113 : : DEFACLOBJ_FUNCTION,
2114 : : DEFACLOBJ_TYPE,
2115 : : DEFACLOBJ_NAMESPACE,
2116 : : DEFACLOBJ_LARGEOBJECT)));
2117 : : }
2118 : :
2119 : : /*
2120 : : * Look up user ID. Behave as "default ACL not found" if the user doesn't
2121 : : * exist.
2122 : : */
2123 : 16 : tp = SearchSysCache1(AUTHNAME,
2124 : : CStringGetDatum(username));
2125 [ - + ]: 16 : if (!HeapTupleIsValid(tp))
4098 alvherre@alvh.no-ip. 2126 :UBC 0 : goto not_found;
2748 andres@anarazel.de 2127 :CBC 16 : userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
4098 alvherre@alvh.no-ip. 2128 : 16 : ReleaseSysCache(tp);
2129 : :
2130 : : /*
2131 : : * If a schema name was given, look up its OID. If it doesn't exist,
2132 : : * behave as "default ACL not found".
2133 : : */
2134 [ + + ]: 16 : if (schema)
2135 : : {
2136 : 8 : schemaid = get_namespace_oid(schema, true);
2137 [ - + ]: 8 : if (schemaid == InvalidOid)
4098 alvherre@alvh.no-ip. 2138 :UBC 0 : goto not_found;
2139 : : }
2140 : : else
4098 alvherre@alvh.no-ip. 2141 :CBC 8 : schemaid = InvalidOid;
2142 : :
2143 : : /* Finally, look up the pg_default_acl object */
2144 : 16 : tp = SearchSysCache3(DEFACLROLENSPOBJ,
2145 : : ObjectIdGetDatum(userid),
2146 : : ObjectIdGetDatum(schemaid),
2147 : : CharGetDatum(objtype));
2148 [ - + ]: 16 : if (!HeapTupleIsValid(tp))
4098 alvherre@alvh.no-ip. 2149 :UBC 0 : goto not_found;
2150 : :
2748 andres@anarazel.de 2151 :CBC 16 : address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
4098 alvherre@alvh.no-ip. 2152 : 16 : ReleaseSysCache(tp);
2153 : :
2154 : 16 : return address;
2155 : :
4098 alvherre@alvh.no-ip. 2156 :UBC 0 : not_found:
2157 [ # # ]: 0 : if (!missing_ok)
2158 : : {
2159 [ # # ]: 0 : if (schema)
2160 [ # # ]: 0 : ereport(ERROR,
2161 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
2162 : : errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2163 : : username, schema, objtype_str)));
2164 : : else
2165 [ # # ]: 0 : ereport(ERROR,
2166 : : (errcode(ERRCODE_UNDEFINED_OBJECT),
2167 : : errmsg("default ACL for user \"%s\" on %s does not exist",
2168 : : username, objtype_str)));
2169 : : }
2170 : 0 : return address;
2171 : : }
2172 : :
2173 : : /*
2174 : : * Convert an array of TEXT into a List of string Values, as emitted by the
2175 : : * parser, which is what get_object_address uses as input.
2176 : : */
2177 : : static List *
4176 alvherre@alvh.no-ip. 2178 :CBC 2322 : textarray_to_strvaluelist(ArrayType *arr)
2179 : : {
2180 : : Datum *elems;
2181 : : bool *nulls;
2182 : : int nelems;
4025 bruce@momjian.us 2183 : 2322 : List *list = NIL;
2184 : : int i;
2185 : :
1429 peter@eisentraut.org 2186 : 2322 : deconstruct_array_builtin(arr, TEXTOID, &elems, &nulls, &nelems);
2187 : :
4176 alvherre@alvh.no-ip. 2188 [ + + ]: 5063 : for (i = 0; i < nelems; i++)
2189 : : {
2190 [ + + ]: 2745 : if (nulls[i])
2191 [ + - ]: 4 : ereport(ERROR,
2192 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2193 : : errmsg("name or argument lists may not contain nulls")));
2194 : 2741 : list = lappend(list, makeString(TextDatumGetCString(elems[i])));
2195 : : }
2196 : :
2197 : 2318 : return list;
2198 : : }
2199 : :
2200 : : /*
2201 : : * SQL-callable version of get_object_address
2202 : : */
2203 : : Datum
2204 : 1433 : pg_get_object_address(PG_FUNCTION_ARGS)
2205 : : {
3985 tgl@sss.pgh.pa.us 2206 : 1433 : char *ttype = TextDatumGetCString(PG_GETARG_DATUM(0));
4025 bruce@momjian.us 2207 : 1433 : ArrayType *namearr = PG_GETARG_ARRAYTYPE_P(1);
2208 : 1433 : ArrayType *argsarr = PG_GETARG_ARRAYTYPE_P(2);
2209 : : int itype;
2210 : : ObjectType type;
3486 peter_e@gmx.net 2211 : 1433 : List *name = NIL;
2212 : 1433 : TypeName *typename = NULL;
2213 : 1433 : List *args = NIL;
2214 : 1433 : Node *objnode = NULL;
2215 : : ObjectAddress addr;
2216 : : TupleDesc tupdesc;
2217 : : Datum values[3];
2218 : : bool nulls[3];
2219 : : HeapTuple htup;
2220 : : Relation relation;
2221 : :
2222 : : /* Decode object type, raise error if unknown */
4176 alvherre@alvh.no-ip. 2223 : 1433 : itype = read_objtype_from_string(ttype);
2224 [ + + ]: 1429 : if (itype < 0)
2225 [ + - ]: 36 : ereport(ERROR,
2226 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2227 : : errmsg("unsupported object type \"%s\"", ttype)));
2228 : 1393 : type = (ObjectType) itype;
2229 : :
2230 : : /*
2231 : : * Convert the text array to the representation appropriate for the given
2232 : : * object type. Most use a simple string Values list, but there are some
2233 : : * exceptions.
2234 : : */
4169 2235 [ + + + - : 1393 : if (type == OBJECT_TYPE || type == OBJECT_DOMAIN || type == OBJECT_CAST ||
+ + + + ]
3996 2236 [ + + ]: 1273 : type == OBJECT_TRANSFORM || type == OBJECT_DOMCONSTRAINT)
4176 2237 : 88 : {
2238 : : Datum *elems;
2239 : : bool *nulls;
2240 : : int nelems;
2241 : :
1429 peter@eisentraut.org 2242 : 152 : deconstruct_array_builtin(namearr, TEXTOID, &elems, &nulls, &nelems);
4176 alvherre@alvh.no-ip. 2243 [ + + ]: 152 : if (nelems != 1)
2244 [ + - ]: 64 : ereport(ERROR,
2245 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2246 : : errmsg("name list length must be exactly %d", 1)));
2247 [ - + ]: 88 : if (nulls[0])
4176 alvherre@alvh.no-ip. 2248 [ # # ]:UBC 0 : ereport(ERROR,
2249 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2250 : : errmsg("name or argument lists may not contain nulls")));
1250 tgl@sss.pgh.pa.us 2251 :CBC 88 : typename = typeStringToTypeName(TextDatumGetCString(elems[0]), NULL);
2252 : : }
4176 alvherre@alvh.no-ip. 2253 [ + + ]: 1241 : else if (type == OBJECT_LARGEOBJECT)
2254 : : {
2255 : : Datum *elems;
2256 : : bool *nulls;
2257 : : int nelems;
2258 : :
1429 peter@eisentraut.org 2259 : 12 : deconstruct_array_builtin(namearr, TEXTOID, &elems, &nulls, &nelems);
4176 alvherre@alvh.no-ip. 2260 [ + + ]: 12 : if (nelems != 1)
2261 [ + - ]: 4 : ereport(ERROR,
2262 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2263 : : errmsg("name list length must be exactly %d", 1)));
2264 [ - + ]: 8 : if (nulls[0])
4176 alvherre@alvh.no-ip. 2265 [ # # ]:UBC 0 : ereport(ERROR,
2266 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2267 : : errmsg("large object OID may not be null")));
3486 peter_e@gmx.net 2268 :CBC 8 : objnode = (Node *) makeFloat(TextDatumGetCString(elems[0]));
2269 : : }
2270 : : else
2271 : : {
4176 alvherre@alvh.no-ip. 2272 : 1229 : name = textarray_to_strvaluelist(namearr);
1382 tgl@sss.pgh.pa.us 2273 [ + + ]: 1225 : if (name == NIL)
4176 alvherre@alvh.no-ip. 2274 [ + - ]: 4 : ereport(ERROR,
2275 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2276 : : errmsg("name list length must be at least %d", 1)));
2277 : : }
2278 : :
2279 : : /*
2280 : : * If args are given, decode them according to the object type.
2281 : : */
2282 [ + + + + ]: 1317 : if (type == OBJECT_AGGREGATE ||
2283 [ + + ]: 1253 : type == OBJECT_FUNCTION ||
3103 peter_e@gmx.net 2284 [ + - ]: 1221 : type == OBJECT_PROCEDURE ||
2285 [ + + ]: 1221 : type == OBJECT_ROUTINE ||
4176 alvherre@alvh.no-ip. 2286 [ + + ]: 1189 : type == OBJECT_OPERATOR ||
4093 2287 [ + + ]: 1173 : type == OBJECT_CAST ||
2288 [ + + ]: 1133 : type == OBJECT_AMOP ||
2289 : : type == OBJECT_AMPROC)
4176 2290 : 224 : {
2291 : : /* in these cases, the args list must be of TypeName */
2292 : : Datum *elems;
2293 : : bool *nulls;
2294 : : int nelems;
2295 : : int i;
2296 : :
1429 peter@eisentraut.org 2297 : 224 : deconstruct_array_builtin(argsarr, TEXTOID, &elems, &nulls, &nelems);
2298 : :
4176 alvherre@alvh.no-ip. 2299 : 224 : args = NIL;
2300 [ + + ]: 428 : for (i = 0; i < nelems; i++)
2301 : : {
2302 [ - + ]: 204 : if (nulls[i])
4176 alvherre@alvh.no-ip. 2303 [ # # ]:UBC 0 : ereport(ERROR,
2304 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2305 : : errmsg("name or argument lists may not contain nulls")));
4176 alvherre@alvh.no-ip. 2306 :CBC 204 : args = lappend(args,
1250 tgl@sss.pgh.pa.us 2307 : 204 : typeStringToTypeName(TextDatumGetCString(elems[i]),
2308 : : NULL));
2309 : : }
2310 : : }
2311 : : else
2312 : : {
2313 : : /* For all other object types, use string Values */
4176 alvherre@alvh.no-ip. 2314 : 1093 : args = textarray_to_strvaluelist(argsarr);
2315 : : }
2316 : :
2317 : : /*
2318 : : * get_object_address is pretty sensitive to the length of its input
2319 : : * lists; check that they're what it wants.
2320 : : */
2321 [ + + + + : 1317 : switch (type)
+ + ]
2322 : : {
1347 peter@eisentraut.org 2323 : 64 : case OBJECT_PUBLICATION_NAMESPACE:
2324 : : case OBJECT_USER_MAPPING:
2325 [ + + ]: 64 : if (list_length(name) != 1)
2326 [ + - ]: 32 : ereport(ERROR,
2327 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2328 : : errmsg("name list length must be exactly %d", 1)));
2329 : : /* fall through to check args length */
2330 : : pg_fallthrough;
2331 : : case OBJECT_DOMCONSTRAINT:
2332 : : case OBJECT_CAST:
2333 : : case OBJECT_PUBLICATION_REL:
2334 : : case OBJECT_DEFACL:
2335 : : case OBJECT_TRANSFORM:
4176 alvherre@alvh.no-ip. 2336 [ + + ]: 152 : if (list_length(args) != 1)
2337 [ + - ]: 44 : ereport(ERROR,
2338 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2339 : : errmsg("argument list length must be exactly %d", 1)));
2340 : 108 : break;
4093 2341 : 64 : case OBJECT_OPFAMILY:
2342 : : case OBJECT_OPCLASS:
2343 [ + + ]: 64 : if (list_length(name) < 2)
2344 [ + - ]: 16 : ereport(ERROR,
2345 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2346 : : errmsg("name list length must be at least %d", 2)));
2347 : 48 : break;
2348 : 80 : case OBJECT_AMOP:
2349 : : case OBJECT_AMPROC:
2350 [ + + ]: 80 : if (list_length(name) < 3)
2351 [ + - ]: 32 : ereport(ERROR,
2352 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2353 : : errmsg("name list length must be at least %d", 3)));
2354 : : /* fall through to check args length */
2355 : : pg_fallthrough;
2356 : : case OBJECT_OPERATOR:
4176 2357 [ + + ]: 80 : if (list_length(args) != 2)
2358 [ + - ]: 40 : ereport(ERROR,
2359 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2360 : : errmsg("argument list length must be exactly %d", 2)));
2361 : 40 : break;
2362 : 957 : default:
2363 : 957 : break;
2364 : : }
2365 : :
2366 : : /*
2367 : : * Now build the Node type that get_object_address() expects for the given
2368 : : * type.
2369 : : */
3486 peter_e@gmx.net 2370 : 1153 : switch (type)
[ + + + +
+ + + + +
+ - ]
2371 : : {
2372 : 688 : case OBJECT_TABLE:
2373 : : case OBJECT_SEQUENCE:
2374 : : case OBJECT_VIEW:
2375 : : case OBJECT_MATVIEW:
2376 : : case OBJECT_INDEX:
2377 : : case OBJECT_FOREIGN_TABLE:
2378 : : case OBJECT_PROPGRAPH:
2379 : : case OBJECT_COLUMN:
2380 : : case OBJECT_ATTRIBUTE:
2381 : : case OBJECT_COLLATION:
2382 : : case OBJECT_CONVERSION:
2383 : : case OBJECT_STATISTIC_EXT:
2384 : : case OBJECT_TSPARSER:
2385 : : case OBJECT_TSDICTIONARY:
2386 : : case OBJECT_TSTEMPLATE:
2387 : : case OBJECT_TSCONFIGURATION:
2388 : : case OBJECT_DEFAULT:
2389 : : case OBJECT_POLICY:
2390 : : case OBJECT_RULE:
2391 : : case OBJECT_TRIGGER:
2392 : : case OBJECT_TABCONSTRAINT:
2393 : : case OBJECT_OPCLASS:
2394 : : case OBJECT_OPFAMILY:
2395 : 688 : objnode = (Node *) name;
2396 : 688 : break;
2397 : 173 : case OBJECT_ACCESS_METHOD:
2398 : : case OBJECT_DATABASE:
2399 : : case OBJECT_EVENT_TRIGGER:
2400 : : case OBJECT_EXTENSION:
2401 : : case OBJECT_FDW:
2402 : : case OBJECT_FOREIGN_SERVER:
2403 : : case OBJECT_LANGUAGE:
2404 : : case OBJECT_PARAMETER_ACL:
2405 : : case OBJECT_PUBLICATION:
2406 : : case OBJECT_ROLE:
2407 : : case OBJECT_SCHEMA:
2408 : : case OBJECT_SUBSCRIPTION:
2409 : : case OBJECT_TABLESPACE:
2410 [ + + ]: 173 : if (list_length(name) != 1)
2411 [ + - ]: 48 : ereport(ERROR,
2412 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2413 : : errmsg("name list length must be exactly %d", 1)));
2414 : 125 : objnode = linitial(name);
2415 : 125 : break;
2416 : 40 : case OBJECT_TYPE:
2417 : : case OBJECT_DOMAIN:
2418 : 40 : objnode = (Node *) typename;
2419 : 40 : break;
2420 : 36 : case OBJECT_CAST:
2421 : : case OBJECT_DOMCONSTRAINT:
2422 : : case OBJECT_TRANSFORM:
2423 : 36 : objnode = (Node *) list_make2(typename, linitial(args));
2424 : 36 : break;
2425 : 20 : case OBJECT_PUBLICATION_REL:
2426 : 20 : objnode = (Node *) list_make2(name, linitial(args));
2427 : 20 : break;
1676 akapila@postgresql.o 2428 : 24 : case OBJECT_PUBLICATION_NAMESPACE:
2429 : : case OBJECT_USER_MAPPING:
3486 peter_e@gmx.net 2430 : 24 : objnode = (Node *) list_make2(linitial(name), linitial(args));
2431 : 24 : break;
2432 : 28 : case OBJECT_DEFACL:
2433 : 28 : objnode = (Node *) lcons(linitial(args), name);
2434 : 28 : break;
2435 : 32 : case OBJECT_AMOP:
2436 : : case OBJECT_AMPROC:
2437 : 32 : objnode = (Node *) list_make2(name, args);
2438 : 32 : break;
2439 : 104 : case OBJECT_FUNCTION:
2440 : : case OBJECT_PROCEDURE:
2441 : : case OBJECT_ROUTINE:
2442 : : case OBJECT_AGGREGATE:
2443 : : case OBJECT_OPERATOR:
2444 : : {
3300 bruce@momjian.us 2445 : 104 : ObjectWithArgs *owa = makeNode(ObjectWithArgs);
2446 : :
2447 : 104 : owa->objname = name;
2448 : 104 : owa->objargs = args;
2449 : 104 : objnode = (Node *) owa;
2450 : 104 : break;
2451 : : }
3486 peter_e@gmx.net 2452 : 8 : case OBJECT_LARGEOBJECT:
2453 : : /* already handled above */
2454 : 8 : break;
2455 : : /* no default, to let compiler warn about missing case */
2456 : : }
2457 : :
2458 [ - + ]: 1105 : if (objnode == NULL)
3486 peter_e@gmx.net 2459 [ # # ]:UBC 0 : elog(ERROR, "unrecognized object type: %d", type);
2460 : :
3486 peter_e@gmx.net 2461 :CBC 1105 : addr = get_object_address(type, objnode,
2462 : : &relation, AccessShareLock, false);
2463 : :
2464 : : /* We don't need the relcache entry, thank you very much */
4176 alvherre@alvh.no-ip. 2465 [ + + ]: 421 : if (relation)
2466 : 136 : relation_close(relation, AccessShareLock);
2467 : :
1256 michael@paquier.xyz 2468 [ - + ]: 421 : if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1256 michael@paquier.xyz 2469 [ # # ]:UBC 0 : elog(ERROR, "return type must be a row type");
2470 : :
4176 alvherre@alvh.no-ip. 2471 :CBC 421 : values[0] = ObjectIdGetDatum(addr.classId);
2472 : 421 : values[1] = ObjectIdGetDatum(addr.objectId);
2473 : 421 : values[2] = Int32GetDatum(addr.objectSubId);
2474 : 421 : nulls[0] = false;
2475 : 421 : nulls[1] = false;
2476 : 421 : nulls[2] = false;
2477 : :
2478 : 421 : htup = heap_form_tuple(tupdesc, values, nulls);
2479 : :
2480 : 421 : PG_RETURN_DATUM(HeapTupleGetDatum(htup));
2481 : : }
2482 : :
2483 : : /*
2484 : : * Check ownership of an object previously identified by get_object_address.
2485 : : */
2486 : : void
5566 tgl@sss.pgh.pa.us 2487 : 6700 : check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
2488 : : Node *object, Relation relation)
2489 : : {
2490 : 6700 : switch (objtype)
[ + + + +
+ + + + +
+ + - - ]
2491 : : {
2492 : 1277 : case OBJECT_INDEX:
2493 : : case OBJECT_SEQUENCE:
2494 : : case OBJECT_TABLE:
2495 : : case OBJECT_VIEW:
2496 : : case OBJECT_MATVIEW:
2497 : : case OBJECT_FOREIGN_TABLE:
2498 : : case OBJECT_PROPGRAPH:
2499 : : case OBJECT_COLUMN:
2500 : : case OBJECT_RULE:
2501 : : case OBJECT_TRIGGER:
2502 : : case OBJECT_POLICY:
2503 : : case OBJECT_TABCONSTRAINT:
1294 peter@eisentraut.org 2504 [ + + ]: 1277 : if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
3101 peter_e@gmx.net 2505 : 14 : aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
5566 tgl@sss.pgh.pa.us 2506 : 14 : RelationGetRelationName(relation));
2507 : 1263 : break;
2508 : 53 : case OBJECT_TYPE:
2509 : : case OBJECT_DOMAIN:
2510 : : case OBJECT_ATTRIBUTE:
1294 peter@eisentraut.org 2511 [ - + ]: 53 : if (!object_ownercheck(address.classId, address.objectId, roleid))
5097 peter_e@gmx.net 2512 :UBC 0 : aclcheck_error_type(ACLCHECK_NOT_OWNER, address.objectId);
5566 tgl@sss.pgh.pa.us 2513 :CBC 53 : break;
2544 michael@paquier.xyz 2514 : 27 : case OBJECT_DOMCONSTRAINT:
2515 : : {
2516 : : HeapTuple tuple;
2517 : : Oid contypid;
2518 : :
2519 : 27 : tuple = SearchSysCache1(CONSTROID,
2520 : : ObjectIdGetDatum(address.objectId));
2521 [ - + ]: 27 : if (!HeapTupleIsValid(tuple))
2544 michael@paquier.xyz 2522 [ # # ]:UBC 0 : elog(ERROR, "constraint with OID %u does not exist",
2523 : : address.objectId);
2524 : :
2544 michael@paquier.xyz 2525 :CBC 27 : contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2526 : :
2527 : 27 : ReleaseSysCache(tuple);
2528 : :
2529 : : /*
2530 : : * Fallback to type ownership check in this case as this is
2531 : : * what domain constraints rely on.
2532 : : */
1294 peter@eisentraut.org 2533 [ + + ]: 27 : if (!object_ownercheck(TypeRelationId, contypid, roleid))
2544 michael@paquier.xyz 2534 : 4 : aclcheck_error_type(ACLCHECK_NOT_OWNER, contypid);
2535 : : }
2536 : 23 : break;
5566 tgl@sss.pgh.pa.us 2537 : 261 : case OBJECT_AGGREGATE:
2538 : : case OBJECT_FUNCTION:
2539 : : case OBJECT_PROCEDURE:
2540 : : case OBJECT_ROUTINE:
2541 : : case OBJECT_OPERATOR:
1294 peter@eisentraut.org 2542 [ + + ]: 261 : if (!object_ownercheck(address.classId, address.objectId, roleid))
3101 peter_e@gmx.net 2543 : 12 : aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
3486 2544 : 12 : NameListToString((castNode(ObjectWithArgs, object))->objname));
5566 tgl@sss.pgh.pa.us 2545 : 249 : break;
1294 peter@eisentraut.org 2546 : 1447 : case OBJECT_DATABASE:
2547 : : case OBJECT_EVENT_TRIGGER:
2548 : : case OBJECT_EXTENSION:
2549 : : case OBJECT_FDW:
2550 : : case OBJECT_FOREIGN_SERVER:
2551 : : case OBJECT_LANGUAGE:
2552 : : case OBJECT_PUBLICATION:
2553 : : case OBJECT_SCHEMA:
2554 : : case OBJECT_SUBSCRIPTION:
2555 : : case OBJECT_TABLESPACE:
2556 [ + + ]: 1447 : if (!object_ownercheck(address.classId, address.objectId, roleid))
3101 peter_e@gmx.net 2557 : 28 : aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
1724 peter@eisentraut.org 2558 : 28 : strVal(object));
5566 tgl@sss.pgh.pa.us 2559 : 1419 : break;
1294 peter@eisentraut.org 2560 : 3461 : case OBJECT_COLLATION:
2561 : : case OBJECT_CONVERSION:
2562 : : case OBJECT_OPCLASS:
2563 : : case OBJECT_OPFAMILY:
2564 : : case OBJECT_STATISTIC_EXT:
2565 : : case OBJECT_TSDICTIONARY:
2566 : : case OBJECT_TSCONFIGURATION:
2567 [ + + ]: 3461 : if (!object_ownercheck(address.classId, address.objectId, roleid))
3101 peter_e@gmx.net 2568 : 8 : aclcheck_error(ACLCHECK_NOT_OWNER, objtype,
3486 2569 : 8 : NameListToString(castNode(List, object)));
5566 tgl@sss.pgh.pa.us 2570 : 3453 : break;
2571 : 33 : case OBJECT_LARGEOBJECT:
2572 [ + - ]: 33 : if (!lo_compat_privileges &&
1294 peter@eisentraut.org 2573 [ - + ]: 33 : !object_ownercheck(address.classId, address.objectId, roleid))
5566 tgl@sss.pgh.pa.us 2574 [ # # ]:UBC 0 : ereport(ERROR,
2575 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2576 : : errmsg("must be owner of large object %u",
2577 : : address.objectId)));
5566 tgl@sss.pgh.pa.us 2578 :CBC 33 : break;
2579 : 18 : case OBJECT_CAST:
2580 : : {
2581 : : /* We can only check permissions on the source/target types */
3337 2582 : 18 : TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2583 : 18 : TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
5529 bruce@momjian.us 2584 : 18 : Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2585 : 18 : Oid targettypeid = typenameTypeId(NULL, targettype);
2586 : :
1294 peter@eisentraut.org 2587 [ - + ]: 18 : if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
1294 peter@eisentraut.org 2588 [ # # ]:UBC 0 : && !object_ownercheck(TypeRelationId, targettypeid, roleid))
5566 tgl@sss.pgh.pa.us 2589 [ # # ]: 0 : ereport(ERROR,
2590 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2591 : : errmsg("must be owner of type %s or type %s",
2592 : : format_type_be(sourcetypeid),
2593 : : format_type_be(targettypeid))));
2594 : : }
5566 tgl@sss.pgh.pa.us 2595 :CBC 18 : break;
4052 peter_e@gmx.net 2596 : 11 : case OBJECT_TRANSFORM:
2597 : : {
3337 tgl@sss.pgh.pa.us 2598 : 11 : TypeName *typename = linitial_node(TypeName, castNode(List, object));
4052 peter_e@gmx.net 2599 : 11 : Oid typeid = typenameTypeId(NULL, typename);
2600 : :
1294 peter@eisentraut.org 2601 [ - + ]: 11 : if (!object_ownercheck(TypeRelationId, typeid, roleid))
4052 peter_e@gmx.net 2602 :UBC 0 : aclcheck_error_type(ACLCHECK_NOT_OWNER, typeid);
2603 : : }
4052 peter_e@gmx.net 2604 :CBC 11 : break;
5561 tgl@sss.pgh.pa.us 2605 : 26 : case OBJECT_ROLE:
2606 : :
2607 : : /*
2608 : : * We treat roles as being "owned" by those with CREATEROLE priv,
2609 : : * provided that they also have admin option on the role.
2610 : : *
2611 : : * However, superusers are only owned by superusers.
2612 : : */
2613 [ - + ]: 26 : if (superuser_arg(address.objectId))
2614 : : {
5561 tgl@sss.pgh.pa.us 2615 [ # # ]:UBC 0 : if (!superuser_arg(roleid))
2616 [ # # ]: 0 : ereport(ERROR,
2617 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2618 : : errmsg("permission denied"),
2619 : : errdetail("The current user must have the %s attribute.",
2620 : : "SUPERUSER")));
2621 : : }
2622 : : else
2623 : : {
4176 alvherre@alvh.no-ip. 2624 [ + + ]:CBC 26 : if (!has_createrole_privilege(roleid))
5561 tgl@sss.pgh.pa.us 2625 [ + - ]: 1 : ereport(ERROR,
2626 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2627 : : errmsg("permission denied"),
2628 : : errdetail("The current user must have the %s attribute.",
2629 : : "CREATEROLE")));
1236 rhaas@postgresql.org 2630 [ + + ]: 25 : if (!is_admin_of_role(roleid, address.objectId))
2631 [ + - ]: 4 : ereport(ERROR,
2632 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2633 : : errmsg("permission denied"),
2634 : : errdetail("The current user must have the %s option on role \"%s\".",
2635 : : "ADMIN",
2636 : : GetUserNameFromId(address.objectId,
2637 : : true))));
2638 : : }
5561 tgl@sss.pgh.pa.us 2639 : 21 : break;
5566 2640 : 86 : case OBJECT_TSPARSER:
2641 : : case OBJECT_TSTEMPLATE:
2642 : : case OBJECT_ACCESS_METHOD:
2643 : : case OBJECT_PARAMETER_ACL:
2644 : : /* We treat these object types as being owned by superusers */
2645 [ - + ]: 86 : if (!superuser_arg(roleid))
5566 tgl@sss.pgh.pa.us 2646 [ # # ]:UBC 0 : ereport(ERROR,
2647 : : (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2648 : : errmsg("must be superuser")));
5566 tgl@sss.pgh.pa.us 2649 :CBC 86 : break;
1290 peter@eisentraut.org 2650 :UBC 0 : case OBJECT_AMOP:
2651 : : case OBJECT_AMPROC:
2652 : : case OBJECT_DEFAULT:
2653 : : case OBJECT_DEFACL:
2654 : : case OBJECT_PUBLICATION_NAMESPACE:
2655 : : case OBJECT_PUBLICATION_REL:
2656 : : case OBJECT_USER_MAPPING:
2657 : : /* These are currently not supported or don't make sense here. */
2658 [ # # ]: 0 : elog(ERROR, "unsupported object type: %d", (int) objtype);
2659 : : break;
2660 : : }
5566 tgl@sss.pgh.pa.us 2661 :CBC 6629 : }
2662 : :
2663 : : /*
2664 : : * get_object_namespace
2665 : : *
2666 : : * Find the schema containing the specified object. For non-schema objects,
2667 : : * this function returns InvalidOid.
2668 : : */
2669 : : Oid
5337 rhaas@postgresql.org 2670 : 552247 : get_object_namespace(const ObjectAddress *address)
2671 : : {
2672 : : SysCacheIdentifier cache;
2673 : : HeapTuple tuple;
2674 : : Oid oid;
2675 : : const ObjectPropertyType *property;
2676 : :
2677 : : /* If not owned by a namespace, just return InvalidOid. */
2678 : 552247 : property = get_object_property_data(address->classId);
2679 [ + + ]: 552247 : if (property->attnum_namespace == InvalidAttrNumber)
2680 : 29856 : return InvalidOid;
2681 : :
2682 : : /* Currently, we can only handle object types with system caches. */
2683 : 522391 : cache = property->oid_catcache_id;
101 michael@paquier.xyz 2684 [ - + ]:GNC 522391 : Assert(cache != SYSCACHEID_INVALID);
2685 : :
2686 : : /* Fetch tuple from syscache and extract namespace attribute. */
5337 rhaas@postgresql.org 2687 :CBC 522391 : tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2688 [ - + ]: 522391 : if (!HeapTupleIsValid(tuple))
5337 rhaas@postgresql.org 2689 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for cache %d oid %u",
2690 : : cache, address->objectId);
1162 dgustafsson@postgres 2691 :CBC 522391 : oid = DatumGetObjectId(SysCacheGetAttrNotNull(cache,
2692 : : tuple,
2693 : 522391 : property->attnum_namespace));
5337 rhaas@postgresql.org 2694 : 522391 : ReleaseSysCache(tuple);
2695 : :
2696 : 522391 : return oid;
2697 : : }
2698 : :
2699 : : /*
2700 : : * Return ObjectType for the given object type as given by
2701 : : * getObjectTypeDescription; if no valid ObjectType code exists, but it's a
2702 : : * possible output type from getObjectTypeDescription, return -1.
2703 : : * Otherwise, an error is thrown.
2704 : : */
2705 : : int
4176 alvherre@alvh.no-ip. 2706 : 1433 : read_objtype_from_string(const char *objtype)
2707 : : {
2708 : : int i;
2709 : :
2710 [ + + ]: 43461 : for (i = 0; i < lengthof(ObjectTypeMap); i++)
2711 : : {
2712 [ + + ]: 43457 : if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
3531 2713 : 1429 : return ObjectTypeMap[i].tm_type;
2714 : : }
2715 [ + - ]: 4 : ereport(ERROR,
2716 : : (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2717 : : errmsg("unrecognized object type \"%s\"", objtype)));
2718 : :
2719 : : return -1; /* keep compiler quiet */
2720 : : }
2721 : :
2722 : : /*
2723 : : * Interfaces to reference fields of ObjectPropertyType
2724 : : */
2725 : : const char *
2181 peter@eisentraut.org 2726 : 8 : get_object_class_descr(Oid class_id)
2727 : : {
2728 : 8 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2729 : :
2730 : 8 : return prop->class_descr;
2731 : : }
2732 : :
2733 : : Oid
4993 alvherre@alvh.no-ip. 2734 : 58623 : get_object_oid_index(Oid class_id)
2735 : : {
4515 tgl@sss.pgh.pa.us 2736 : 58623 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2737 : :
4993 alvherre@alvh.no-ip. 2738 : 58623 : return prop->oid_index_oid;
2739 : : }
2740 : :
2741 : : SysCacheIdentifier
2742 : 151699 : get_object_catcache_oid(Oid class_id)
2743 : : {
4515 tgl@sss.pgh.pa.us 2744 : 151699 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2745 : :
4993 alvherre@alvh.no-ip. 2746 : 151699 : return prop->oid_catcache_id;
2747 : : }
2748 : :
2749 : : SysCacheIdentifier
2750 : 465 : get_object_catcache_name(Oid class_id)
2751 : : {
4515 tgl@sss.pgh.pa.us 2752 : 465 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2753 : :
4993 alvherre@alvh.no-ip. 2754 : 465 : return prop->name_catcache_id;
2755 : : }
2756 : :
2757 : : AttrNumber
2748 andres@anarazel.de 2758 : 62446 : get_object_attnum_oid(Oid class_id)
2759 : : {
2760 : 62446 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2761 : :
2762 : 62446 : return prop->attnum_oid;
2763 : : }
2764 : :
2765 : : AttrNumber
4993 alvherre@alvh.no-ip. 2766 : 5165 : get_object_attnum_name(Oid class_id)
2767 : : {
4515 tgl@sss.pgh.pa.us 2768 : 5165 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2769 : :
4993 alvherre@alvh.no-ip. 2770 : 5165 : return prop->attnum_name;
2771 : : }
2772 : :
2773 : : AttrNumber
2774 : 5746 : get_object_attnum_namespace(Oid class_id)
2775 : : {
4515 tgl@sss.pgh.pa.us 2776 : 5746 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2777 : :
4993 alvherre@alvh.no-ip. 2778 : 5746 : return prop->attnum_namespace;
2779 : : }
2780 : :
2781 : : AttrNumber
2782 : 43277 : get_object_attnum_owner(Oid class_id)
2783 : : {
4515 tgl@sss.pgh.pa.us 2784 : 43277 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2785 : :
4993 alvherre@alvh.no-ip. 2786 : 43277 : return prop->attnum_owner;
2787 : : }
2788 : :
2789 : : AttrNumber
2790 : 37411 : get_object_attnum_acl(Oid class_id)
2791 : : {
4515 tgl@sss.pgh.pa.us 2792 : 37411 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2793 : :
4993 alvherre@alvh.no-ip. 2794 : 37411 : return prop->attnum_acl;
2795 : : }
2796 : :
2797 : : /*
2798 : : * get_object_type
2799 : : *
2800 : : * Return the object type associated with a given object. This routine
2801 : : * is primarily used to determine the object type to mention in ACL check
2802 : : * error messages, so it's desirable for it to avoid failing.
2803 : : */
2804 : : ObjectType
3101 peter_e@gmx.net 2805 : 32969 : get_object_type(Oid class_id, Oid object_id)
2806 : : {
4515 tgl@sss.pgh.pa.us 2807 : 32969 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2808 : :
3101 peter_e@gmx.net 2809 [ + + ]: 32969 : if (prop->objtype == OBJECT_TABLE)
2810 : : {
2811 : : /*
2812 : : * If the property data says it's a table, dig a little deeper to get
2813 : : * the real relation kind, so that callers can produce more precise
2814 : : * error messages.
2815 : : */
3101 peter_e@gmx.net 2816 :GBC 4 : return get_relkind_objtype(get_rel_relkind(object_id));
2817 : : }
2818 : : else
3101 peter_e@gmx.net 2819 :CBC 32965 : return prop->objtype;
2820 : : }
2821 : :
2822 : : bool
4819 alvherre@alvh.no-ip. 2823 : 4133 : get_object_namensp_unique(Oid class_id)
2824 : : {
4515 tgl@sss.pgh.pa.us 2825 : 4133 : const ObjectPropertyType *prop = get_object_property_data(class_id);
2826 : :
4819 alvherre@alvh.no-ip. 2827 : 4133 : return prop->is_nsp_name_unique;
2828 : : }
2829 : :
2830 : : /*
2831 : : * Return whether we have useful data for the given object class in the
2832 : : * ObjectProperty table.
2833 : : */
2834 : : bool
2835 : 4798 : is_objectclass_supported(Oid class_id)
2836 : : {
2837 : : int index;
2838 : :
2839 [ + + ]: 125640 : for (index = 0; index < lengthof(ObjectProperty); index++)
2840 : : {
2841 [ + + ]: 125547 : if (ObjectProperty[index].class_oid == class_id)
2842 : 4705 : return true;
2843 : : }
2844 : :
2845 : 93 : return false;
2846 : : }
2847 : :
2848 : : /*
2849 : : * Find ObjectProperty structure by class_id.
2850 : : */
2851 : : static const ObjectPropertyType *
5337 rhaas@postgresql.org 2852 : 954189 : get_object_property_data(Oid class_id)
2853 : : {
2854 : : static const ObjectPropertyType *prop_last = NULL;
2855 : : int index;
2856 : :
2857 : : /*
2858 : : * A shortcut to speed up multiple consecutive lookups of a particular
2859 : : * object class.
2860 : : */
4993 alvherre@alvh.no-ip. 2861 [ + + + + ]: 954189 : if (prop_last && prop_last->class_oid == class_id)
2862 : 548416 : return prop_last;
2863 : :
5337 rhaas@postgresql.org 2864 [ + - ]: 10461773 : for (index = 0; index < lengthof(ObjectProperty); index++)
2865 : : {
2866 [ + + ]: 10461773 : if (ObjectProperty[index].class_oid == class_id)
2867 : : {
4993 alvherre@alvh.no-ip. 2868 : 405773 : prop_last = &ObjectProperty[index];
5337 rhaas@postgresql.org 2869 : 405773 : return &ObjectProperty[index];
2870 : : }
2871 : : }
2872 : :
4993 alvherre@alvh.no-ip. 2873 [ # # ]:UBC 0 : ereport(ERROR,
2874 : : (errmsg_internal("unrecognized class ID: %u", class_id)));
2875 : :
2876 : : return NULL; /* keep MSC compiler happy */
2877 : : }
2878 : :
2879 : : /*
2880 : : * Return a copy of the tuple for the object with the given object OID, from
2881 : : * the given catalog (which must have been opened by the caller and suitably
2882 : : * locked). NULL is returned if the OID is not found.
2883 : : *
2884 : : * We try a syscache first, if available.
2885 : : */
2886 : : HeapTuple
2748 andres@anarazel.de 2887 :CBC 6318 : get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
2888 : : {
2889 : : return
518 noah@leadboat.com 2890 : 6318 : get_catalog_object_by_oid_extended(catalog, oidcol, objectId, false);
2891 : : }
2892 : :
2893 : : /*
2894 : : * Same as get_catalog_object_by_oid(), but with an additional "locktup"
2895 : : * argument controlling whether to acquire a LOCKTAG_TUPLE at mode
2896 : : * InplaceUpdateTupleLock. See README.tuplock section "Locking to write
2897 : : * inplace-updated tables".
2898 : : */
2899 : : HeapTuple
2900 : 7049 : get_catalog_object_by_oid_extended(Relation catalog,
2901 : : AttrNumber oidcol,
2902 : : Oid objectId,
2903 : : bool locktup)
2904 : : {
2905 : : HeapTuple tuple;
4819 alvherre@alvh.no-ip. 2906 : 7049 : Oid classId = RelationGetRelid(catalog);
101 michael@paquier.xyz 2907 :GNC 7049 : SysCacheIdentifier oidCacheId = get_object_catcache_oid(classId);
2908 : :
2909 [ + + ]: 7049 : if (oidCacheId >= 0)
2910 : : {
518 noah@leadboat.com 2911 [ + + ]:CBC 5469 : if (locktup)
2912 : 721 : tuple = SearchSysCacheLockedCopy1(oidCacheId,
2913 : : ObjectIdGetDatum(objectId));
2914 : : else
2915 : 4748 : tuple = SearchSysCacheCopy1(oidCacheId,
2916 : : ObjectIdGetDatum(objectId));
4749 bruce@momjian.us 2917 [ + + ]: 5469 : if (!HeapTupleIsValid(tuple)) /* should not happen */
4819 alvherre@alvh.no-ip. 2918 : 136 : return NULL;
2919 : : }
2920 : : else
2921 : : {
2922 : 1580 : Oid oidIndexId = get_object_oid_index(classId);
2923 : : SysScanDesc scan;
2924 : : ScanKeyData skey;
2925 : :
2926 [ - + ]: 1580 : Assert(OidIsValid(oidIndexId));
2927 : :
2928 : 1580 : ScanKeyInit(&skey,
2929 : : oidcol,
2930 : : BTEqualStrategyNumber, F_OIDEQ,
2931 : : ObjectIdGetDatum(objectId));
2932 : :
2933 : 1580 : scan = systable_beginscan(catalog, oidIndexId, true,
2934 : : NULL, 1, &skey);
2935 : 1580 : tuple = systable_getnext(scan);
2936 [ + + ]: 1580 : if (!HeapTupleIsValid(tuple))
2937 : : {
2938 : 72 : systable_endscan(scan);
2939 : 72 : return NULL;
2940 : : }
2941 : :
518 noah@leadboat.com 2942 [ + + ]: 1508 : if (locktup)
2943 : 10 : LockTuple(catalog, &tuple->t_self, InplaceUpdateTupleLock);
2944 : :
4819 alvherre@alvh.no-ip. 2945 : 1508 : tuple = heap_copytuple(tuple);
2946 : :
2947 : 1508 : systable_endscan(scan);
2948 : : }
2949 : :
2950 : 6841 : return tuple;
2951 : : }
2952 : :
2953 : : /*
2954 : : * getPublicationSchemaInfo
2955 : : *
2956 : : * Get publication name and schema name from the object address into pubname and
2957 : : * nspname. Both pubname and nspname are palloc'd strings which will be freed by
2958 : : * the caller.
2959 : : */
2960 : : static bool
1676 akapila@postgresql.o 2961 : 138 : getPublicationSchemaInfo(const ObjectAddress *object, bool missing_ok,
2962 : : char **pubname, char **nspname)
2963 : : {
2964 : : HeapTuple tup;
2965 : : Form_pg_publication_namespace pnform;
2966 : :
2967 : 138 : tup = SearchSysCache1(PUBLICATIONNAMESPACE,
2968 : 138 : ObjectIdGetDatum(object->objectId));
2969 [ + + ]: 138 : if (!HeapTupleIsValid(tup))
2970 : : {
2971 [ - + ]: 12 : if (!missing_ok)
1676 akapila@postgresql.o 2972 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for publication schema %u",
2973 : : object->objectId);
1676 akapila@postgresql.o 2974 :CBC 12 : return false;
2975 : : }
2976 : :
2977 : 126 : pnform = (Form_pg_publication_namespace) GETSTRUCT(tup);
2978 : 126 : *pubname = get_publication_name(pnform->pnpubid, missing_ok);
2979 [ - + ]: 126 : if (!(*pubname))
2980 : : {
1676 akapila@postgresql.o 2981 :UBC 0 : ReleaseSysCache(tup);
2982 : 0 : return false;
2983 : : }
2984 : :
1676 akapila@postgresql.o 2985 :CBC 126 : *nspname = get_namespace_name(pnform->pnnspid);
2986 [ - + ]: 126 : if (!(*nspname))
2987 : : {
1676 akapila@postgresql.o 2988 :UBC 0 : Oid schemaid = pnform->pnnspid;
2989 : :
2990 : 0 : pfree(*pubname);
2991 : 0 : ReleaseSysCache(tup);
2992 [ # # ]: 0 : if (!missing_ok)
2993 [ # # ]: 0 : elog(ERROR, "cache lookup failed for schema %u",
2994 : : schemaid);
2995 : 0 : return false;
2996 : : }
2997 : :
1676 akapila@postgresql.o 2998 :CBC 126 : ReleaseSysCache(tup);
2999 : 126 : return true;
3000 : : }
3001 : :
3002 : : /*
3003 : : * getObjectDescription: build an object description for messages
3004 : : *
3005 : : * The result is a palloc'd string. NULL is returned for an undefined
3006 : : * object if missing_ok is true, else an error is generated.
3007 : : */
3008 : : char *
2145 michael@paquier.xyz 3009 : 126844 : getObjectDescription(const ObjectAddress *object, bool missing_ok)
3010 : : {
3011 : : StringInfoData buffer;
3012 : :
4819 alvherre@alvh.no-ip. 3013 : 126844 : initStringInfo(&buffer);
3014 : :
795 peter@eisentraut.org 3015 : 126844 : switch (object->classId)
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - ]
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - ]
3016 : : {
3017 : 35100 : case RelationRelationId:
2928 tgl@sss.pgh.pa.us 3018 [ + + ]: 35100 : if (object->objectSubId == 0)
2145 michael@paquier.xyz 3019 : 32648 : getRelationDescription(&buffer, object->objectId, missing_ok);
3020 : : else
3021 : : {
3022 : : /* column, not whole relation */
3023 : : StringInfoData rel;
3024 : 2452 : char *attname = get_attname(object->objectId,
3025 : 2452 : object->objectSubId,
3026 : : missing_ok);
3027 : :
3028 [ + + ]: 2452 : if (!attname)
3029 : 4 : break;
3030 : :
2928 tgl@sss.pgh.pa.us 3031 : 2448 : initStringInfo(&rel);
2145 michael@paquier.xyz 3032 : 2448 : getRelationDescription(&rel, object->objectId, missing_ok);
3033 : : /* translator: second %s is, e.g., "table %s" */
2928 tgl@sss.pgh.pa.us 3034 : 2448 : appendStringInfo(&buffer, _("column %s of %s"),
3035 : : attname, rel.data);
3036 : 2448 : pfree(rel.data);
3037 : : }
4819 alvherre@alvh.no-ip. 3038 : 35096 : break;
3039 : :
795 peter@eisentraut.org 3040 : 2884 : case ProcedureRelationId:
3041 : : {
61 nathan@postgresql.or 3042 :GNC 2884 : uint16 flags = FORMAT_PROC_INVALID_AS_NULL;
2145 michael@paquier.xyz 3043 :CBC 2884 : char *proname = format_procedure_extended(object->objectId,
3044 : : flags);
3045 : :
3046 [ + + ]: 2884 : if (proname == NULL)
3047 : 4 : break;
3048 : :
3049 : 2880 : appendStringInfo(&buffer, _("function %s"), proname);
3050 : 2880 : break;
3051 : : }
3052 : :
795 peter@eisentraut.org 3053 : 51350 : case TypeRelationId:
3054 : : {
61 nathan@postgresql.or 3055 :GNC 51350 : uint16 flags = FORMAT_TYPE_INVALID_AS_NULL;
2145 michael@paquier.xyz 3056 :CBC 51350 : char *typname = format_type_extended(object->objectId, -1,
3057 : : flags);
3058 : :
3059 [ + + ]: 51350 : if (typname == NULL)
3060 : 4 : break;
3061 : :
3062 : 51346 : appendStringInfo(&buffer, _("type %s"), typname);
3063 : 51346 : break;
3064 : : }
3065 : :
795 peter@eisentraut.org 3066 : 190 : case CastRelationId:
3067 : : {
3068 : : Relation castDesc;
3069 : : ScanKeyData skey[1];
3070 : : SysScanDesc rcscan;
3071 : : HeapTuple tup;
3072 : : Form_pg_cast castForm;
3073 : :
2686 andres@anarazel.de 3074 : 190 : castDesc = table_open(CastRelationId, AccessShareLock);
3075 : :
4819 alvherre@alvh.no-ip. 3076 : 190 : ScanKeyInit(&skey[0],
3077 : : Anum_pg_cast_oid,
3078 : : BTEqualStrategyNumber, F_OIDEQ,
3079 : 190 : ObjectIdGetDatum(object->objectId));
3080 : :
3081 : 190 : rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
3082 : : NULL, 1, skey);
3083 : :
3084 : 190 : tup = systable_getnext(rcscan);
3085 : :
3086 [ + + ]: 190 : if (!HeapTupleIsValid(tup))
3087 : : {
2145 michael@paquier.xyz 3088 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3089 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for cast %u",
3090 : : object->objectId);
3091 : :
2145 michael@paquier.xyz 3092 :CBC 4 : systable_endscan(rcscan);
3093 : 4 : table_close(castDesc, AccessShareLock);
3094 : 4 : break;
3095 : : }
3096 : :
4819 alvherre@alvh.no-ip. 3097 : 186 : castForm = (Form_pg_cast) GETSTRUCT(tup);
3098 : :
3099 : 186 : appendStringInfo(&buffer, _("cast from %s to %s"),
3100 : : format_type_be(castForm->castsource),
3101 : : format_type_be(castForm->casttarget));
3102 : :
3103 : 186 : systable_endscan(rcscan);
2686 andres@anarazel.de 3104 : 186 : table_close(castDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 3105 : 186 : break;
3106 : : }
3107 : :
795 peter@eisentraut.org 3108 : 52 : case CollationRelationId:
3109 : : {
3110 : : HeapTuple collTup;
3111 : : Form_pg_collation coll;
3112 : : char *nspname;
3113 : :
4819 alvherre@alvh.no-ip. 3114 : 52 : collTup = SearchSysCache1(COLLOID,
3115 : 52 : ObjectIdGetDatum(object->objectId));
3116 [ + + ]: 52 : if (!HeapTupleIsValid(collTup))
3117 : : {
2145 michael@paquier.xyz 3118 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3119 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for collation %u",
3120 : : object->objectId);
2145 michael@paquier.xyz 3121 :CBC 4 : break;
3122 : : }
3123 : :
4819 alvherre@alvh.no-ip. 3124 : 48 : coll = (Form_pg_collation) GETSTRUCT(collTup);
3125 : :
3126 : : /* Qualify the name if not visible in search path */
2928 tgl@sss.pgh.pa.us 3127 [ + + ]: 48 : if (CollationIsVisible(object->objectId))
3128 : 43 : nspname = NULL;
3129 : : else
2928 tgl@sss.pgh.pa.us 3130 :GBC 5 : nspname = get_namespace_name(coll->collnamespace);
3131 : :
4819 alvherre@alvh.no-ip. 3132 :CBC 48 : appendStringInfo(&buffer, _("collation %s"),
3133 : : quote_qualified_identifier(nspname,
2928 tgl@sss.pgh.pa.us 3134 : 48 : NameStr(coll->collname)));
4819 alvherre@alvh.no-ip. 3135 : 48 : ReleaseSysCache(collTup);
3136 : 48 : break;
3137 : : }
3138 : :
795 peter@eisentraut.org 3139 : 17637 : case ConstraintRelationId:
3140 : : {
3141 : : HeapTuple conTup;
3142 : : Form_pg_constraint con;
3143 : :
4819 alvherre@alvh.no-ip. 3144 : 17637 : conTup = SearchSysCache1(CONSTROID,
3145 : 17637 : ObjectIdGetDatum(object->objectId));
3146 [ + + ]: 17637 : if (!HeapTupleIsValid(conTup))
3147 : : {
2145 michael@paquier.xyz 3148 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3149 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for constraint %u",
3150 : : object->objectId);
2145 michael@paquier.xyz 3151 :CBC 4 : break;
3152 : : }
3153 : :
4819 alvherre@alvh.no-ip. 3154 : 17633 : con = (Form_pg_constraint) GETSTRUCT(conTup);
3155 : :
3156 [ + + ]: 17633 : if (OidIsValid(con->conrelid))
3157 : : {
3158 : : StringInfoData rel;
3159 : :
3160 : 17383 : initStringInfo(&rel);
2145 michael@paquier.xyz 3161 : 17383 : getRelationDescription(&rel, con->conrelid, false);
3162 : : /* translator: second %s is, e.g., "table %s" */
4819 alvherre@alvh.no-ip. 3163 : 17383 : appendStringInfo(&buffer, _("constraint %s on %s"),
3164 : 17383 : NameStr(con->conname), rel.data);
3165 : 17383 : pfree(rel.data);
3166 : : }
3167 : : else
3168 : : {
3169 : 250 : appendStringInfo(&buffer, _("constraint %s"),
3170 : 250 : NameStr(con->conname));
3171 : : }
3172 : :
3173 : 17633 : ReleaseSysCache(conTup);
3174 : 17633 : break;
3175 : : }
3176 : :
795 peter@eisentraut.org 3177 : 24 : case ConversionRelationId:
3178 : : {
3179 : : HeapTuple conTup;
3180 : : Form_pg_conversion conv;
3181 : : char *nspname;
3182 : :
4819 alvherre@alvh.no-ip. 3183 : 24 : conTup = SearchSysCache1(CONVOID,
3184 : 24 : ObjectIdGetDatum(object->objectId));
3185 [ + + ]: 24 : if (!HeapTupleIsValid(conTup))
3186 : : {
2145 michael@paquier.xyz 3187 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3188 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for conversion %u",
3189 : : object->objectId);
2145 michael@paquier.xyz 3190 :CBC 4 : break;
3191 : : }
3192 : :
2928 tgl@sss.pgh.pa.us 3193 : 20 : conv = (Form_pg_conversion) GETSTRUCT(conTup);
3194 : :
3195 : : /* Qualify the name if not visible in search path */
3196 [ + + ]: 20 : if (ConversionIsVisible(object->objectId))
3197 : 12 : nspname = NULL;
3198 : : else
3199 : 8 : nspname = get_namespace_name(conv->connamespace);
3200 : :
4819 alvherre@alvh.no-ip. 3201 : 20 : appendStringInfo(&buffer, _("conversion %s"),
3202 : : quote_qualified_identifier(nspname,
2928 tgl@sss.pgh.pa.us 3203 : 20 : NameStr(conv->conname)));
4819 alvherre@alvh.no-ip. 3204 : 20 : ReleaseSysCache(conTup);
3205 : 20 : break;
3206 : : }
3207 : :
795 peter@eisentraut.org 3208 : 2155 : case AttrDefaultRelationId:
3209 : : {
3210 : : ObjectAddress colobject;
3211 : :
1531 tgl@sss.pgh.pa.us 3212 : 2155 : colobject = GetAttrDefaultColumnAddress(object->objectId);
3213 : :
3214 [ + + ]: 2155 : if (!OidIsValid(colobject.objectId))
3215 : : {
2145 michael@paquier.xyz 3216 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3217 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for attrdef %u",
3218 : : object->objectId);
2145 michael@paquier.xyz 3219 :CBC 4 : break;
3220 : : }
3221 : :
3222 : : /* translator: %s is typically "column %s of table %s" */
2928 tgl@sss.pgh.pa.us 3223 : 2151 : appendStringInfo(&buffer, _("default value for %s"),
3224 : : getObjectDescription(&colobject, false));
4819 alvherre@alvh.no-ip. 3225 : 2151 : break;
3226 : : }
3227 : :
795 peter@eisentraut.org 3228 : 13 : case LanguageRelationId:
3229 : : {
2145 michael@paquier.xyz 3230 : 13 : char *langname = get_language_name(object->objectId,
3231 : : missing_ok);
3232 : :
3233 [ + + ]: 13 : if (langname)
3234 : 9 : appendStringInfo(&buffer, _("language %s"),
3235 : 9 : get_language_name(object->objectId, false));
3236 : 13 : break;
3237 : : }
3238 : :
795 peter@eisentraut.org 3239 : 4 : case LargeObjectRelationId:
2145 michael@paquier.xyz 3240 [ + - ]: 4 : if (!LargeObjectExists(object->objectId))
3241 : 4 : break;
4819 alvherre@alvh.no-ip. 3242 :UBC 0 : appendStringInfo(&buffer, _("large object %u"),
3243 : 0 : object->objectId);
3244 : 0 : break;
3245 : :
795 peter@eisentraut.org 3246 :CBC 406 : case OperatorRelationId:
3247 : : {
61 nathan@postgresql.or 3248 :GNC 406 : uint16 flags = FORMAT_OPERATOR_INVALID_AS_NULL;
2145 michael@paquier.xyz 3249 :CBC 406 : char *oprname = format_operator_extended(object->objectId,
3250 : : flags);
3251 : :
3252 [ + + ]: 406 : if (oprname == NULL)
3253 : 4 : break;
3254 : :
3255 : 402 : appendStringInfo(&buffer, _("operator %s"), oprname);
3256 : 402 : break;
3257 : : }
3258 : :
795 peter@eisentraut.org 3259 : 164 : case OperatorClassRelationId:
3260 : : {
3261 : : HeapTuple opcTup;
3262 : : Form_pg_opclass opcForm;
3263 : : HeapTuple amTup;
3264 : : Form_pg_am amForm;
3265 : : char *nspname;
3266 : :
4819 alvherre@alvh.no-ip. 3267 : 164 : opcTup = SearchSysCache1(CLAOID,
3268 : 164 : ObjectIdGetDatum(object->objectId));
3269 [ + + ]: 164 : if (!HeapTupleIsValid(opcTup))
3270 : : {
2145 michael@paquier.xyz 3271 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3272 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for opclass %u",
3273 : : object->objectId);
2145 michael@paquier.xyz 3274 :CBC 4 : break;
3275 : : }
3276 : :
4819 alvherre@alvh.no-ip. 3277 : 160 : opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3278 : :
3279 : 160 : amTup = SearchSysCache1(AMOID,
3280 : : ObjectIdGetDatum(opcForm->opcmethod));
3281 [ - + ]: 160 : if (!HeapTupleIsValid(amTup))
4819 alvherre@alvh.no-ip. 3282 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for access method %u",
3283 : : opcForm->opcmethod);
4819 alvherre@alvh.no-ip. 3284 :CBC 160 : amForm = (Form_pg_am) GETSTRUCT(amTup);
3285 : :
3286 : : /* Qualify the name if not visible in search path */
3287 [ + + ]: 160 : if (OpclassIsVisible(object->objectId))
3288 : 144 : nspname = NULL;
3289 : : else
3290 : 16 : nspname = get_namespace_name(opcForm->opcnamespace);
3291 : :
3292 : 160 : appendStringInfo(&buffer, _("operator class %s for access method %s"),
3293 : : quote_qualified_identifier(nspname,
3265 tgl@sss.pgh.pa.us 3294 : 160 : NameStr(opcForm->opcname)),
4819 alvherre@alvh.no-ip. 3295 : 160 : NameStr(amForm->amname));
3296 : :
3297 : 160 : ReleaseSysCache(amTup);
3298 : 160 : ReleaseSysCache(opcTup);
3299 : 160 : break;
3300 : : }
3301 : :
795 peter@eisentraut.org 3302 : 170 : case OperatorFamilyRelationId:
2145 michael@paquier.xyz 3303 : 170 : getOpFamilyDescription(&buffer, object->objectId, missing_ok);
4819 alvherre@alvh.no-ip. 3304 : 170 : break;
3305 : :
795 peter@eisentraut.org 3306 : 45 : case AccessMethodRelationId:
3307 : : {
3308 : : HeapTuple tup;
3309 : :
3303 tgl@sss.pgh.pa.us 3310 : 45 : tup = SearchSysCache1(AMOID,
3311 : 45 : ObjectIdGetDatum(object->objectId));
3312 [ + + ]: 45 : if (!HeapTupleIsValid(tup))
3313 : : {
2145 michael@paquier.xyz 3314 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3315 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for access method %u",
3316 : : object->objectId);
2145 michael@paquier.xyz 3317 :CBC 4 : break;
3318 : : }
3319 : :
3303 tgl@sss.pgh.pa.us 3320 : 41 : appendStringInfo(&buffer, _("access method %s"),
3265 3321 : 41 : NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3303 3322 : 41 : ReleaseSysCache(tup);
3323 : 41 : break;
3324 : : }
3325 : :
795 peter@eisentraut.org 3326 : 1099 : case AccessMethodOperatorRelationId:
3327 : : {
3328 : : Relation amopDesc;
3329 : : HeapTuple tup;
3330 : : ScanKeyData skey[1];
3331 : : SysScanDesc amscan;
3332 : : Form_pg_amop amopForm;
3333 : : StringInfoData opfam;
3334 : :
2686 andres@anarazel.de 3335 : 1099 : amopDesc = table_open(AccessMethodOperatorRelationId,
3336 : : AccessShareLock);
3337 : :
4819 alvherre@alvh.no-ip. 3338 : 1099 : ScanKeyInit(&skey[0],
3339 : : Anum_pg_amop_oid,
3340 : : BTEqualStrategyNumber, F_OIDEQ,
3341 : 1099 : ObjectIdGetDatum(object->objectId));
3342 : :
3343 : 1099 : amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3344 : : NULL, 1, skey);
3345 : :
3346 : 1099 : tup = systable_getnext(amscan);
3347 : :
3348 [ + + ]: 1099 : if (!HeapTupleIsValid(tup))
3349 : : {
2145 michael@paquier.xyz 3350 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3351 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for amop entry %u",
3352 : : object->objectId);
3353 : :
2145 michael@paquier.xyz 3354 :CBC 4 : systable_endscan(amscan);
3355 : 4 : table_close(amopDesc, AccessShareLock);
3356 : 4 : break;
3357 : : }
3358 : :
4819 alvherre@alvh.no-ip. 3359 : 1095 : amopForm = (Form_pg_amop) GETSTRUCT(tup);
3360 : :
3361 : 1095 : initStringInfo(&opfam);
2145 michael@paquier.xyz 3362 : 1095 : getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3363 : :
3364 : : /*
3365 : : * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3366 : : * completely if the type links are dangling, which is a form
3367 : : * of catalog corruption that could occur due to old bugs.
3368 : : */
3369 : :
3370 : : /*------
3371 : : translator: %d is the operator strategy (a number), the
3372 : : first two %s's are data type names, the third %s is the
3373 : : description of the operator family, and the last %s is the
3374 : : textual form of the operator with arguments. */
4819 alvherre@alvh.no-ip. 3375 : 1095 : appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3376 : 1095 : amopForm->amopstrategy,
3377 : : format_type_extended(amopForm->amoplefttype,
3378 : : -1, FORMAT_TYPE_ALLOW_INVALID),
3379 : : format_type_extended(amopForm->amoprighttype,
3380 : : -1, FORMAT_TYPE_ALLOW_INVALID),
3381 : : opfam.data,
3382 : : format_operator(amopForm->amopopr));
3383 : :
3384 : 1095 : pfree(opfam.data);
3385 : :
3386 : 1095 : systable_endscan(amscan);
2686 andres@anarazel.de 3387 : 1095 : table_close(amopDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 3388 : 1095 : break;
3389 : : }
3390 : :
795 peter@eisentraut.org 3391 : 882 : case AccessMethodProcedureRelationId:
3392 : : {
3393 : : Relation amprocDesc;
3394 : : ScanKeyData skey[1];
3395 : : SysScanDesc amscan;
3396 : : HeapTuple tup;
3397 : : Form_pg_amproc amprocForm;
3398 : : StringInfoData opfam;
3399 : :
2686 andres@anarazel.de 3400 : 882 : amprocDesc = table_open(AccessMethodProcedureRelationId,
3401 : : AccessShareLock);
3402 : :
4819 alvherre@alvh.no-ip. 3403 : 882 : ScanKeyInit(&skey[0],
3404 : : Anum_pg_amproc_oid,
3405 : : BTEqualStrategyNumber, F_OIDEQ,
3406 : 882 : ObjectIdGetDatum(object->objectId));
3407 : :
3408 : 882 : amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3409 : : NULL, 1, skey);
3410 : :
3411 : 882 : tup = systable_getnext(amscan);
3412 : :
3413 [ + + ]: 882 : if (!HeapTupleIsValid(tup))
3414 : : {
2145 michael@paquier.xyz 3415 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3416 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for amproc entry %u",
3417 : : object->objectId);
3418 : :
2145 michael@paquier.xyz 3419 :CBC 4 : systable_endscan(amscan);
3420 : 4 : table_close(amprocDesc, AccessShareLock);
3421 : 4 : break;
3422 : : }
3423 : :
4819 alvherre@alvh.no-ip. 3424 : 878 : amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3425 : :
3426 : 878 : initStringInfo(&opfam);
2145 michael@paquier.xyz 3427 : 878 : getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3428 : :
3429 : : /*
3430 : : * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3431 : : * completely if the type links are dangling, which is a form
3432 : : * of catalog corruption that could occur due to old bugs.
3433 : : */
3434 : :
3435 : : /*------
3436 : : translator: %d is the function number, the first two %s's
3437 : : are data type names, the third %s is the description of the
3438 : : operator family, and the last %s is the textual form of the
3439 : : function with arguments. */
4819 alvherre@alvh.no-ip. 3440 : 878 : appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3441 : 878 : amprocForm->amprocnum,
3442 : : format_type_extended(amprocForm->amproclefttype,
3443 : : -1, FORMAT_TYPE_ALLOW_INVALID),
3444 : : format_type_extended(amprocForm->amprocrighttype,
3445 : : -1, FORMAT_TYPE_ALLOW_INVALID),
3446 : : opfam.data,
3447 : : format_procedure(amprocForm->amproc));
3448 : :
3449 : 878 : pfree(opfam.data);
3450 : :
3451 : 878 : systable_endscan(amscan);
2686 andres@anarazel.de 3452 : 878 : table_close(amprocDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 3453 : 878 : break;
3454 : : }
3455 : :
795 peter@eisentraut.org 3456 : 1871 : case RewriteRelationId:
3457 : : {
3458 : : Relation ruleDesc;
3459 : : ScanKeyData skey[1];
3460 : : SysScanDesc rcscan;
3461 : : HeapTuple tup;
3462 : : Form_pg_rewrite rule;
3463 : : StringInfoData rel;
3464 : :
2686 andres@anarazel.de 3465 : 1871 : ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3466 : :
4819 alvherre@alvh.no-ip. 3467 : 1871 : ScanKeyInit(&skey[0],
3468 : : Anum_pg_rewrite_oid,
3469 : : BTEqualStrategyNumber, F_OIDEQ,
3470 : 1871 : ObjectIdGetDatum(object->objectId));
3471 : :
3472 : 1871 : rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3473 : : NULL, 1, skey);
3474 : :
3475 : 1871 : tup = systable_getnext(rcscan);
3476 : :
3477 [ + + ]: 1871 : if (!HeapTupleIsValid(tup))
3478 : : {
2145 michael@paquier.xyz 3479 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3480 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for rule %u",
3481 : : object->objectId);
3482 : :
2145 michael@paquier.xyz 3483 :CBC 4 : systable_endscan(rcscan);
3484 : 4 : table_close(ruleDesc, AccessShareLock);
3485 : 4 : break;
3486 : : }
3487 : :
4819 alvherre@alvh.no-ip. 3488 : 1867 : rule = (Form_pg_rewrite) GETSTRUCT(tup);
3489 : :
2928 tgl@sss.pgh.pa.us 3490 : 1867 : initStringInfo(&rel);
2145 michael@paquier.xyz 3491 : 1867 : getRelationDescription(&rel, rule->ev_class, false);
3492 : :
3493 : : /* translator: second %s is, e.g., "table %s" */
2928 tgl@sss.pgh.pa.us 3494 : 1867 : appendStringInfo(&buffer, _("rule %s on %s"),
3495 : 1867 : NameStr(rule->rulename), rel.data);
3496 : 1867 : pfree(rel.data);
4819 alvherre@alvh.no-ip. 3497 : 1867 : systable_endscan(rcscan);
2686 andres@anarazel.de 3498 : 1867 : table_close(ruleDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 3499 : 1867 : break;
3500 : : }
3501 : :
795 peter@eisentraut.org 3502 : 9030 : case TriggerRelationId:
3503 : : {
3504 : : Relation trigDesc;
3505 : : ScanKeyData skey[1];
3506 : : SysScanDesc tgscan;
3507 : : HeapTuple tup;
3508 : : Form_pg_trigger trig;
3509 : : StringInfoData rel;
3510 : :
2686 andres@anarazel.de 3511 : 9030 : trigDesc = table_open(TriggerRelationId, AccessShareLock);
3512 : :
4819 alvherre@alvh.no-ip. 3513 : 9030 : ScanKeyInit(&skey[0],
3514 : : Anum_pg_trigger_oid,
3515 : : BTEqualStrategyNumber, F_OIDEQ,
3516 : 9030 : ObjectIdGetDatum(object->objectId));
3517 : :
3518 : 9030 : tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3519 : : NULL, 1, skey);
3520 : :
3521 : 9030 : tup = systable_getnext(tgscan);
3522 : :
3523 [ + + ]: 9030 : if (!HeapTupleIsValid(tup))
3524 : : {
2145 michael@paquier.xyz 3525 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3526 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for trigger %u",
3527 : : object->objectId);
3528 : :
2145 michael@paquier.xyz 3529 :CBC 4 : systable_endscan(tgscan);
3530 : 4 : table_close(trigDesc, AccessShareLock);
3531 : 4 : break;
3532 : : }
3533 : :
4819 alvherre@alvh.no-ip. 3534 : 9026 : trig = (Form_pg_trigger) GETSTRUCT(tup);
3535 : :
2928 tgl@sss.pgh.pa.us 3536 : 9026 : initStringInfo(&rel);
2145 michael@paquier.xyz 3537 : 9026 : getRelationDescription(&rel, trig->tgrelid, false);
3538 : :
3539 : : /* translator: second %s is, e.g., "table %s" */
2928 tgl@sss.pgh.pa.us 3540 : 9026 : appendStringInfo(&buffer, _("trigger %s on %s"),
3541 : 9026 : NameStr(trig->tgname), rel.data);
3542 : 9026 : pfree(rel.data);
4819 alvherre@alvh.no-ip. 3543 : 9026 : systable_endscan(tgscan);
2686 andres@anarazel.de 3544 : 9026 : table_close(trigDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 3545 : 9026 : break;
3546 : : }
3547 : :
795 peter@eisentraut.org 3548 : 102 : case NamespaceRelationId:
3549 : : {
3550 : : char *nspname;
3551 : :
4819 alvherre@alvh.no-ip. 3552 : 102 : nspname = get_namespace_name(object->objectId);
3553 [ + + ]: 102 : if (!nspname)
3554 : : {
2145 michael@paquier.xyz 3555 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3556 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for namespace %u",
3557 : : object->objectId);
2145 michael@paquier.xyz 3558 :CBC 4 : break;
3559 : : }
4819 alvherre@alvh.no-ip. 3560 : 98 : appendStringInfo(&buffer, _("schema %s"), nspname);
3561 : 98 : break;
3562 : : }
3563 : :
795 peter@eisentraut.org 3564 : 370 : case StatisticExtRelationId:
3565 : : {
3566 : : HeapTuple stxTup;
3567 : : Form_pg_statistic_ext stxForm;
3568 : : char *nspname;
3569 : :
3303 tgl@sss.pgh.pa.us 3570 : 370 : stxTup = SearchSysCache1(STATEXTOID,
3571 : 370 : ObjectIdGetDatum(object->objectId));
3572 [ + + ]: 370 : if (!HeapTupleIsValid(stxTup))
3573 : : {
2145 michael@paquier.xyz 3574 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3575 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for statistics object %u",
3576 : : object->objectId);
2145 michael@paquier.xyz 3577 :CBC 4 : break;
3578 : : }
3579 : :
3303 tgl@sss.pgh.pa.us 3580 : 366 : stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3581 : :
3582 : : /* Qualify the name if not visible in search path */
2928 3583 [ + + ]: 366 : if (StatisticsObjIsVisible(object->objectId))
3584 : 246 : nspname = NULL;
3585 : : else
3586 : 120 : nspname = get_namespace_name(stxForm->stxnamespace);
3587 : :
3303 3588 : 366 : appendStringInfo(&buffer, _("statistics object %s"),
3589 : : quote_qualified_identifier(nspname,
2928 3590 : 366 : NameStr(stxForm->stxname)));
3591 : :
3303 3592 : 366 : ReleaseSysCache(stxTup);
3593 : 366 : break;
3594 : : }
3595 : :
795 peter@eisentraut.org 3596 : 29 : case TSParserRelationId:
3597 : : {
3598 : : HeapTuple tup;
3599 : : Form_pg_ts_parser prsForm;
3600 : : char *nspname;
3601 : :
4819 alvherre@alvh.no-ip. 3602 : 29 : tup = SearchSysCache1(TSPARSEROID,
3603 : 29 : ObjectIdGetDatum(object->objectId));
3604 [ + + ]: 29 : if (!HeapTupleIsValid(tup))
3605 : : {
2145 michael@paquier.xyz 3606 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3607 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search parser %u",
3608 : : object->objectId);
2145 michael@paquier.xyz 3609 :CBC 4 : break;
3610 : : }
2928 tgl@sss.pgh.pa.us 3611 : 25 : prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3612 : :
3613 : : /* Qualify the name if not visible in search path */
3614 [ + + ]: 25 : if (TSParserIsVisible(object->objectId))
3615 : 12 : nspname = NULL;
3616 : : else
3617 : 13 : nspname = get_namespace_name(prsForm->prsnamespace);
3618 : :
4819 alvherre@alvh.no-ip. 3619 : 25 : appendStringInfo(&buffer, _("text search parser %s"),
3620 : : quote_qualified_identifier(nspname,
2928 tgl@sss.pgh.pa.us 3621 : 25 : NameStr(prsForm->prsname)));
4819 alvherre@alvh.no-ip. 3622 : 25 : ReleaseSysCache(tup);
3623 : 25 : break;
3624 : : }
3625 : :
795 peter@eisentraut.org 3626 : 32 : case TSDictionaryRelationId:
3627 : : {
3628 : : HeapTuple tup;
3629 : : Form_pg_ts_dict dictForm;
3630 : : char *nspname;
3631 : :
4819 alvherre@alvh.no-ip. 3632 : 32 : tup = SearchSysCache1(TSDICTOID,
3633 : 32 : ObjectIdGetDatum(object->objectId));
3634 [ + + ]: 32 : if (!HeapTupleIsValid(tup))
3635 : : {
2145 michael@paquier.xyz 3636 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3637 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search dictionary %u",
3638 : : object->objectId);
2145 michael@paquier.xyz 3639 :CBC 4 : break;
3640 : : }
3641 : :
2928 tgl@sss.pgh.pa.us 3642 : 28 : dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3643 : :
3644 : : /* Qualify the name if not visible in search path */
3645 [ + + ]: 28 : if (TSDictionaryIsVisible(object->objectId))
3646 : 16 : nspname = NULL;
3647 : : else
3648 : 12 : nspname = get_namespace_name(dictForm->dictnamespace);
3649 : :
4819 alvherre@alvh.no-ip. 3650 : 28 : appendStringInfo(&buffer, _("text search dictionary %s"),
3651 : : quote_qualified_identifier(nspname,
2928 tgl@sss.pgh.pa.us 3652 : 28 : NameStr(dictForm->dictname)));
4819 alvherre@alvh.no-ip. 3653 : 28 : ReleaseSysCache(tup);
3654 : 28 : break;
3655 : : }
3656 : :
795 peter@eisentraut.org 3657 : 28 : case TSTemplateRelationId:
3658 : : {
3659 : : HeapTuple tup;
3660 : : Form_pg_ts_template tmplForm;
3661 : : char *nspname;
3662 : :
4819 alvherre@alvh.no-ip. 3663 : 28 : tup = SearchSysCache1(TSTEMPLATEOID,
3664 : 28 : ObjectIdGetDatum(object->objectId));
3665 [ + + ]: 28 : if (!HeapTupleIsValid(tup))
3666 : : {
2145 michael@paquier.xyz 3667 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3668 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search template %u",
3669 : : object->objectId);
2145 michael@paquier.xyz 3670 :CBC 4 : break;
3671 : : }
3672 : :
2928 tgl@sss.pgh.pa.us 3673 : 24 : tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3674 : :
3675 : : /* Qualify the name if not visible in search path */
3676 [ + + ]: 24 : if (TSTemplateIsVisible(object->objectId))
3677 : 12 : nspname = NULL;
3678 : : else
3679 : 12 : nspname = get_namespace_name(tmplForm->tmplnamespace);
3680 : :
4819 alvherre@alvh.no-ip. 3681 : 24 : appendStringInfo(&buffer, _("text search template %s"),
3682 : : quote_qualified_identifier(nspname,
2928 tgl@sss.pgh.pa.us 3683 : 24 : NameStr(tmplForm->tmplname)));
4819 alvherre@alvh.no-ip. 3684 : 24 : ReleaseSysCache(tup);
3685 : 24 : break;
3686 : : }
3687 : :
795 peter@eisentraut.org 3688 : 32 : case TSConfigRelationId:
3689 : : {
3690 : : HeapTuple tup;
3691 : : Form_pg_ts_config cfgForm;
3692 : : char *nspname;
3693 : :
4819 alvherre@alvh.no-ip. 3694 : 32 : tup = SearchSysCache1(TSCONFIGOID,
3695 : 32 : ObjectIdGetDatum(object->objectId));
3696 [ + + ]: 32 : if (!HeapTupleIsValid(tup))
3697 : : {
2145 michael@paquier.xyz 3698 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3699 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search configuration %u",
3700 : : object->objectId);
2145 michael@paquier.xyz 3701 :CBC 4 : break;
3702 : : }
3703 : :
2928 tgl@sss.pgh.pa.us 3704 : 28 : cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3705 : :
3706 : : /* Qualify the name if not visible in search path */
3707 [ + + ]: 28 : if (TSConfigIsVisible(object->objectId))
3708 : 16 : nspname = NULL;
3709 : : else
3710 : 12 : nspname = get_namespace_name(cfgForm->cfgnamespace);
3711 : :
4819 alvherre@alvh.no-ip. 3712 : 28 : appendStringInfo(&buffer, _("text search configuration %s"),
3713 : : quote_qualified_identifier(nspname,
2928 tgl@sss.pgh.pa.us 3714 : 28 : NameStr(cfgForm->cfgname)));
4819 alvherre@alvh.no-ip. 3715 : 28 : ReleaseSysCache(tup);
3716 : 28 : break;
3717 : : }
3718 : :
795 peter@eisentraut.org 3719 : 84 : case AuthIdRelationId:
3720 : : {
2145 michael@paquier.xyz 3721 : 84 : char *username = GetUserNameFromId(object->objectId,
3722 : : missing_ok);
3723 : :
3724 [ + + ]: 84 : if (username)
3725 : 80 : appendStringInfo(&buffer, _("role %s"), username);
4819 alvherre@alvh.no-ip. 3726 : 84 : break;
3727 : : }
3728 : :
795 peter@eisentraut.org 3729 : 36 : case AuthMemRelationId:
3730 : : {
3731 : : Relation amDesc;
3732 : : ScanKeyData skey[1];
3733 : : SysScanDesc rcscan;
3734 : : HeapTuple tup;
3735 : : Form_pg_auth_members amForm;
3736 : :
1381 rhaas@postgresql.org 3737 : 36 : amDesc = table_open(AuthMemRelationId, AccessShareLock);
3738 : :
3739 : 36 : ScanKeyInit(&skey[0],
3740 : : Anum_pg_auth_members_oid,
3741 : : BTEqualStrategyNumber, F_OIDEQ,
3742 : 36 : ObjectIdGetDatum(object->objectId));
3743 : :
3744 : 36 : rcscan = systable_beginscan(amDesc, AuthMemOidIndexId, true,
3745 : : NULL, 1, skey);
3746 : :
3747 : 36 : tup = systable_getnext(rcscan);
3748 : :
3749 [ + + ]: 36 : if (!HeapTupleIsValid(tup))
3750 : : {
3751 [ - + ]: 4 : if (!missing_ok)
1381 rhaas@postgresql.org 3752 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for role membership %u",
3753 : : object->objectId);
3754 : :
1381 rhaas@postgresql.org 3755 :CBC 4 : systable_endscan(rcscan);
3756 : 4 : table_close(amDesc, AccessShareLock);
3757 : 4 : break;
3758 : : }
3759 : :
3760 : 32 : amForm = (Form_pg_auth_members) GETSTRUCT(tup);
3761 : :
3762 : 32 : appendStringInfo(&buffer, _("membership of role %s in role %s"),
3763 : : GetUserNameFromId(amForm->member, false),
3764 : : GetUserNameFromId(amForm->roleid, false));
3765 : :
3766 : 32 : systable_endscan(rcscan);
3767 : 32 : table_close(amDesc, AccessShareLock);
3768 : 32 : break;
3769 : : }
3770 : :
795 peter@eisentraut.org 3771 : 12 : case DatabaseRelationId:
3772 : : {
3773 : : char *datname;
3774 : :
4819 alvherre@alvh.no-ip. 3775 : 12 : datname = get_database_name(object->objectId);
3776 [ + + ]: 12 : if (!datname)
3777 : : {
2145 michael@paquier.xyz 3778 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3779 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for database %u",
3780 : : object->objectId);
2145 michael@paquier.xyz 3781 :CBC 4 : break;
3782 : : }
4819 alvherre@alvh.no-ip. 3783 : 8 : appendStringInfo(&buffer, _("database %s"), datname);
3784 : 8 : break;
3785 : : }
3786 : :
795 peter@eisentraut.org 3787 : 4 : case TableSpaceRelationId:
3788 : : {
3789 : : char *tblspace;
3790 : :
4819 alvherre@alvh.no-ip. 3791 : 4 : tblspace = get_tablespace_name(object->objectId);
3792 [ + - ]: 4 : if (!tblspace)
3793 : : {
2145 michael@paquier.xyz 3794 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3795 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for tablespace %u",
3796 : : object->objectId);
2145 michael@paquier.xyz 3797 :CBC 4 : break;
3798 : : }
4819 alvherre@alvh.no-ip. 3799 :UBC 0 : appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3800 : 0 : break;
3801 : : }
3802 : :
795 peter@eisentraut.org 3803 :CBC 62 : case ForeignDataWrapperRelationId:
3804 : : {
3805 : : ForeignDataWrapper *fdw;
3806 : :
2145 michael@paquier.xyz 3807 : 62 : fdw = GetForeignDataWrapperExtended(object->objectId,
3808 : : missing_ok);
3809 [ + + ]: 62 : if (fdw)
3810 : 58 : appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
4819 alvherre@alvh.no-ip. 3811 : 62 : break;
3812 : : }
3813 : :
795 peter@eisentraut.org 3814 : 90 : case ForeignServerRelationId:
3815 : : {
3816 : : ForeignServer *srv;
3817 : :
2145 michael@paquier.xyz 3818 : 90 : srv = GetForeignServerExtended(object->objectId, missing_ok);
3819 [ + + ]: 90 : if (srv)
3820 : 86 : appendStringInfo(&buffer, _("server %s"), srv->servername);
4819 alvherre@alvh.no-ip. 3821 : 90 : break;
3822 : : }
3823 : :
795 peter@eisentraut.org 3824 : 91 : case UserMappingRelationId:
3825 : : {
3826 : : HeapTuple tup;
3827 : : Oid useid;
3828 : : char *usename;
3829 : : Form_pg_user_mapping umform;
3830 : : ForeignServer *srv;
3831 : :
4819 alvherre@alvh.no-ip. 3832 : 91 : tup = SearchSysCache1(USERMAPPINGOID,
3833 : 91 : ObjectIdGetDatum(object->objectId));
3834 [ + + ]: 91 : if (!HeapTupleIsValid(tup))
3835 : : {
2145 michael@paquier.xyz 3836 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3837 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for user mapping %u",
3838 : : object->objectId);
2145 michael@paquier.xyz 3839 :CBC 4 : break;
3840 : : }
3841 : :
4104 alvherre@alvh.no-ip. 3842 : 87 : umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3843 : 87 : useid = umform->umuser;
3844 : 87 : srv = GetForeignServer(umform->umserver);
3845 : :
4819 3846 : 87 : ReleaseSysCache(tup);
3847 : :
3848 [ + + ]: 87 : if (OidIsValid(useid))
4039 andrew@dunslane.net 3849 : 66 : usename = GetUserNameFromId(useid, false);
3850 : : else
4819 alvherre@alvh.no-ip. 3851 : 21 : usename = "public";
3852 : :
4104 3853 : 87 : appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3854 : : srv->servername);
4819 3855 : 87 : break;
3856 : : }
3857 : :
795 peter@eisentraut.org 3858 : 32 : case DefaultAclRelationId:
3859 : : {
3860 : : Relation defaclrel;
3861 : : ScanKeyData skey[1];
3862 : : SysScanDesc rcscan;
3863 : : HeapTuple tup;
3864 : : Form_pg_default_acl defacl;
3865 : : char *rolename;
3866 : : char *nspname;
3867 : :
2686 andres@anarazel.de 3868 : 32 : defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3869 : :
4819 alvherre@alvh.no-ip. 3870 : 32 : ScanKeyInit(&skey[0],
3871 : : Anum_pg_default_acl_oid,
3872 : : BTEqualStrategyNumber, F_OIDEQ,
3873 : 32 : ObjectIdGetDatum(object->objectId));
3874 : :
3875 : 32 : rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3876 : : true, NULL, 1, skey);
3877 : :
3878 : 32 : tup = systable_getnext(rcscan);
3879 : :
3880 [ + + ]: 32 : if (!HeapTupleIsValid(tup))
3881 : : {
2145 michael@paquier.xyz 3882 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3883 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for default ACL %u",
3884 : : object->objectId);
3885 : :
2145 michael@paquier.xyz 3886 :CBC 4 : systable_endscan(rcscan);
3887 : 4 : table_close(defaclrel, AccessShareLock);
3888 : 4 : break;
3889 : : }
3890 : :
4819 alvherre@alvh.no-ip. 3891 : 28 : defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3892 : :
2928 tgl@sss.pgh.pa.us 3893 : 28 : rolename = GetUserNameFromId(defacl->defaclrole, false);
3894 : :
3895 [ + + ]: 28 : if (OidIsValid(defacl->defaclnamespace))
3896 : 20 : nspname = get_namespace_name(defacl->defaclnamespace);
3897 : : else
3898 : 8 : nspname = NULL;
3899 : :
4819 alvherre@alvh.no-ip. 3900 [ + - + + : 28 : switch (defacl->defaclobjtype)
- - - ]
3901 : : {
3902 : 20 : case DEFACLOBJ_RELATION:
2928 tgl@sss.pgh.pa.us 3903 [ + + ]: 20 : if (nspname)
3904 : 12 : appendStringInfo(&buffer,
3905 : 12 : _("default privileges on new relations belonging to role %s in schema %s"),
3906 : : rolename, nspname);
3907 : : else
3908 : 8 : appendStringInfo(&buffer,
3909 : 8 : _("default privileges on new relations belonging to role %s"),
3910 : : rolename);
4819 alvherre@alvh.no-ip. 3911 : 20 : break;
4819 alvherre@alvh.no-ip. 3912 :UBC 0 : case DEFACLOBJ_SEQUENCE:
2928 tgl@sss.pgh.pa.us 3913 [ # # ]: 0 : if (nspname)
3914 : 0 : appendStringInfo(&buffer,
3915 : 0 : _("default privileges on new sequences belonging to role %s in schema %s"),
3916 : : rolename, nspname);
3917 : : else
3918 : 0 : appendStringInfo(&buffer,
3919 : 0 : _("default privileges on new sequences belonging to role %s"),
3920 : : rolename);
4819 alvherre@alvh.no-ip. 3921 : 0 : break;
4819 alvherre@alvh.no-ip. 3922 :CBC 4 : case DEFACLOBJ_FUNCTION:
2928 tgl@sss.pgh.pa.us 3923 [ + - ]: 4 : if (nspname)
3924 : 4 : appendStringInfo(&buffer,
3925 : 4 : _("default privileges on new functions belonging to role %s in schema %s"),
3926 : : rolename, nspname);
3927 : : else
2928 tgl@sss.pgh.pa.us 3928 :UBC 0 : appendStringInfo(&buffer,
3929 : 0 : _("default privileges on new functions belonging to role %s"),
3930 : : rolename);
4819 alvherre@alvh.no-ip. 3931 :CBC 4 : break;
3932 : 4 : case DEFACLOBJ_TYPE:
2928 tgl@sss.pgh.pa.us 3933 [ + - ]: 4 : if (nspname)
3934 : 4 : appendStringInfo(&buffer,
3935 : 4 : _("default privileges on new types belonging to role %s in schema %s"),
3936 : : rolename, nspname);
3937 : : else
2928 tgl@sss.pgh.pa.us 3938 :UBC 0 : appendStringInfo(&buffer,
3939 : 0 : _("default privileges on new types belonging to role %s"),
3940 : : rolename);
4819 alvherre@alvh.no-ip. 3941 :CBC 4 : break;
3350 teodor@sigaev.ru 3942 :UBC 0 : case DEFACLOBJ_NAMESPACE:
2928 tgl@sss.pgh.pa.us 3943 [ # # ]: 0 : Assert(!nspname);
3350 teodor@sigaev.ru 3944 : 0 : appendStringInfo(&buffer,
3945 : 0 : _("default privileges on new schemas belonging to role %s"),
3946 : : rolename);
3947 : 0 : break;
421 fujii@postgresql.org 3948 : 0 : case DEFACLOBJ_LARGEOBJECT:
3949 [ # # ]: 0 : Assert(!nspname);
3950 : 0 : appendStringInfo(&buffer,
3951 : 0 : _("default privileges on new large objects belonging to role %s"),
3952 : : rolename);
3953 : 0 : break;
4819 alvherre@alvh.no-ip. 3954 : 0 : default:
3955 : : /* shouldn't get here */
2928 tgl@sss.pgh.pa.us 3956 [ # # ]: 0 : if (nspname)
3957 : 0 : appendStringInfo(&buffer,
3958 : 0 : _("default privileges belonging to role %s in schema %s"),
3959 : : rolename, nspname);
3960 : : else
3961 : 0 : appendStringInfo(&buffer,
3962 : 0 : _("default privileges belonging to role %s"),
3963 : : rolename);
4819 alvherre@alvh.no-ip. 3964 : 0 : break;
3965 : : }
3966 : :
4819 alvherre@alvh.no-ip. 3967 :CBC 28 : systable_endscan(rcscan);
2686 andres@anarazel.de 3968 : 28 : table_close(defaclrel, AccessShareLock);
4819 alvherre@alvh.no-ip. 3969 : 28 : break;
3970 : : }
3971 : :
795 peter@eisentraut.org 3972 : 30 : case ExtensionRelationId:
3973 : : {
3974 : : char *extname;
3975 : :
4819 alvherre@alvh.no-ip. 3976 : 30 : extname = get_extension_name(object->objectId);
3977 [ + + ]: 30 : if (!extname)
3978 : : {
2145 michael@paquier.xyz 3979 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3980 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for extension %u",
3981 : : object->objectId);
2145 michael@paquier.xyz 3982 :CBC 4 : break;
3983 : : }
4819 alvherre@alvh.no-ip. 3984 : 26 : appendStringInfo(&buffer, _("extension %s"), extname);
3985 : 26 : break;
3986 : : }
3987 : :
795 peter@eisentraut.org 3988 : 25 : case EventTriggerRelationId:
3989 : : {
3990 : : HeapTuple tup;
3991 : :
4819 alvherre@alvh.no-ip. 3992 : 25 : tup = SearchSysCache1(EVENTTRIGGEROID,
3993 : 25 : ObjectIdGetDatum(object->objectId));
3994 [ + + ]: 25 : if (!HeapTupleIsValid(tup))
3995 : : {
2145 michael@paquier.xyz 3996 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 3997 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for event trigger %u",
3998 : : object->objectId);
2145 michael@paquier.xyz 3999 :CBC 4 : break;
4000 : : }
4819 alvherre@alvh.no-ip. 4001 : 21 : appendStringInfo(&buffer, _("event trigger %s"),
3265 tgl@sss.pgh.pa.us 4002 : 21 : NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
4819 alvherre@alvh.no-ip. 4003 : 21 : ReleaseSysCache(tup);
4004 : 21 : break;
4005 : : }
4006 : :
795 peter@eisentraut.org 4007 : 65 : case ParameterAclRelationId:
4008 : : {
4009 : : HeapTuple tup;
4010 : : Datum nameDatum;
4011 : : char *parname;
4012 : :
1515 tgl@sss.pgh.pa.us 4013 : 65 : tup = SearchSysCache1(PARAMETERACLOID,
4014 : 65 : ObjectIdGetDatum(object->objectId));
4015 [ + + ]: 65 : if (!HeapTupleIsValid(tup))
4016 : : {
4017 [ - + ]: 4 : if (!missing_ok)
1515 tgl@sss.pgh.pa.us 4018 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for parameter ACL %u",
4019 : : object->objectId);
1515 tgl@sss.pgh.pa.us 4020 :CBC 4 : break;
4021 : : }
1162 dgustafsson@postgres 4022 : 61 : nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
4023 : : Anum_pg_parameter_acl_parname);
1515 tgl@sss.pgh.pa.us 4024 : 61 : parname = TextDatumGetCString(nameDatum);
4025 : 61 : appendStringInfo(&buffer, _("parameter %s"), parname);
4026 : 61 : ReleaseSysCache(tup);
4027 : 61 : break;
4028 : : }
4029 : :
795 peter@eisentraut.org 4030 : 369 : case PolicyRelationId:
4031 : : {
4032 : : Relation policy_rel;
4033 : : ScanKeyData skey[1];
4034 : : SysScanDesc sscan;
4035 : : HeapTuple tuple;
4036 : : Form_pg_policy form_policy;
4037 : : StringInfoData rel;
4038 : :
2686 andres@anarazel.de 4039 : 369 : policy_rel = table_open(PolicyRelationId, AccessShareLock);
4040 : :
4271 sfrost@snowman.net 4041 : 369 : ScanKeyInit(&skey[0],
4042 : : Anum_pg_policy_oid,
4043 : : BTEqualStrategyNumber, F_OIDEQ,
4044 : 369 : ObjectIdGetDatum(object->objectId));
4045 : :
4202 4046 : 369 : sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
4047 : : true, NULL, 1, skey);
4048 : :
4271 4049 : 369 : tuple = systable_getnext(sscan);
4050 : :
4051 [ + + ]: 369 : if (!HeapTupleIsValid(tuple))
4052 : : {
2145 michael@paquier.xyz 4053 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 4054 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for policy %u",
4055 : : object->objectId);
4056 : :
2145 michael@paquier.xyz 4057 :CBC 4 : systable_endscan(sscan);
4058 : 4 : table_close(policy_rel, AccessShareLock);
4059 : 4 : break;
4060 : : }
4061 : :
4202 sfrost@snowman.net 4062 : 365 : form_policy = (Form_pg_policy) GETSTRUCT(tuple);
4063 : :
2928 tgl@sss.pgh.pa.us 4064 : 365 : initStringInfo(&rel);
2145 michael@paquier.xyz 4065 : 365 : getRelationDescription(&rel, form_policy->polrelid, false);
4066 : :
4067 : : /* translator: second %s is, e.g., "table %s" */
2928 tgl@sss.pgh.pa.us 4068 : 365 : appendStringInfo(&buffer, _("policy %s on %s"),
4069 : 365 : NameStr(form_policy->polname), rel.data);
4070 : 365 : pfree(rel.data);
4271 sfrost@snowman.net 4071 : 365 : systable_endscan(sscan);
2686 andres@anarazel.de 4072 : 365 : table_close(policy_rel, AccessShareLock);
4271 sfrost@snowman.net 4073 : 365 : break;
4074 : : }
4075 : :
75 peter@eisentraut.org 4076 :GNC 658 : case PropgraphElementRelationId:
4077 : : {
4078 : : HeapTuple tup;
4079 : : Form_pg_propgraph_element pgeform;
4080 : :
4081 : 658 : tup = SearchSysCache1(PROPGRAPHELOID, ObjectIdGetDatum(object->objectId));
4082 [ + + ]: 658 : if (!HeapTupleIsValid(tup))
4083 : : {
4084 [ - + ]: 4 : if (!missing_ok)
75 peter@eisentraut.org 4085 [ # # ]:UNC 0 : elog(ERROR, "cache lookup failed for property graph element %u",
4086 : : object->objectId);
75 peter@eisentraut.org 4087 :GNC 4 : break;
4088 : : }
4089 : :
4090 : 654 : pgeform = (Form_pg_propgraph_element) GETSTRUCT(tup);
4091 : :
4092 [ + + ]: 654 : if (pgeform->pgekind == PGEKIND_VERTEX)
4093 : : /* translator: followed by, e.g., "property graph %s" */
4094 : 365 : appendStringInfo(&buffer, _("vertex %s of "), NameStr(pgeform->pgealias));
4095 [ + - ]: 289 : else if (pgeform->pgekind == PGEKIND_EDGE)
4096 : : /* translator: followed by, e.g., "property graph %s" */
4097 : 289 : appendStringInfo(&buffer, _("edge %s of "), NameStr(pgeform->pgealias));
4098 : : else
75 peter@eisentraut.org 4099 :UNC 0 : appendStringInfo(&buffer, "??? element %s of ", NameStr(pgeform->pgealias));
75 peter@eisentraut.org 4100 :GNC 654 : getRelationDescription(&buffer, pgeform->pgepgid, false);
4101 : :
4102 : 654 : ReleaseSysCache(tup);
4103 : 654 : break;
4104 : : }
4105 : :
4106 : 515 : case PropgraphElementLabelRelationId:
4107 : : {
4108 : : Relation rel;
4109 : : HeapTuple tuple;
4110 : : Form_pg_propgraph_element_label pgelform;
4111 : : ObjectAddress oa;
4112 : :
4113 : 515 : rel = table_open(PropgraphElementLabelRelationId, AccessShareLock);
23 michael@paquier.xyz 4114 : 515 : tuple = get_catalog_object_by_oid(rel,
4115 : : Anum_pg_propgraph_element_label_oid,
4116 : 515 : object->objectId);
75 peter@eisentraut.org 4117 [ - + ]: 515 : if (!HeapTupleIsValid(tuple))
4118 : : {
75 peter@eisentraut.org 4119 [ # # ]:UNC 0 : if (!missing_ok)
4120 [ # # ]: 0 : elog(ERROR, "could not find tuple for element label %u", object->objectId);
4121 : :
4122 : 0 : table_close(rel, AccessShareLock);
4123 : 0 : break;
4124 : : }
4125 : :
75 peter@eisentraut.org 4126 :GNC 515 : pgelform = (Form_pg_propgraph_element_label) GETSTRUCT(tuple);
4127 : :
4128 : 515 : appendStringInfo(&buffer, _("label %s of "), get_propgraph_label_name(pgelform->pgellabelid));
4129 : 515 : ObjectAddressSet(oa, PropgraphElementRelationId, pgelform->pgelelid);
4130 : 515 : appendStringInfoString(&buffer, getObjectDescription(&oa, false));
4131 : :
4132 : 515 : table_close(rel, AccessShareLock);
4133 : 515 : break;
4134 : : }
4135 : :
4136 : 115 : case PropgraphLabelRelationId:
4137 : : {
4138 : : HeapTuple tuple;
4139 : : Form_pg_propgraph_label pglform;
4140 : :
40 4141 : 115 : tuple = SearchSysCache1(PROPGRAPHLABELOID, ObjectIdGetDatum(object->objectId));
75 4142 [ + + ]: 115 : if (!HeapTupleIsValid(tuple))
4143 : : {
4144 [ - + ]: 4 : if (!missing_ok)
75 peter@eisentraut.org 4145 [ # # ]:UNC 0 : elog(ERROR, "could not find tuple for label %u", object->objectId);
75 peter@eisentraut.org 4146 :GNC 4 : break;
4147 : : }
4148 : :
4149 : 111 : pglform = (Form_pg_propgraph_label) GETSTRUCT(tuple);
4150 : :
4151 : : /* translator: followed by, e.g., "property graph %s" */
4152 : 111 : appendStringInfo(&buffer, _("label %s of "), NameStr(pglform->pgllabel));
4153 : 111 : getRelationDescription(&buffer, pglform->pglpgid, false);
4154 : 111 : ReleaseSysCache(tuple);
4155 : 111 : break;
4156 : : }
4157 : :
4158 : 364 : case PropgraphLabelPropertyRelationId:
4159 : : {
4160 : : Relation rel;
4161 : : HeapTuple tuple;
4162 : : Form_pg_propgraph_label_property plpform;
4163 : : ObjectAddress oa;
4164 : :
4165 : 364 : rel = table_open(PropgraphLabelPropertyRelationId, AccessShareLock);
23 michael@paquier.xyz 4166 : 364 : tuple = get_catalog_object_by_oid(rel,
4167 : : Anum_pg_propgraph_label_property_oid,
4168 : 364 : object->objectId);
75 peter@eisentraut.org 4169 [ - + ]: 364 : if (!HeapTupleIsValid(tuple))
4170 : : {
75 peter@eisentraut.org 4171 [ # # ]:UNC 0 : if (!missing_ok)
4172 [ # # ]: 0 : elog(ERROR, "could not find tuple for label property %u", object->objectId);
4173 : :
4174 : 0 : table_close(rel, AccessShareLock);
4175 : 0 : break;
4176 : : }
4177 : :
75 peter@eisentraut.org 4178 :GNC 364 : plpform = (Form_pg_propgraph_label_property) GETSTRUCT(tuple);
4179 : :
4180 : 364 : appendStringInfo(&buffer, _("property %s of "), get_propgraph_property_name(plpform->plppropid));
4181 : 364 : ObjectAddressSet(oa, PropgraphElementLabelRelationId, plpform->plpellabelid);
4182 : 364 : appendStringInfoString(&buffer, getObjectDescription(&oa, false));
4183 : :
4184 : 364 : table_close(rel, AccessShareLock);
4185 : 364 : break;
4186 : : }
4187 : :
4188 : 182 : case PropgraphPropertyRelationId:
4189 : : {
4190 : : HeapTuple tuple;
4191 : : Form_pg_propgraph_property pgpform;
4192 : :
40 4193 : 182 : tuple = SearchSysCache1(PROPGRAPHPROPOID, ObjectIdGetDatum(object->objectId));
75 4194 [ + + ]: 182 : if (!HeapTupleIsValid(tuple))
4195 : : {
4196 [ - + ]: 4 : if (!missing_ok)
75 peter@eisentraut.org 4197 [ # # ]:UNC 0 : elog(ERROR, "could not find tuple for property %u", object->objectId);
75 peter@eisentraut.org 4198 :GNC 4 : break;
4199 : : }
4200 : :
4201 : 178 : pgpform = (Form_pg_propgraph_property) GETSTRUCT(tuple);
4202 : :
4203 : : /* translator: followed by, e.g., "property graph %s" */
4204 : 178 : appendStringInfo(&buffer, _("property %s of "), NameStr(pgpform->pgpname));
4205 : 178 : getRelationDescription(&buffer, pgpform->pgppgid, false);
4206 : 178 : ReleaseSysCache(tuple);
4207 : 178 : break;
4208 : : }
4209 : :
795 peter@eisentraut.org 4210 :CBC 4 : case PublicationRelationId:
4211 : : {
2145 michael@paquier.xyz 4212 : 4 : char *pubname = get_publication_name(object->objectId,
4213 : : missing_ok);
4214 : :
4215 [ - + ]: 4 : if (pubname)
2145 michael@paquier.xyz 4216 :UBC 0 : appendStringInfo(&buffer, _("publication %s"), pubname);
3418 peter_e@gmx.net 4217 :CBC 4 : break;
4218 : : }
4219 : :
795 peter@eisentraut.org 4220 : 102 : case PublicationNamespaceRelationId:
4221 : : {
4222 : : char *pubname;
4223 : : char *nspname;
4224 : :
1676 akapila@postgresql.o 4225 [ + + ]: 102 : if (!getPublicationSchemaInfo(object, missing_ok,
4226 : : &pubname, &nspname))
4227 : 4 : break;
4228 : :
1514 tomas.vondra@postgre 4229 : 98 : appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
4230 : : nspname, pubname);
1676 akapila@postgresql.o 4231 : 98 : pfree(pubname);
4232 : 98 : pfree(nspname);
4233 : 98 : break;
4234 : : }
4235 : :
795 peter@eisentraut.org 4236 : 318 : case PublicationRelRelationId:
4237 : : {
4238 : : HeapTuple tup;
4239 : : char *pubname;
4240 : : Form_pg_publication_rel prform;
4241 : : StringInfoData rel;
4242 : :
3418 peter_e@gmx.net 4243 : 318 : tup = SearchSysCache1(PUBLICATIONREL,
4244 : 318 : ObjectIdGetDatum(object->objectId));
4245 [ + + ]: 318 : if (!HeapTupleIsValid(tup))
4246 : : {
2145 michael@paquier.xyz 4247 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 4248 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for publication table %u",
4249 : : object->objectId);
2145 michael@paquier.xyz 4250 :CBC 4 : break;
4251 : : }
4252 : :
3418 peter_e@gmx.net 4253 : 314 : prform = (Form_pg_publication_rel) GETSTRUCT(tup);
2811 michael@paquier.xyz 4254 : 314 : pubname = get_publication_name(prform->prpubid, false);
4255 : :
2928 tgl@sss.pgh.pa.us 4256 : 314 : initStringInfo(&rel);
2145 michael@paquier.xyz 4257 : 314 : getRelationDescription(&rel, prform->prrelid, false);
4258 : :
4259 : : /* translator: first %s is, e.g., "table %s" */
2928 tgl@sss.pgh.pa.us 4260 : 314 : appendStringInfo(&buffer, _("publication of %s in publication %s"),
4261 : : rel.data, pubname);
4262 : 314 : pfree(rel.data);
3418 peter_e@gmx.net 4263 : 314 : ReleaseSysCache(tup);
4264 : 314 : break;
4265 : : }
4266 : :
795 peter@eisentraut.org 4267 : 4 : case SubscriptionRelationId:
4268 : : {
2145 michael@paquier.xyz 4269 : 4 : char *subname = get_subscription_name(object->objectId,
4270 : : missing_ok);
4271 : :
4272 [ - + ]: 4 : if (subname)
2145 michael@paquier.xyz 4273 :UBC 0 : appendStringInfo(&buffer, _("subscription %s"), subname);
3418 peter_e@gmx.net 4274 :CBC 4 : break;
4275 : : }
4276 : :
795 peter@eisentraut.org 4277 : 13 : case TransformRelationId:
4278 : : {
4279 : : HeapTuple trfTup;
4280 : : Form_pg_transform trfForm;
4281 : :
3303 tgl@sss.pgh.pa.us 4282 : 13 : trfTup = SearchSysCache1(TRFOID,
4283 : 13 : ObjectIdGetDatum(object->objectId));
4284 [ + + ]: 13 : if (!HeapTupleIsValid(trfTup))
4285 : : {
2145 michael@paquier.xyz 4286 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 4287 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for transform %u",
4288 : : object->objectId);
2145 michael@paquier.xyz 4289 :CBC 4 : break;
4290 : : }
4291 : :
3303 tgl@sss.pgh.pa.us 4292 : 9 : trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
4293 : :
4294 : 9 : appendStringInfo(&buffer, _("transform for %s language %s"),
4295 : : format_type_be(trfForm->trftype),
4296 : : get_language_name(trfForm->trflang, false));
4297 : :
4298 : 9 : ReleaseSysCache(trfTup);
4299 : 9 : break;
4300 : : }
4301 : :
795 peter@eisentraut.org 4302 :UBC 0 : default:
4303 [ # # ]: 0 : elog(ERROR, "unsupported object class: %u", object->classId);
4304 : : }
4305 : :
4306 : : /* an empty buffer is equivalent to no object found */
2145 michael@paquier.xyz 4307 [ + + ]:CBC 126844 : if (buffer.len == 0)
4308 : 180 : return NULL;
4309 : :
4819 alvherre@alvh.no-ip. 4310 : 126664 : return buffer.data;
4311 : : }
4312 : :
4313 : : /*
4314 : : * getObjectDescriptionOids: as above, except the object is specified by Oids
4315 : : */
4316 : : char *
4819 alvherre@alvh.no-ip. 4317 :UBC 0 : getObjectDescriptionOids(Oid classid, Oid objid)
4318 : : {
4319 : : ObjectAddress address;
4320 : :
4321 : 0 : address.classId = classid;
4322 : 0 : address.objectId = objid;
4323 : 0 : address.objectSubId = 0;
4324 : :
2145 michael@paquier.xyz 4325 : 0 : return getObjectDescription(&address, false);
4326 : : }
4327 : :
4328 : : /*
4329 : : * subroutine for getObjectDescription: describe a relation
4330 : : *
4331 : : * The result is appended to "buffer".
4332 : : */
4333 : : static void
2145 michael@paquier.xyz 4334 :CBC 64994 : getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
4335 : : {
4336 : : HeapTuple relTup;
4337 : : Form_pg_class relForm;
4338 : : char *nspname;
4339 : : char *relname;
4340 : :
4819 alvherre@alvh.no-ip. 4341 : 64994 : relTup = SearchSysCache1(RELOID,
4342 : : ObjectIdGetDatum(relid));
4343 [ + + ]: 64994 : if (!HeapTupleIsValid(relTup))
4344 : : {
2145 michael@paquier.xyz 4345 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 4346 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for relation %u", relid);
2145 michael@paquier.xyz 4347 :CBC 4 : return;
4348 : : }
4819 alvherre@alvh.no-ip. 4349 : 64990 : relForm = (Form_pg_class) GETSTRUCT(relTup);
4350 : :
4351 : : /* Qualify the name if not visible in search path */
4352 [ + + ]: 64990 : if (RelationIsVisible(relid))
4353 : 46586 : nspname = NULL;
4354 : : else
4355 : 18404 : nspname = get_namespace_name(relForm->relnamespace);
4356 : :
4357 : 64990 : relname = quote_qualified_identifier(nspname, NameStr(relForm->relname));
4358 : :
4359 [ + + + + : 64990 : switch (relForm->relkind)
+ + + +
- ][ + + +
+ + + + +
+ - ]
4360 : : {
4361 : 36626 : case RELKIND_RELATION:
4362 : : case RELKIND_PARTITIONED_TABLE:
4363 : 36626 : appendStringInfo(buffer, _("table %s"),
4364 : : relname);
4365 : 36626 : break;
4366 : 14980 : case RELKIND_INDEX:
4367 : : case RELKIND_PARTITIONED_INDEX:
4368 : 14980 : appendStringInfo(buffer, _("index %s"),
4369 : : relname);
4370 : 14980 : break;
4371 : 569 : case RELKIND_SEQUENCE:
4372 : 569 : appendStringInfo(buffer, _("sequence %s"),
4373 : : relname);
4374 : 569 : break;
4375 : 6393 : case RELKIND_TOASTVALUE:
4376 : 6393 : appendStringInfo(buffer, _("toast table %s"),
4377 : : relname);
4378 : 6393 : break;
4379 : 2477 : case RELKIND_VIEW:
4380 : 2477 : appendStringInfo(buffer, _("view %s"),
4381 : : relname);
4382 : 2477 : break;
4383 : 391 : case RELKIND_MATVIEW:
4384 : 391 : appendStringInfo(buffer, _("materialized view %s"),
4385 : : relname);
4386 : 391 : break;
4387 : 2237 : case RELKIND_COMPOSITE_TYPE:
4388 : 2237 : appendStringInfo(buffer, _("composite type %s"),
4389 : : relname);
4390 : 2237 : break;
4391 : 266 : case RELKIND_FOREIGN_TABLE:
4392 : 266 : appendStringInfo(buffer, _("foreign table %s"),
4393 : : relname);
4394 : 266 : break;
75 peter@eisentraut.org 4395 :GNC 1051 : case RELKIND_PROPGRAPH:
4396 : 1051 : appendStringInfo(buffer, _("property graph %s"),
4397 : : relname);
4398 : 1051 : break;
4819 alvherre@alvh.no-ip. 4399 :UBC 0 : default:
4400 : : /* shouldn't get here */
4401 : 0 : appendStringInfo(buffer, _("relation %s"),
4402 : : relname);
4403 : 0 : break;
4404 : : }
4405 : :
4819 alvherre@alvh.no-ip. 4406 :CBC 64990 : ReleaseSysCache(relTup);
4407 : : }
4408 : :
4409 : : /*
4410 : : * subroutine for getObjectDescription: describe an operator family
4411 : : */
4412 : : static void
2145 michael@paquier.xyz 4413 : 2143 : getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
4414 : : {
4415 : : HeapTuple opfTup;
4416 : : Form_pg_opfamily opfForm;
4417 : : HeapTuple amTup;
4418 : : Form_pg_am amForm;
4419 : : char *nspname;
4420 : :
4819 alvherre@alvh.no-ip. 4421 : 2143 : opfTup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfid));
4422 [ + + ]: 2143 : if (!HeapTupleIsValid(opfTup))
4423 : : {
2145 michael@paquier.xyz 4424 [ - + ]: 4 : if (!missing_ok)
2145 michael@paquier.xyz 4425 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for opfamily %u", opfid);
2145 michael@paquier.xyz 4426 :CBC 4 : return;
4427 : : }
4819 alvherre@alvh.no-ip. 4428 : 2139 : opfForm = (Form_pg_opfamily) GETSTRUCT(opfTup);
4429 : :
4430 : 2139 : amTup = SearchSysCache1(AMOID, ObjectIdGetDatum(opfForm->opfmethod));
4431 [ - + ]: 2139 : if (!HeapTupleIsValid(amTup))
4819 alvherre@alvh.no-ip. 4432 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for access method %u",
4433 : : opfForm->opfmethod);
4819 alvherre@alvh.no-ip. 4434 :CBC 2139 : amForm = (Form_pg_am) GETSTRUCT(amTup);
4435 : :
4436 : : /* Qualify the name if not visible in search path */
4437 [ + + ]: 2139 : if (OpfamilyIsVisible(opfid))
4438 : 2038 : nspname = NULL;
4439 : : else
4440 : 101 : nspname = get_namespace_name(opfForm->opfnamespace);
4441 : :
4442 : 2139 : appendStringInfo(buffer, _("operator family %s for access method %s"),
4443 : : quote_qualified_identifier(nspname,
4444 : 2139 : NameStr(opfForm->opfname)),
4445 : 2139 : NameStr(amForm->amname));
4446 : :
4447 : 2139 : ReleaseSysCache(amTup);
4448 : 2139 : ReleaseSysCache(opfTup);
4449 : : }
4450 : :
4451 : : /*
4452 : : * SQL-level callable version of getObjectDescription
4453 : : */
4454 : : Datum
4455 : 1463 : pg_describe_object(PG_FUNCTION_ARGS)
4456 : : {
4457 : 1463 : Oid classid = PG_GETARG_OID(0);
4458 : 1463 : Oid objid = PG_GETARG_OID(1);
3377 peter_e@gmx.net 4459 : 1463 : int32 objsubid = PG_GETARG_INT32(2);
4460 : : char *description;
4461 : : ObjectAddress address;
4462 : :
4463 : : /* for "pinned" items in pg_depend, return null */
4819 alvherre@alvh.no-ip. 4464 [ - + - - ]: 1463 : if (!OidIsValid(classid) && !OidIsValid(objid))
4819 alvherre@alvh.no-ip. 4465 :UBC 0 : PG_RETURN_NULL();
4466 : :
4819 alvherre@alvh.no-ip. 4467 :CBC 1463 : address.classId = classid;
4468 : 1463 : address.objectId = objid;
3377 peter_e@gmx.net 4469 : 1463 : address.objectSubId = objsubid;
4470 : :
2145 michael@paquier.xyz 4471 : 1463 : description = getObjectDescription(&address, true);
4472 : :
4473 [ + + ]: 1463 : if (description == NULL)
4474 : 180 : PG_RETURN_NULL();
4475 : :
4819 alvherre@alvh.no-ip. 4476 : 1283 : PG_RETURN_TEXT_P(cstring_to_text(description));
4477 : : }
4478 : :
4479 : : /*
4480 : : * SQL-level callable function to obtain object type + identity
4481 : : */
4482 : : Datum
4483 : 1742 : pg_identify_object(PG_FUNCTION_ARGS)
4484 : : {
4485 : 1742 : Oid classid = PG_GETARG_OID(0);
4486 : 1742 : Oid objid = PG_GETARG_OID(1);
3377 peter_e@gmx.net 4487 : 1742 : int32 objsubid = PG_GETARG_INT32(2);
4819 alvherre@alvh.no-ip. 4488 : 1742 : Oid schema_oid = InvalidOid;
4489 : 1742 : const char *objname = NULL;
4490 : : char *objidentity;
4491 : : ObjectAddress address;
4492 : : Datum values[4];
4493 : : bool nulls[4];
4494 : : TupleDesc tupdesc;
4495 : : HeapTuple htup;
4496 : :
4497 : 1742 : address.classId = classid;
4498 : 1742 : address.objectId = objid;
3377 peter_e@gmx.net 4499 : 1742 : address.objectSubId = objsubid;
4500 : :
1256 michael@paquier.xyz 4501 [ - + ]: 1742 : if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1256 michael@paquier.xyz 4502 [ # # ]:UBC 0 : elog(ERROR, "return type must be a row type");
4503 : :
4819 alvherre@alvh.no-ip. 4504 [ + + ]:CBC 1742 : if (is_objectclass_supported(address.classId))
4505 : : {
4506 : : HeapTuple objtup;
2686 andres@anarazel.de 4507 : 1649 : Relation catalog = table_open(address.classId, AccessShareLock);
4508 : :
2748 4509 : 1649 : objtup = get_catalog_object_by_oid(catalog,
4510 : 1649 : get_object_attnum_oid(address.classId),
4511 : : address.objectId);
4819 alvherre@alvh.no-ip. 4512 [ + + ]: 1649 : if (objtup != NULL)
4513 : : {
4514 : : bool isnull;
4515 : : AttrNumber nspAttnum;
4516 : : AttrNumber nameAttnum;
4517 : :
4518 : 1493 : nspAttnum = get_object_attnum_namespace(address.classId);
4519 [ + + ]: 1493 : if (nspAttnum != InvalidAttrNumber)
4520 : : {
295 peter@eisentraut.org 4521 :GNC 728 : schema_oid = DatumGetObjectId(heap_getattr(objtup, nspAttnum,
4522 : : RelationGetDescr(catalog), &isnull));
4819 alvherre@alvh.no-ip. 4523 [ - + ]:CBC 728 : if (isnull)
4819 alvherre@alvh.no-ip. 4524 [ # # ]:UBC 0 : elog(ERROR, "invalid null namespace in object %u/%u/%d",
4525 : : address.classId, address.objectId, address.objectSubId);
4526 : : }
4527 : :
4528 : : /*
4529 : : * We only return the object name if it can be used (together with
4530 : : * the schema name, if any) as a unique identifier.
4531 : : */
4819 alvherre@alvh.no-ip. 4532 [ + + ]:CBC 1493 : if (get_object_namensp_unique(address.classId))
4533 : : {
4534 : 786 : nameAttnum = get_object_attnum_name(address.classId);
4535 [ + - ]: 786 : if (nameAttnum != InvalidAttrNumber)
4536 : : {
4537 : : Datum nameDatum;
4538 : :
4539 : 786 : nameDatum = heap_getattr(objtup, nameAttnum,
4540 : : RelationGetDescr(catalog), &isnull);
4541 [ - + ]: 786 : if (isnull)
4819 alvherre@alvh.no-ip. 4542 [ # # ]:UBC 0 : elog(ERROR, "invalid null name in object %u/%u/%d",
4543 : : address.classId, address.objectId, address.objectSubId);
4819 alvherre@alvh.no-ip. 4544 :CBC 786 : objname = quote_identifier(NameStr(*(DatumGetName(nameDatum))));
4545 : : }
4546 : : }
4547 : : }
4548 : :
2686 andres@anarazel.de 4549 : 1649 : table_close(catalog, AccessShareLock);
4550 : : }
4551 : :
4552 : : /* object type, which can never be NULL */
2145 michael@paquier.xyz 4553 : 1742 : values[0] = CStringGetTextDatum(getObjectTypeDescription(&address, true));
4819 alvherre@alvh.no-ip. 4554 : 1742 : nulls[0] = false;
4555 : :
4556 : : /*
4557 : : * Before doing anything, extract the object identity. If the identity
4558 : : * could not be found, set all the fields except the object type to NULL.
4559 : : */
2145 michael@paquier.xyz 4560 : 1742 : objidentity = getObjectIdentity(&address, true);
4561 : :
4562 : : /* schema name */
4563 [ + + + + ]: 1742 : if (OidIsValid(schema_oid) && objidentity)
4819 alvherre@alvh.no-ip. 4564 : 724 : {
4749 bruce@momjian.us 4565 : 724 : const char *schema = quote_identifier(get_namespace_name(schema_oid));
4566 : :
4819 alvherre@alvh.no-ip. 4567 : 724 : values[1] = CStringGetTextDatum(schema);
4568 : 724 : nulls[1] = false;
4569 : : }
4570 : : else
4571 : 1018 : nulls[1] = true;
4572 : :
4573 : : /* object name */
2145 michael@paquier.xyz 4574 [ + + + + ]: 1742 : if (objname && objidentity)
4575 : : {
4819 alvherre@alvh.no-ip. 4576 : 782 : values[2] = CStringGetTextDatum(objname);
4577 : 782 : nulls[2] = false;
4578 : : }
4579 : : else
4580 : 960 : nulls[2] = true;
4581 : :
4582 : : /* object identity */
2145 michael@paquier.xyz 4583 [ + + ]: 1742 : if (objidentity)
4584 : : {
4585 : 1562 : values[3] = CStringGetTextDatum(objidentity);
4586 : 1562 : nulls[3] = false;
4587 : : }
4588 : : else
4589 : 180 : nulls[3] = true;
4590 : :
4819 alvherre@alvh.no-ip. 4591 : 1742 : htup = heap_form_tuple(tupdesc, values, nulls);
4592 : :
4593 : 1742 : PG_RETURN_DATUM(HeapTupleGetDatum(htup));
4594 : : }
4595 : :
4596 : : /*
4597 : : * SQL-level callable function to obtain object type + identity
4598 : : */
4599 : : Datum
4169 4600 : 637 : pg_identify_object_as_address(PG_FUNCTION_ARGS)
4601 : : {
4602 : 637 : Oid classid = PG_GETARG_OID(0);
4603 : 637 : Oid objid = PG_GETARG_OID(1);
3377 peter_e@gmx.net 4604 : 637 : int32 objsubid = PG_GETARG_INT32(2);
4605 : : ObjectAddress address;
4606 : : char *identity;
4607 : : List *names;
4608 : : List *args;
4609 : : Datum values[3];
4610 : : bool nulls[3];
4611 : : TupleDesc tupdesc;
4612 : : HeapTuple htup;
4613 : :
4169 alvherre@alvh.no-ip. 4614 : 637 : address.classId = classid;
4615 : 637 : address.objectId = objid;
3377 peter_e@gmx.net 4616 : 637 : address.objectSubId = objsubid;
4617 : :
1256 michael@paquier.xyz 4618 [ - + ]: 637 : if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1256 michael@paquier.xyz 4619 [ # # ]:UBC 0 : elog(ERROR, "return type must be a row type");
4620 : :
4621 : : /* object type, which can never be NULL */
2145 michael@paquier.xyz 4622 :CBC 637 : values[0] = CStringGetTextDatum(getObjectTypeDescription(&address, true));
4169 alvherre@alvh.no-ip. 4623 : 637 : nulls[0] = false;
4624 : :
4625 : : /* object identity */
2145 michael@paquier.xyz 4626 : 637 : identity = getObjectIdentityParts(&address, &names, &args, true);
4627 [ + + ]: 637 : if (identity == NULL)
4628 : : {
4629 : 180 : nulls[1] = true;
4630 : 180 : nulls[2] = true;
4631 : : }
4632 : : else
4633 : : {
4634 : 457 : pfree(identity);
4635 : :
4636 : : /* object_names */
4637 [ + - ]: 457 : if (names != NIL)
4638 : 457 : values[1] = PointerGetDatum(strlist_to_textarray(names));
4639 : : else
2145 michael@paquier.xyz 4640 :UBC 0 : values[1] = PointerGetDatum(construct_empty_array(TEXTOID));
2145 michael@paquier.xyz 4641 :CBC 457 : nulls[1] = false;
4642 : :
4643 : : /* object_args */
4644 [ + + ]: 457 : if (args)
4645 : 56 : values[2] = PointerGetDatum(strlist_to_textarray(args));
4646 : : else
4647 : 401 : values[2] = PointerGetDatum(construct_empty_array(TEXTOID));
4648 : 457 : nulls[2] = false;
4649 : : }
4650 : :
4169 alvherre@alvh.no-ip. 4651 : 637 : htup = heap_form_tuple(tupdesc, values, nulls);
4652 : :
4653 : 637 : PG_RETURN_DATUM(HeapTupleGetDatum(htup));
4654 : : }
4655 : :
4656 : : /*
4657 : : * SQL-level callable function to obtain the ACL of a specified object, given
4658 : : * its catalog OID, object OID and sub-object ID.
4659 : : */
4660 : : Datum
695 michael@paquier.xyz 4661 : 57 : pg_get_acl(PG_FUNCTION_ARGS)
4662 : : {
4663 : 57 : Oid classId = PG_GETARG_OID(0);
4664 : 57 : Oid objectId = PG_GETARG_OID(1);
689 4665 : 57 : int32 objsubid = PG_GETARG_INT32(2);
4666 : : Oid catalogId;
4667 : : AttrNumber Anum_acl;
4668 : : Datum datum;
4669 : : bool isnull;
4670 : : HeapTuple tup;
4671 : :
4672 : : /* for "pinned" items in pg_depend, return null */
695 4673 [ + + + - ]: 57 : if (!OidIsValid(classId) && !OidIsValid(objectId))
4674 : 4 : PG_RETURN_NULL();
4675 : :
4676 : : /* for large objects, the catalog to look at is pg_largeobject_metadata */
4677 : 53 : catalogId = (classId == LargeObjectRelationId) ?
4678 [ + - ]: 53 : LargeObjectMetadataRelationId : classId;
4679 : 53 : Anum_acl = get_object_attnum_acl(catalogId);
4680 : :
4681 : : /* return NULL if no ACL field for this catalog */
4682 [ - + ]: 53 : if (Anum_acl == InvalidAttrNumber)
695 michael@paquier.xyz 4683 :UBC 0 : PG_RETURN_NULL();
4684 : :
4685 : : /*
4686 : : * If dealing with a relation's attribute (objsubid is set), the ACL is
4687 : : * retrieved from pg_attribute.
4688 : : */
689 michael@paquier.xyz 4689 [ + - + + ]:CBC 53 : if (classId == RelationRelationId && objsubid != 0)
4690 : 36 : {
4691 : 36 : AttrNumber attnum = (AttrNumber) objsubid;
4692 : :
4693 : 36 : tup = SearchSysCacheCopyAttNum(objectId, attnum);
4694 : :
4695 [ - + ]: 36 : if (!HeapTupleIsValid(tup))
689 michael@paquier.xyz 4696 :UBC 0 : PG_RETURN_NULL();
4697 : :
689 michael@paquier.xyz 4698 :CBC 36 : datum = SysCacheGetAttr(ATTNUM, tup, Anum_pg_attribute_attacl,
4699 : : &isnull);
4700 : : }
4701 : : else
4702 : : {
4703 : : Relation rel;
4704 : :
4705 : 17 : rel = table_open(catalogId, AccessShareLock);
4706 : :
4707 : 17 : tup = get_catalog_object_by_oid(rel, get_object_attnum_oid(catalogId),
4708 : : objectId);
4709 [ + + ]: 17 : if (!HeapTupleIsValid(tup))
4710 : : {
4711 : 4 : table_close(rel, AccessShareLock);
4712 : 4 : PG_RETURN_NULL();
4713 : : }
4714 : :
4715 : 13 : datum = heap_getattr(tup, Anum_acl, RelationGetDescr(rel), &isnull);
695 4716 : 13 : table_close(rel, AccessShareLock);
4717 : : }
4718 : :
4719 [ + + ]: 49 : if (isnull)
4720 : 13 : PG_RETURN_NULL();
4721 : :
4722 : 36 : PG_RETURN_DATUM(datum);
4723 : : }
4724 : :
4725 : : /*
4726 : : * Return a palloc'ed string that describes the type of object that the
4727 : : * passed address is for.
4728 : : *
4729 : : * Keep ObjectTypeMap in sync with this.
4730 : : */
4731 : : char *
2145 4732 : 5480 : getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
4733 : : {
4734 : : StringInfoData buffer;
4735 : :
4819 alvherre@alvh.no-ip. 4736 : 5480 : initStringInfo(&buffer);
4737 : :
795 peter@eisentraut.org 4738 : 5480 : switch (object->classId)
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - ]
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
- ]
4739 : : {
4740 : 1475 : case RelationRelationId:
4819 alvherre@alvh.no-ip. 4741 : 1475 : getRelationTypeDescription(&buffer, object->objectId,
2145 michael@paquier.xyz 4742 : 1475 : object->objectSubId,
4743 : : missing_ok);
4819 alvherre@alvh.no-ip. 4744 : 1475 : break;
4745 : :
795 peter@eisentraut.org 4746 : 208 : case ProcedureRelationId:
2145 michael@paquier.xyz 4747 : 208 : getProcedureTypeDescription(&buffer, object->objectId,
4748 : : missing_ok);
4819 alvherre@alvh.no-ip. 4749 : 208 : break;
4750 : :
795 peter@eisentraut.org 4751 : 1028 : case TypeRelationId:
4594 rhaas@postgresql.org 4752 : 1028 : appendStringInfoString(&buffer, "type");
4819 alvherre@alvh.no-ip. 4753 : 1028 : break;
4754 : :
795 peter@eisentraut.org 4755 : 41 : case CastRelationId:
4594 rhaas@postgresql.org 4756 : 41 : appendStringInfoString(&buffer, "cast");
4819 alvherre@alvh.no-ip. 4757 : 41 : break;
4758 : :
795 peter@eisentraut.org 4759 : 38 : case CollationRelationId:
4594 rhaas@postgresql.org 4760 : 38 : appendStringInfoString(&buffer, "collation");
4819 alvherre@alvh.no-ip. 4761 : 38 : break;
4762 : :
795 peter@eisentraut.org 4763 : 438 : case ConstraintRelationId:
2145 michael@paquier.xyz 4764 : 438 : getConstraintTypeDescription(&buffer, object->objectId,
4765 : : missing_ok);
4819 alvherre@alvh.no-ip. 4766 : 438 : break;
4767 : :
795 peter@eisentraut.org 4768 : 37 : case ConversionRelationId:
4594 rhaas@postgresql.org 4769 : 37 : appendStringInfoString(&buffer, "conversion");
4819 alvherre@alvh.no-ip. 4770 : 37 : break;
4771 : :
795 peter@eisentraut.org 4772 : 338 : case AttrDefaultRelationId:
4594 rhaas@postgresql.org 4773 : 338 : appendStringInfoString(&buffer, "default value");
4819 alvherre@alvh.no-ip. 4774 : 338 : break;
4775 : :
795 peter@eisentraut.org 4776 : 36 : case LanguageRelationId:
4594 rhaas@postgresql.org 4777 : 36 : appendStringInfoString(&buffer, "language");
4819 alvherre@alvh.no-ip. 4778 : 36 : break;
4779 : :
795 peter@eisentraut.org 4780 : 8 : case LargeObjectRelationId:
4594 rhaas@postgresql.org 4781 : 8 : appendStringInfoString(&buffer, "large object");
4819 alvherre@alvh.no-ip. 4782 : 8 : break;
4783 : :
795 peter@eisentraut.org 4784 : 38 : case OperatorRelationId:
4594 rhaas@postgresql.org 4785 : 38 : appendStringInfoString(&buffer, "operator");
4819 alvherre@alvh.no-ip. 4786 : 38 : break;
4787 : :
795 peter@eisentraut.org 4788 : 41 : case OperatorClassRelationId:
4594 rhaas@postgresql.org 4789 : 41 : appendStringInfoString(&buffer, "operator class");
4819 alvherre@alvh.no-ip. 4790 : 41 : break;
4791 : :
795 peter@eisentraut.org 4792 : 42 : case OperatorFamilyRelationId:
4594 rhaas@postgresql.org 4793 : 42 : appendStringInfoString(&buffer, "operator family");
4819 alvherre@alvh.no-ip. 4794 : 42 : break;
4795 : :
795 peter@eisentraut.org 4796 : 36 : case AccessMethodRelationId:
3303 tgl@sss.pgh.pa.us 4797 : 36 : appendStringInfoString(&buffer, "access method");
4798 : 36 : break;
4799 : :
795 peter@eisentraut.org 4800 : 36 : case AccessMethodOperatorRelationId:
4594 rhaas@postgresql.org 4801 : 36 : appendStringInfoString(&buffer, "operator of access method");
4819 alvherre@alvh.no-ip. 4802 : 36 : break;
4803 : :
795 peter@eisentraut.org 4804 : 36 : case AccessMethodProcedureRelationId:
4594 rhaas@postgresql.org 4805 : 36 : appendStringInfoString(&buffer, "function of access method");
4819 alvherre@alvh.no-ip. 4806 : 36 : break;
4807 : :
795 peter@eisentraut.org 4808 : 59 : case RewriteRelationId:
4594 rhaas@postgresql.org 4809 : 59 : appendStringInfoString(&buffer, "rule");
4819 alvherre@alvh.no-ip. 4810 : 59 : break;
4811 : :
795 peter@eisentraut.org 4812 : 127 : case TriggerRelationId:
4594 rhaas@postgresql.org 4813 : 127 : appendStringInfoString(&buffer, "trigger");
4819 alvherre@alvh.no-ip. 4814 : 127 : break;
4815 : :
795 peter@eisentraut.org 4816 : 91 : case NamespaceRelationId:
4594 rhaas@postgresql.org 4817 : 91 : appendStringInfoString(&buffer, "schema");
4819 alvherre@alvh.no-ip. 4818 : 91 : break;
4819 : :
795 peter@eisentraut.org 4820 : 37 : case StatisticExtRelationId:
3303 tgl@sss.pgh.pa.us 4821 : 37 : appendStringInfoString(&buffer, "statistics object");
4822 : 37 : break;
4823 : :
795 peter@eisentraut.org 4824 : 38 : case TSParserRelationId:
4594 rhaas@postgresql.org 4825 : 38 : appendStringInfoString(&buffer, "text search parser");
4819 alvherre@alvh.no-ip. 4826 : 38 : break;
4827 : :
795 peter@eisentraut.org 4828 : 36 : case TSDictionaryRelationId:
4594 rhaas@postgresql.org 4829 : 36 : appendStringInfoString(&buffer, "text search dictionary");
4819 alvherre@alvh.no-ip. 4830 : 36 : break;
4831 : :
795 peter@eisentraut.org 4832 : 36 : case TSTemplateRelationId:
4594 rhaas@postgresql.org 4833 : 36 : appendStringInfoString(&buffer, "text search template");
4819 alvherre@alvh.no-ip. 4834 : 36 : break;
4835 : :
795 peter@eisentraut.org 4836 : 40 : case TSConfigRelationId:
4594 rhaas@postgresql.org 4837 : 40 : appendStringInfoString(&buffer, "text search configuration");
4819 alvherre@alvh.no-ip. 4838 : 40 : break;
4839 : :
795 peter@eisentraut.org 4840 : 36 : case AuthIdRelationId:
4594 rhaas@postgresql.org 4841 : 36 : appendStringInfoString(&buffer, "role");
4819 alvherre@alvh.no-ip. 4842 : 36 : break;
4843 : :
795 peter@eisentraut.org 4844 : 8 : case AuthMemRelationId:
1381 rhaas@postgresql.org 4845 : 8 : appendStringInfoString(&buffer, "role membership");
4846 : 8 : break;
4847 : :
795 peter@eisentraut.org 4848 : 8 : case DatabaseRelationId:
4594 rhaas@postgresql.org 4849 : 8 : appendStringInfoString(&buffer, "database");
4819 alvherre@alvh.no-ip. 4850 : 8 : break;
4851 : :
795 peter@eisentraut.org 4852 : 8 : case TableSpaceRelationId:
4594 rhaas@postgresql.org 4853 : 8 : appendStringInfoString(&buffer, "tablespace");
4819 alvherre@alvh.no-ip. 4854 : 8 : break;
4855 : :
795 peter@eisentraut.org 4856 : 40 : case ForeignDataWrapperRelationId:
4594 rhaas@postgresql.org 4857 : 40 : appendStringInfoString(&buffer, "foreign-data wrapper");
4819 alvherre@alvh.no-ip. 4858 : 40 : break;
4859 : :
795 peter@eisentraut.org 4860 : 40 : case ForeignServerRelationId:
4594 rhaas@postgresql.org 4861 : 40 : appendStringInfoString(&buffer, "server");
4819 alvherre@alvh.no-ip. 4862 : 40 : break;
4863 : :
795 peter@eisentraut.org 4864 : 40 : case UserMappingRelationId:
4594 rhaas@postgresql.org 4865 : 40 : appendStringInfoString(&buffer, "user mapping");
4819 alvherre@alvh.no-ip. 4866 : 40 : break;
4867 : :
795 peter@eisentraut.org 4868 : 68 : case DefaultAclRelationId:
4594 rhaas@postgresql.org 4869 : 68 : appendStringInfoString(&buffer, "default acl");
4819 alvherre@alvh.no-ip. 4870 : 68 : break;
4871 : :
795 peter@eisentraut.org 4872 : 20 : case ExtensionRelationId:
4594 rhaas@postgresql.org 4873 : 20 : appendStringInfoString(&buffer, "extension");
4819 alvherre@alvh.no-ip. 4874 : 20 : break;
4875 : :
795 peter@eisentraut.org 4876 : 32 : case EventTriggerRelationId:
4594 rhaas@postgresql.org 4877 : 32 : appendStringInfoString(&buffer, "event trigger");
4819 alvherre@alvh.no-ip. 4878 : 32 : break;
4879 : :
795 peter@eisentraut.org 4880 : 10 : case ParameterAclRelationId:
1515 tgl@sss.pgh.pa.us 4881 : 10 : appendStringInfoString(&buffer, "parameter ACL");
4882 : 10 : break;
4883 : :
795 peter@eisentraut.org 4884 : 64 : case PolicyRelationId:
4202 sfrost@snowman.net 4885 : 64 : appendStringInfoString(&buffer, "policy");
4886 : 64 : break;
4887 : :
75 peter@eisentraut.org 4888 :GNC 148 : case PropgraphElementRelationId:
4889 : 148 : appendStringInfoString(&buffer, "property graph element");
4890 : 148 : break;
4891 : :
4892 : 176 : case PropgraphLabelRelationId:
4893 : 176 : appendStringInfoString(&buffer, "property graph label");
4894 : 176 : break;
4895 : :
4896 : 260 : case PropgraphPropertyRelationId:
4897 : 260 : appendStringInfoString(&buffer, "property graph property");
4898 : 260 : break;
4899 : :
795 peter@eisentraut.org 4900 :CBC 36 : case PublicationRelationId:
3418 peter_e@gmx.net 4901 : 36 : appendStringInfoString(&buffer, "publication");
4902 : 36 : break;
4903 : :
795 peter@eisentraut.org 4904 : 36 : case PublicationNamespaceRelationId:
1676 akapila@postgresql.o 4905 : 36 : appendStringInfoString(&buffer, "publication namespace");
4906 : 36 : break;
4907 : :
795 peter@eisentraut.org 4908 : 36 : case PublicationRelRelationId:
3411 peter_e@gmx.net 4909 : 36 : appendStringInfoString(&buffer, "publication relation");
3418 4910 : 36 : break;
4911 : :
795 peter@eisentraut.org 4912 : 36 : case SubscriptionRelationId:
3418 peter_e@gmx.net 4913 : 36 : appendStringInfoString(&buffer, "subscription");
4914 : 36 : break;
4915 : :
795 peter@eisentraut.org 4916 : 38 : case TransformRelationId:
3303 tgl@sss.pgh.pa.us 4917 : 38 : appendStringInfoString(&buffer, "transform");
3354 alvherre@alvh.no-ip. 4918 : 38 : break;
4919 : :
795 peter@eisentraut.org 4920 :UBC 0 : default:
4921 [ # # ]: 0 : elog(ERROR, "unsupported object class: %u", object->classId);
4922 : : }
4923 : :
4924 : : /* the result can never be empty */
1813 michael@paquier.xyz 4925 [ - + ]:CBC 5480 : Assert(buffer.len > 0);
4926 : :
4819 alvherre@alvh.no-ip. 4927 : 5480 : return buffer.data;
4928 : : }
4929 : :
4930 : : /*
4931 : : * subroutine for getObjectTypeDescription: describe a relation type
4932 : : */
4933 : : static void
2145 michael@paquier.xyz 4934 : 1475 : getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId,
4935 : : bool missing_ok)
4936 : : {
4937 : : HeapTuple relTup;
4938 : : Form_pg_class relForm;
4939 : :
4819 alvherre@alvh.no-ip. 4940 : 1475 : relTup = SearchSysCache1(RELOID,
4941 : : ObjectIdGetDatum(relid));
4942 [ + + ]: 1475 : if (!HeapTupleIsValid(relTup))
4943 : : {
2145 michael@paquier.xyz 4944 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 4945 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for relation %u", relid);
4946 : :
4947 : : /* fallback to "relation" for an undefined object */
2145 michael@paquier.xyz 4948 :CBC 8 : appendStringInfoString(buffer, "relation");
4949 : 8 : return;
4950 : : }
4819 alvherre@alvh.no-ip. 4951 : 1467 : relForm = (Form_pg_class) GETSTRUCT(relTup);
4952 : :
4953 [ + + + + : 1467 : switch (relForm->relkind)
+ + + +
- ][ + + +
+ + + + +
+ - ]
4954 : : {
4955 : 622 : case RELKIND_RELATION:
4956 : : case RELKIND_PARTITIONED_TABLE:
4594 rhaas@postgresql.org 4957 : 622 : appendStringInfoString(buffer, "table");
4819 alvherre@alvh.no-ip. 4958 : 622 : break;
4959 : 457 : case RELKIND_INDEX:
4960 : : case RELKIND_PARTITIONED_INDEX:
4594 rhaas@postgresql.org 4961 : 457 : appendStringInfoString(buffer, "index");
4819 alvherre@alvh.no-ip. 4962 : 457 : break;
4963 : 120 : case RELKIND_SEQUENCE:
4594 rhaas@postgresql.org 4964 : 120 : appendStringInfoString(buffer, "sequence");
4819 alvherre@alvh.no-ip. 4965 : 120 : break;
4966 : 72 : case RELKIND_TOASTVALUE:
4594 rhaas@postgresql.org 4967 : 72 : appendStringInfoString(buffer, "toast table");
4819 alvherre@alvh.no-ip. 4968 : 72 : break;
4969 : 68 : case RELKIND_VIEW:
4594 rhaas@postgresql.org 4970 : 68 : appendStringInfoString(buffer, "view");
4819 alvherre@alvh.no-ip. 4971 : 68 : break;
4972 : 38 : case RELKIND_MATVIEW:
4594 rhaas@postgresql.org 4973 : 38 : appendStringInfoString(buffer, "materialized view");
4819 alvherre@alvh.no-ip. 4974 : 38 : break;
4975 : 2 : case RELKIND_COMPOSITE_TYPE:
4594 rhaas@postgresql.org 4976 : 2 : appendStringInfoString(buffer, "composite type");
4819 alvherre@alvh.no-ip. 4977 : 2 : break;
4978 : 60 : case RELKIND_FOREIGN_TABLE:
4594 rhaas@postgresql.org 4979 : 60 : appendStringInfoString(buffer, "foreign table");
4819 alvherre@alvh.no-ip. 4980 : 60 : break;
75 peter@eisentraut.org 4981 :GNC 28 : case RELKIND_PROPGRAPH:
4982 : 28 : appendStringInfoString(buffer, "property graph");
4983 : 28 : break;
4819 alvherre@alvh.no-ip. 4984 :UBC 0 : default:
4985 : : /* shouldn't get here */
4594 rhaas@postgresql.org 4986 : 0 : appendStringInfoString(buffer, "relation");
4819 alvherre@alvh.no-ip. 4987 : 0 : break;
4988 : : }
4989 : :
4819 alvherre@alvh.no-ip. 4990 [ + + ]:CBC 1467 : if (objectSubId != 0)
4594 rhaas@postgresql.org 4991 : 85 : appendStringInfoString(buffer, " column");
4992 : :
4819 alvherre@alvh.no-ip. 4993 : 1467 : ReleaseSysCache(relTup);
4994 : : }
4995 : :
4996 : : /*
4997 : : * subroutine for getObjectTypeDescription: describe a constraint type
4998 : : */
4999 : : static void
2145 michael@paquier.xyz 5000 : 438 : getConstraintTypeDescription(StringInfo buffer, Oid constroid, bool missing_ok)
5001 : : {
5002 : : Relation constrRel;
5003 : : HeapTuple constrTup;
5004 : : Form_pg_constraint constrForm;
5005 : :
2686 andres@anarazel.de 5006 : 438 : constrRel = table_open(ConstraintRelationId, AccessShareLock);
2748 5007 : 438 : constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
5008 : : constroid);
4819 alvherre@alvh.no-ip. 5009 [ + + ]: 438 : if (!HeapTupleIsValid(constrTup))
5010 : : {
2145 michael@paquier.xyz 5011 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5012 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for constraint %u", constroid);
5013 : :
2145 michael@paquier.xyz 5014 :CBC 8 : table_close(constrRel, AccessShareLock);
5015 : :
5016 : : /* fallback to "constraint" for an undefined object */
5017 : 8 : appendStringInfoString(buffer, "constraint");
5018 : 8 : return;
5019 : : }
5020 : :
4819 alvherre@alvh.no-ip. 5021 : 430 : constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
5022 : :
5023 [ + + ]: 430 : if (OidIsValid(constrForm->conrelid))
5024 : 378 : appendStringInfoString(buffer, "table constraint");
5025 [ + - ]: 52 : else if (OidIsValid(constrForm->contypid))
5026 : 52 : appendStringInfoString(buffer, "domain constraint");
5027 : : else
2748 andres@anarazel.de 5028 [ # # ]:UBC 0 : elog(ERROR, "invalid constraint %u", constrForm->oid);
5029 : :
2686 andres@anarazel.de 5030 :CBC 430 : table_close(constrRel, AccessShareLock);
5031 : : }
5032 : :
5033 : : /*
5034 : : * subroutine for getObjectTypeDescription: describe a procedure type
5035 : : */
5036 : : static void
2145 michael@paquier.xyz 5037 : 208 : getProcedureTypeDescription(StringInfo buffer, Oid procid,
5038 : : bool missing_ok)
5039 : : {
5040 : : HeapTuple procTup;
5041 : : Form_pg_proc procForm;
5042 : :
4819 alvherre@alvh.no-ip. 5043 : 208 : procTup = SearchSysCache1(PROCOID,
5044 : : ObjectIdGetDatum(procid));
5045 [ + + ]: 208 : if (!HeapTupleIsValid(procTup))
5046 : : {
2145 michael@paquier.xyz 5047 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5048 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for procedure %u", procid);
5049 : :
5050 : : /* fallback to "procedure" for an undefined object */
2145 michael@paquier.xyz 5051 :CBC 8 : appendStringInfoString(buffer, "routine");
5052 : 8 : return;
5053 : : }
4819 alvherre@alvh.no-ip. 5054 : 200 : procForm = (Form_pg_proc) GETSTRUCT(procTup);
5055 : :
3011 peter_e@gmx.net 5056 [ + + ]: 200 : if (procForm->prokind == PROKIND_AGGREGATE)
4594 rhaas@postgresql.org 5057 : 40 : appendStringInfoString(buffer, "aggregate");
3011 peter_e@gmx.net 5058 [ + + ]: 160 : else if (procForm->prokind == PROKIND_PROCEDURE)
3103 5059 : 34 : appendStringInfoString(buffer, "procedure");
5060 : : else /* function or window function */
4594 rhaas@postgresql.org 5061 : 126 : appendStringInfoString(buffer, "function");
5062 : :
4819 alvherre@alvh.no-ip. 5063 : 200 : ReleaseSysCache(procTup);
5064 : : }
5065 : :
5066 : : /*
5067 : : * Obtain a given object's identity, as a palloc'ed string.
5068 : : *
5069 : : * This is for machine consumption, so it's not translated. All elements are
5070 : : * schema-qualified when appropriate. Returns NULL if the object could not
5071 : : * be found.
5072 : : */
5073 : : char *
2145 michael@paquier.xyz 5074 : 2162 : getObjectIdentity(const ObjectAddress *object, bool missing_ok)
5075 : : {
5076 : 2162 : return getObjectIdentityParts(object, NULL, NULL, missing_ok);
5077 : : }
5078 : :
5079 : : /*
5080 : : * As above, but more detailed.
5081 : : *
5082 : : * There are two sets of return values: the identity itself as a palloc'd
5083 : : * string is returned. objname and objargs, if not NULL, are output parameters
5084 : : * that receive lists of C-strings that are useful to give back to
5085 : : * get_object_address() to reconstruct the ObjectAddress. Returns NULL if
5086 : : * the object could not be found.
5087 : : */
5088 : : char *
4169 alvherre@alvh.no-ip. 5089 : 5866 : getObjectIdentityParts(const ObjectAddress *object,
5090 : : List **objname, List **objargs,
5091 : : bool missing_ok)
5092 : : {
5093 : : StringInfoData buffer;
5094 : :
4819 5095 : 5866 : initStringInfo(&buffer);
5096 : :
5097 : : /*
5098 : : * Make sure that both objname and objargs were passed, or none was; and
5099 : : * initialize them to empty lists. For objname this is useless because it
5100 : : * will be initialized in all cases inside the switch; but we do it anyway
5101 : : * so that we can test below that no branch leaves it unset.
5102 : : */
248 peter@eisentraut.org 5103 [ - + ]:GNC 5866 : Assert((objname != NULL) == (objargs != NULL));
4169 alvherre@alvh.no-ip. 5104 [ + + ]:CBC 5866 : if (objname)
5105 : : {
5106 : 3656 : *objname = NIL;
5107 : 3656 : *objargs = NIL;
5108 : : }
5109 : :
795 peter@eisentraut.org 5110 : 5866 : switch (object->classId)
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + - ]
[ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
- ]
5111 : : {
5112 : 1809 : case RelationRelationId:
5113 : : {
2145 michael@paquier.xyz 5114 : 1809 : char *attr = NULL;
5115 : :
5116 : : /*
5117 : : * Check for the attribute first, so as if it is missing we
5118 : : * can skip the entire relation description.
5119 : : */
5120 [ + + ]: 1809 : if (object->objectSubId != 0)
5121 : : {
5122 : 415 : attr = get_attname(object->objectId,
5123 : 415 : object->objectSubId,
5124 : : missing_ok);
5125 : :
5126 [ + + + + ]: 415 : if (missing_ok && attr == NULL)
5127 : 8 : break;
5128 : : }
5129 : :
5130 : 1801 : getRelationIdentity(&buffer, object->objectId, objname,
5131 : : missing_ok);
5132 [ + + + + ]: 1801 : if (objname && *objname == NIL)
5133 : 4 : break;
5134 : :
5135 [ + + ]: 1797 : if (attr)
5136 : : {
5137 : 407 : appendStringInfo(&buffer, ".%s",
5138 : : quote_identifier(attr));
5139 [ + + ]: 407 : if (objname)
5140 : 334 : *objname = lappend(*objname, attr);
5141 : : }
5142 : : }
4819 alvherre@alvh.no-ip. 5143 : 1797 : break;
5144 : :
795 peter@eisentraut.org 5145 : 208 : case ProcedureRelationId:
5146 : : {
61 nathan@postgresql.or 5147 :GNC 208 : uint16 flags = FORMAT_PROC_FORCE_QUALIFY | FORMAT_PROC_INVALID_AS_NULL;
2145 michael@paquier.xyz 5148 :CBC 208 : char *proname = format_procedure_extended(object->objectId,
5149 : : flags);
5150 : :
5151 [ + + ]: 208 : if (proname == NULL)
5152 : 8 : break;
5153 : :
5154 : 200 : appendStringInfoString(&buffer, proname);
5155 [ + + ]: 200 : if (objname)
5156 : 94 : format_procedure_parts(object->objectId, objname, objargs,
5157 : : missing_ok);
5158 : 200 : break;
5159 : : }
5160 : :
795 peter@eisentraut.org 5161 : 1080 : case TypeRelationId:
5162 : : {
61 nathan@postgresql.or 5163 :GNC 1080 : uint16 flags = FORMAT_TYPE_INVALID_AS_NULL | FORMAT_TYPE_FORCE_QUALIFY;
5164 : : char *typeout;
5165 : :
2145 michael@paquier.xyz 5166 :CBC 1080 : typeout = format_type_extended(object->objectId, -1, flags);
5167 : :
5168 [ + + ]: 1080 : if (typeout == NULL)
5169 : 8 : break;
5170 : :
4169 alvherre@alvh.no-ip. 5171 : 1072 : appendStringInfoString(&buffer, typeout);
5172 [ + + ]: 1072 : if (objname)
5173 : 929 : *objname = list_make1(typeout);
5174 : : }
4819 5175 : 1072 : break;
5176 : :
795 peter@eisentraut.org 5177 : 41 : case CastRelationId:
5178 : : {
5179 : : Relation castRel;
5180 : : HeapTuple tup;
5181 : : Form_pg_cast castForm;
5182 : :
2686 andres@anarazel.de 5183 : 41 : castRel = table_open(CastRelationId, AccessShareLock);
5184 : :
2748 5185 : 41 : tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
5186 : 41 : object->objectId);
5187 : :
4819 alvherre@alvh.no-ip. 5188 [ + + ]: 41 : if (!HeapTupleIsValid(tup))
5189 : : {
2145 michael@paquier.xyz 5190 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5191 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for cast %u",
5192 : : object->objectId);
5193 : :
2145 michael@paquier.xyz 5194 :CBC 8 : table_close(castRel, AccessShareLock);
5195 : 8 : break;
5196 : : }
5197 : :
4819 alvherre@alvh.no-ip. 5198 : 33 : castForm = (Form_pg_cast) GETSTRUCT(tup);
5199 : :
5200 : 33 : appendStringInfo(&buffer, "(%s AS %s)",
5201 : : format_type_be_qualified(castForm->castsource),
5202 : : format_type_be_qualified(castForm->casttarget));
5203 : :
4169 5204 [ + + ]: 33 : if (objname)
5205 : : {
5206 : 5 : *objname = list_make1(format_type_be_qualified(castForm->castsource));
5207 : 5 : *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
5208 : : }
5209 : :
2686 andres@anarazel.de 5210 : 33 : table_close(castRel, AccessShareLock);
4819 alvherre@alvh.no-ip. 5211 : 33 : break;
5212 : : }
5213 : :
795 peter@eisentraut.org 5214 : 38 : case CollationRelationId:
5215 : : {
5216 : : HeapTuple collTup;
5217 : : Form_pg_collation coll;
5218 : : char *schema;
5219 : :
4819 alvherre@alvh.no-ip. 5220 : 38 : collTup = SearchSysCache1(COLLOID,
5221 : 38 : ObjectIdGetDatum(object->objectId));
5222 [ + + ]: 38 : if (!HeapTupleIsValid(collTup))
5223 : : {
2145 michael@paquier.xyz 5224 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5225 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for collation %u",
5226 : : object->objectId);
2145 michael@paquier.xyz 5227 :CBC 8 : break;
5228 : : }
4819 alvherre@alvh.no-ip. 5229 : 30 : coll = (Form_pg_collation) GETSTRUCT(collTup);
4072 5230 : 30 : schema = get_namespace_name_or_temp(coll->collnamespace);
4819 5231 : 30 : appendStringInfoString(&buffer,
5232 : 30 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5233 : 30 : NameStr(coll->collname)));
4169 alvherre@alvh.no-ip. 5234 [ + + ]: 30 : if (objname)
4168 5235 : 5 : *objname = list_make2(schema,
5236 : : pstrdup(NameStr(coll->collname)));
4819 5237 : 30 : ReleaseSysCache(collTup);
5238 : 30 : break;
5239 : : }
5240 : :
795 peter@eisentraut.org 5241 : 438 : case ConstraintRelationId:
5242 : : {
5243 : : HeapTuple conTup;
5244 : : Form_pg_constraint con;
5245 : :
4819 alvherre@alvh.no-ip. 5246 : 438 : conTup = SearchSysCache1(CONSTROID,
5247 : 438 : ObjectIdGetDatum(object->objectId));
5248 [ + + ]: 438 : if (!HeapTupleIsValid(conTup))
5249 : : {
2145 michael@paquier.xyz 5250 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5251 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for constraint %u",
5252 : : object->objectId);
2145 michael@paquier.xyz 5253 :CBC 8 : break;
5254 : : }
4819 alvherre@alvh.no-ip. 5255 : 430 : con = (Form_pg_constraint) GETSTRUCT(conTup);
5256 : :
5257 [ + + ]: 430 : if (OidIsValid(con->conrelid))
5258 : : {
5259 : 378 : appendStringInfo(&buffer, "%s on ",
5260 : 378 : quote_identifier(NameStr(con->conname)));
2145 michael@paquier.xyz 5261 : 378 : getRelationIdentity(&buffer, con->conrelid, objname,
5262 : : false);
4169 alvherre@alvh.no-ip. 5263 [ + + ]: 378 : if (objname)
5264 : 354 : *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
5265 : : }
5266 : : else
5267 : : {
5268 : : ObjectAddress domain;
5269 : :
5270 [ - + ]: 52 : Assert(OidIsValid(con->contypid));
4819 5271 : 52 : domain.classId = TypeRelationId;
5272 : 52 : domain.objectId = con->contypid;
5273 : 52 : domain.objectSubId = 0;
5274 : :
5275 : 104 : appendStringInfo(&buffer, "%s on %s",
5276 : 52 : quote_identifier(NameStr(con->conname)),
5277 : : getObjectIdentityParts(&domain, objname,
5278 : : objargs, false));
5279 : :
4169 5280 [ + + ]: 52 : if (objname)
5281 : 28 : *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
5282 : : }
5283 : :
4819 5284 : 430 : ReleaseSysCache(conTup);
5285 : 430 : break;
5286 : : }
5287 : :
795 peter@eisentraut.org 5288 : 37 : case ConversionRelationId:
5289 : : {
5290 : : HeapTuple conTup;
5291 : : Form_pg_conversion conForm;
5292 : : char *schema;
5293 : :
4819 alvherre@alvh.no-ip. 5294 : 37 : conTup = SearchSysCache1(CONVOID,
5295 : 37 : ObjectIdGetDatum(object->objectId));
5296 [ + + ]: 37 : if (!HeapTupleIsValid(conTup))
5297 : : {
2145 michael@paquier.xyz 5298 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5299 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for conversion %u",
5300 : : object->objectId);
2145 michael@paquier.xyz 5301 :CBC 8 : break;
5302 : : }
4819 alvherre@alvh.no-ip. 5303 : 29 : conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4072 5304 : 29 : schema = get_namespace_name_or_temp(conForm->connamespace);
4594 rhaas@postgresql.org 5305 : 29 : appendStringInfoString(&buffer,
4025 bruce@momjian.us 5306 : 29 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5307 : 29 : NameStr(conForm->conname)));
4169 alvherre@alvh.no-ip. 5308 [ + + ]: 29 : if (objname)
4072 5309 : 4 : *objname = list_make2(schema,
5310 : : pstrdup(NameStr(conForm->conname)));
4819 5311 : 29 : ReleaseSysCache(conTup);
5312 : 29 : break;
5313 : : }
5314 : :
795 peter@eisentraut.org 5315 : 338 : case AttrDefaultRelationId:
5316 : : {
5317 : : ObjectAddress colobject;
5318 : :
1531 tgl@sss.pgh.pa.us 5319 : 338 : colobject = GetAttrDefaultColumnAddress(object->objectId);
5320 : :
5321 [ + + ]: 338 : if (!OidIsValid(colobject.objectId))
5322 : : {
2145 michael@paquier.xyz 5323 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5324 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for attrdef %u",
5325 : : object->objectId);
2145 michael@paquier.xyz 5326 :CBC 8 : break;
5327 : : }
5328 : :
4819 alvherre@alvh.no-ip. 5329 : 330 : appendStringInfo(&buffer, "for %s",
5330 : : getObjectIdentityParts(&colobject,
5331 : : objname, objargs,
5332 : : false));
5333 : 330 : break;
5334 : : }
5335 : :
795 peter@eisentraut.org 5336 : 36 : case LanguageRelationId:
5337 : : {
5338 : : HeapTuple langTup;
5339 : : Form_pg_language langForm;
5340 : :
4819 alvherre@alvh.no-ip. 5341 : 36 : langTup = SearchSysCache1(LANGOID,
5342 : 36 : ObjectIdGetDatum(object->objectId));
5343 [ + + ]: 36 : if (!HeapTupleIsValid(langTup))
5344 : : {
2145 michael@paquier.xyz 5345 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5346 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for language %u",
5347 : : object->objectId);
2145 michael@paquier.xyz 5348 :CBC 8 : break;
5349 : : }
4819 alvherre@alvh.no-ip. 5350 : 28 : langForm = (Form_pg_language) GETSTRUCT(langTup);
4594 rhaas@postgresql.org 5351 : 28 : appendStringInfoString(&buffer,
3265 tgl@sss.pgh.pa.us 5352 : 28 : quote_identifier(NameStr(langForm->lanname)));
4169 alvherre@alvh.no-ip. 5353 [ + + ]: 28 : if (objname)
5354 : 4 : *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4819 5355 : 28 : ReleaseSysCache(langTup);
5356 : 28 : break;
5357 : : }
5358 : :
795 peter@eisentraut.org 5359 : 8 : case LargeObjectRelationId:
2145 michael@paquier.xyz 5360 [ + - ]: 8 : if (!LargeObjectExists(object->objectId))
5361 : 8 : break;
4819 alvherre@alvh.no-ip. 5362 :UBC 0 : appendStringInfo(&buffer, "%u",
5363 : 0 : object->objectId);
4169 5364 [ # # ]: 0 : if (objname)
5365 : 0 : *objname = list_make1(psprintf("%u", object->objectId));
4819 5366 : 0 : break;
5367 : :
795 peter@eisentraut.org 5368 :CBC 38 : case OperatorRelationId:
5369 : : {
61 nathan@postgresql.or 5370 :GNC 38 : uint16 flags = FORMAT_OPERATOR_FORCE_QUALIFY | FORMAT_OPERATOR_INVALID_AS_NULL;
2145 michael@paquier.xyz 5371 :CBC 38 : char *oprname = format_operator_extended(object->objectId,
5372 : : flags);
5373 : :
5374 [ + + ]: 38 : if (oprname == NULL)
5375 : 8 : break;
5376 : :
5377 : 30 : appendStringInfoString(&buffer, oprname);
5378 [ + + ]: 30 : if (objname)
5379 : 4 : format_operator_parts(object->objectId, objname, objargs, missing_ok);
5380 : 30 : break;
5381 : : }
5382 : :
795 peter@eisentraut.org 5383 : 41 : case OperatorClassRelationId:
5384 : : {
5385 : : HeapTuple opcTup;
5386 : : Form_pg_opclass opcForm;
5387 : : HeapTuple amTup;
5388 : : Form_pg_am amForm;
5389 : : char *schema;
5390 : :
4819 alvherre@alvh.no-ip. 5391 : 41 : opcTup = SearchSysCache1(CLAOID,
5392 : 41 : ObjectIdGetDatum(object->objectId));
5393 [ + + ]: 41 : if (!HeapTupleIsValid(opcTup))
5394 : : {
2145 michael@paquier.xyz 5395 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5396 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for opclass %u",
5397 : : object->objectId);
2145 michael@paquier.xyz 5398 :CBC 8 : break;
5399 : : }
4819 alvherre@alvh.no-ip. 5400 : 33 : opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4072 5401 : 33 : schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5402 : :
4819 5403 : 33 : amTup = SearchSysCache1(AMOID,
5404 : : ObjectIdGetDatum(opcForm->opcmethod));
5405 [ - + ]: 33 : if (!HeapTupleIsValid(amTup))
4819 alvherre@alvh.no-ip. 5406 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for access method %u",
5407 : : opcForm->opcmethod);
4819 alvherre@alvh.no-ip. 5408 :CBC 33 : amForm = (Form_pg_am) GETSTRUCT(amTup);
5409 : :
4093 5410 : 33 : appendStringInfo(&buffer, "%s USING %s",
5411 : : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5412 : 33 : NameStr(opcForm->opcname)),
4819 alvherre@alvh.no-ip. 5413 : 33 : quote_identifier(NameStr(amForm->amname)));
4169 5414 [ + + ]: 33 : if (objname)
4093 5415 : 4 : *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5416 : : schema,
5417 : : pstrdup(NameStr(opcForm->opcname)));
5418 : :
4819 5419 : 33 : ReleaseSysCache(amTup);
5420 : 33 : ReleaseSysCache(opcTup);
5421 : 33 : break;
5422 : : }
5423 : :
795 peter@eisentraut.org 5424 : 42 : case OperatorFamilyRelationId:
2145 michael@paquier.xyz 5425 : 42 : getOpFamilyIdentity(&buffer, object->objectId, objname,
5426 : : missing_ok);
4819 alvherre@alvh.no-ip. 5427 : 42 : break;
5428 : :
795 peter@eisentraut.org 5429 : 36 : case AccessMethodRelationId:
5430 : : {
5431 : : char *amname;
5432 : :
3303 tgl@sss.pgh.pa.us 5433 : 36 : amname = get_am_name(object->objectId);
5434 [ + + ]: 36 : if (!amname)
5435 : : {
2145 michael@paquier.xyz 5436 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5437 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for access method %u",
5438 : : object->objectId);
2145 michael@paquier.xyz 5439 :CBC 8 : break;
5440 : : }
3303 tgl@sss.pgh.pa.us 5441 : 28 : appendStringInfoString(&buffer, quote_identifier(amname));
5442 [ + + ]: 28 : if (objname)
5443 : 4 : *objname = list_make1(amname);
5444 : : }
5445 : 28 : break;
5446 : :
795 peter@eisentraut.org 5447 : 36 : case AccessMethodOperatorRelationId:
5448 : : {
5449 : : Relation amopDesc;
5450 : : HeapTuple tup;
5451 : : ScanKeyData skey[1];
5452 : : SysScanDesc amscan;
5453 : : Form_pg_amop amopForm;
5454 : : StringInfoData opfam;
5455 : : char *ltype;
5456 : : char *rtype;
5457 : :
2686 andres@anarazel.de 5458 : 36 : amopDesc = table_open(AccessMethodOperatorRelationId,
5459 : : AccessShareLock);
5460 : :
4819 alvherre@alvh.no-ip. 5461 : 36 : ScanKeyInit(&skey[0],
5462 : : Anum_pg_amop_oid,
5463 : : BTEqualStrategyNumber, F_OIDEQ,
5464 : 36 : ObjectIdGetDatum(object->objectId));
5465 : :
5466 : 36 : amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
5467 : : NULL, 1, skey);
5468 : :
5469 : 36 : tup = systable_getnext(amscan);
5470 : :
5471 [ + + ]: 36 : if (!HeapTupleIsValid(tup))
5472 : : {
2145 michael@paquier.xyz 5473 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5474 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for amop entry %u",
5475 : : object->objectId);
5476 : :
2145 michael@paquier.xyz 5477 :CBC 8 : systable_endscan(amscan);
5478 : 8 : table_close(amopDesc, AccessShareLock);
5479 : 8 : break;
5480 : : }
5481 : :
4819 alvherre@alvh.no-ip. 5482 : 28 : amopForm = (Form_pg_amop) GETSTRUCT(tup);
5483 : :
5484 : 28 : initStringInfo(&opfam);
2145 michael@paquier.xyz 5485 : 28 : getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5486 : : false);
5487 : :
4093 alvherre@alvh.no-ip. 5488 : 28 : ltype = format_type_be_qualified(amopForm->amoplefttype);
5489 : 28 : rtype = format_type_be_qualified(amopForm->amoprighttype);
5490 : :
5491 [ + + ]: 28 : if (objname)
5492 : : {
5493 : 4 : *objname = lappend(*objname,
3265 tgl@sss.pgh.pa.us 5494 : 4 : psprintf("%d", amopForm->amopstrategy));
4093 alvherre@alvh.no-ip. 5495 : 4 : *objargs = list_make2(ltype, rtype);
5496 : : }
5497 : :
4819 5498 : 28 : appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5499 : 28 : amopForm->amopstrategy,
5500 : : ltype, rtype, opfam.data);
5501 : :
5502 : 28 : pfree(opfam.data);
5503 : :
5504 : 28 : systable_endscan(amscan);
2686 andres@anarazel.de 5505 : 28 : table_close(amopDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 5506 : 28 : break;
5507 : : }
5508 : :
795 peter@eisentraut.org 5509 : 36 : case AccessMethodProcedureRelationId:
5510 : : {
5511 : : Relation amprocDesc;
5512 : : ScanKeyData skey[1];
5513 : : SysScanDesc amscan;
5514 : : HeapTuple tup;
5515 : : Form_pg_amproc amprocForm;
5516 : : StringInfoData opfam;
5517 : : char *ltype;
5518 : : char *rtype;
5519 : :
2686 andres@anarazel.de 5520 : 36 : amprocDesc = table_open(AccessMethodProcedureRelationId,
5521 : : AccessShareLock);
5522 : :
4819 alvherre@alvh.no-ip. 5523 : 36 : ScanKeyInit(&skey[0],
5524 : : Anum_pg_amproc_oid,
5525 : : BTEqualStrategyNumber, F_OIDEQ,
5526 : 36 : ObjectIdGetDatum(object->objectId));
5527 : :
5528 : 36 : amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
5529 : : NULL, 1, skey);
5530 : :
5531 : 36 : tup = systable_getnext(amscan);
5532 : :
5533 [ + + ]: 36 : if (!HeapTupleIsValid(tup))
5534 : : {
2145 michael@paquier.xyz 5535 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5536 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for amproc entry %u",
5537 : : object->objectId);
5538 : :
2145 michael@paquier.xyz 5539 :CBC 8 : systable_endscan(amscan);
5540 : 8 : table_close(amprocDesc, AccessShareLock);
5541 : 8 : break;
5542 : : }
5543 : :
4819 alvherre@alvh.no-ip. 5544 : 28 : amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
5545 : :
5546 : 28 : initStringInfo(&opfam);
2145 michael@paquier.xyz 5547 : 28 : getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5548 : : false);
5549 : :
4093 alvherre@alvh.no-ip. 5550 : 28 : ltype = format_type_be_qualified(amprocForm->amproclefttype);
5551 : 28 : rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5552 : :
5553 [ + + ]: 28 : if (objname)
5554 : : {
5555 : 4 : *objname = lappend(*objname,
5556 : 4 : psprintf("%d", amprocForm->amprocnum));
5557 : 4 : *objargs = list_make2(ltype, rtype);
5558 : : }
5559 : :
4819 5560 : 28 : appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5561 : 28 : amprocForm->amprocnum,
5562 : : ltype, rtype, opfam.data);
5563 : :
5564 : 28 : pfree(opfam.data);
5565 : :
5566 : 28 : systable_endscan(amscan);
2686 andres@anarazel.de 5567 : 28 : table_close(amprocDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 5568 : 28 : break;
5569 : : }
5570 : :
795 peter@eisentraut.org 5571 : 59 : case RewriteRelationId:
5572 : : {
5573 : : Relation ruleDesc;
5574 : : HeapTuple tup;
5575 : : Form_pg_rewrite rule;
5576 : :
2686 andres@anarazel.de 5577 : 59 : ruleDesc = table_open(RewriteRelationId, AccessShareLock);
5578 : :
2748 5579 : 59 : tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
5580 : 59 : object->objectId);
5581 : :
4819 alvherre@alvh.no-ip. 5582 [ + + ]: 59 : if (!HeapTupleIsValid(tup))
5583 : : {
2145 michael@paquier.xyz 5584 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5585 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for rule %u",
5586 : : object->objectId);
5587 : :
2145 michael@paquier.xyz 5588 :CBC 8 : table_close(ruleDesc, AccessShareLock);
5589 : 8 : break;
5590 : : }
5591 : :
4819 alvherre@alvh.no-ip. 5592 : 51 : rule = (Form_pg_rewrite) GETSTRUCT(tup);
5593 : :
5594 : 51 : appendStringInfo(&buffer, "%s on ",
5595 : 51 : quote_identifier(NameStr(rule->rulename)));
2145 michael@paquier.xyz 5596 : 51 : getRelationIdentity(&buffer, rule->ev_class, objname, false);
4169 alvherre@alvh.no-ip. 5597 [ + + ]: 51 : if (objname)
4168 5598 : 22 : *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5599 : :
2686 andres@anarazel.de 5600 : 51 : table_close(ruleDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 5601 : 51 : break;
5602 : : }
5603 : :
795 peter@eisentraut.org 5604 : 127 : case TriggerRelationId:
5605 : : {
5606 : : Relation trigDesc;
5607 : : HeapTuple tup;
5608 : : Form_pg_trigger trig;
5609 : :
2686 andres@anarazel.de 5610 : 127 : trigDesc = table_open(TriggerRelationId, AccessShareLock);
5611 : :
2748 5612 : 127 : tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
5613 : 127 : object->objectId);
5614 : :
4819 alvherre@alvh.no-ip. 5615 [ + + ]: 127 : if (!HeapTupleIsValid(tup))
5616 : : {
2145 michael@paquier.xyz 5617 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5618 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for trigger %u",
5619 : : object->objectId);
5620 : :
2145 michael@paquier.xyz 5621 :CBC 8 : table_close(trigDesc, AccessShareLock);
5622 : 8 : break;
5623 : : }
5624 : :
4819 alvherre@alvh.no-ip. 5625 : 119 : trig = (Form_pg_trigger) GETSTRUCT(tup);
5626 : :
5627 : 119 : appendStringInfo(&buffer, "%s on ",
5628 : 119 : quote_identifier(NameStr(trig->tgname)));
2145 michael@paquier.xyz 5629 : 119 : getRelationIdentity(&buffer, trig->tgrelid, objname, false);
4169 alvherre@alvh.no-ip. 5630 [ + + ]: 119 : if (objname)
4168 5631 : 84 : *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5632 : :
2686 andres@anarazel.de 5633 : 119 : table_close(trigDesc, AccessShareLock);
4819 alvherre@alvh.no-ip. 5634 : 119 : break;
5635 : : }
5636 : :
795 peter@eisentraut.org 5637 : 91 : case NamespaceRelationId:
5638 : : {
5639 : : char *nspname;
5640 : :
4072 alvherre@alvh.no-ip. 5641 : 91 : nspname = get_namespace_name_or_temp(object->objectId);
4819 5642 [ + + ]: 91 : if (!nspname)
5643 : : {
2145 michael@paquier.xyz 5644 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5645 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for namespace %u",
5646 : : object->objectId);
2145 michael@paquier.xyz 5647 :CBC 8 : break;
5648 : : }
4594 rhaas@postgresql.org 5649 : 83 : appendStringInfoString(&buffer,
5650 : : quote_identifier(nspname));
4169 alvherre@alvh.no-ip. 5651 [ + + ]: 83 : if (objname)
5652 : 49 : *objname = list_make1(nspname);
4819 5653 : 83 : break;
5654 : : }
5655 : :
795 peter@eisentraut.org 5656 : 37 : case StatisticExtRelationId:
5657 : : {
5658 : : HeapTuple tup;
5659 : : Form_pg_statistic_ext formStatistic;
5660 : : char *schema;
5661 : :
3303 tgl@sss.pgh.pa.us 5662 : 37 : tup = SearchSysCache1(STATEXTOID,
5663 : 37 : ObjectIdGetDatum(object->objectId));
5664 [ + + ]: 37 : if (!HeapTupleIsValid(tup))
5665 : : {
2145 michael@paquier.xyz 5666 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5667 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for statistics object %u",
5668 : : object->objectId);
2145 michael@paquier.xyz 5669 :CBC 8 : break;
5670 : : }
3303 tgl@sss.pgh.pa.us 5671 : 29 : formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
5672 : 29 : schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5673 : 29 : appendStringInfoString(&buffer,
5674 : 29 : quote_qualified_identifier(schema,
3265 5675 : 29 : NameStr(formStatistic->stxname)));
3303 5676 [ + + ]: 29 : if (objname)
5677 : 4 : *objname = list_make2(schema,
5678 : : pstrdup(NameStr(formStatistic->stxname)));
5679 : 29 : ReleaseSysCache(tup);
5680 : : }
5681 : 29 : break;
5682 : :
795 peter@eisentraut.org 5683 : 38 : case TSParserRelationId:
5684 : : {
5685 : : HeapTuple tup;
5686 : : Form_pg_ts_parser formParser;
5687 : : char *schema;
5688 : :
4819 alvherre@alvh.no-ip. 5689 : 38 : tup = SearchSysCache1(TSPARSEROID,
5690 : 38 : ObjectIdGetDatum(object->objectId));
5691 [ + + ]: 38 : if (!HeapTupleIsValid(tup))
5692 : : {
2145 michael@paquier.xyz 5693 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5694 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search parser %u",
5695 : : object->objectId);
2145 michael@paquier.xyz 5696 :CBC 8 : break;
5697 : : }
4819 alvherre@alvh.no-ip. 5698 : 30 : formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4072 5699 : 30 : schema = get_namespace_name_or_temp(formParser->prsnamespace);
4594 rhaas@postgresql.org 5700 : 30 : appendStringInfoString(&buffer,
4427 alvherre@alvh.no-ip. 5701 : 30 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5702 : 30 : NameStr(formParser->prsname)));
4169 alvherre@alvh.no-ip. 5703 [ + + ]: 30 : if (objname)
5704 : 5 : *objname = list_make2(schema,
5705 : : pstrdup(NameStr(formParser->prsname)));
4819 5706 : 30 : ReleaseSysCache(tup);
5707 : 30 : break;
5708 : : }
5709 : :
795 peter@eisentraut.org 5710 : 36 : case TSDictionaryRelationId:
5711 : : {
5712 : : HeapTuple tup;
5713 : : Form_pg_ts_dict formDict;
5714 : : char *schema;
5715 : :
4819 alvherre@alvh.no-ip. 5716 : 36 : tup = SearchSysCache1(TSDICTOID,
5717 : 36 : ObjectIdGetDatum(object->objectId));
5718 [ + + ]: 36 : if (!HeapTupleIsValid(tup))
5719 : : {
2145 michael@paquier.xyz 5720 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5721 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search dictionary %u",
5722 : : object->objectId);
2145 michael@paquier.xyz 5723 :CBC 8 : break;
5724 : : }
4819 alvherre@alvh.no-ip. 5725 : 28 : formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4072 5726 : 28 : schema = get_namespace_name_or_temp(formDict->dictnamespace);
4594 rhaas@postgresql.org 5727 : 28 : appendStringInfoString(&buffer,
4427 alvherre@alvh.no-ip. 5728 : 28 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5729 : 28 : NameStr(formDict->dictname)));
4169 alvherre@alvh.no-ip. 5730 [ + + ]: 28 : if (objname)
5731 : 4 : *objname = list_make2(schema,
5732 : : pstrdup(NameStr(formDict->dictname)));
4819 5733 : 28 : ReleaseSysCache(tup);
5734 : 28 : break;
5735 : : }
5736 : :
795 peter@eisentraut.org 5737 : 36 : case TSTemplateRelationId:
5738 : : {
5739 : : HeapTuple tup;
5740 : : Form_pg_ts_template formTmpl;
5741 : : char *schema;
5742 : :
4819 alvherre@alvh.no-ip. 5743 : 36 : tup = SearchSysCache1(TSTEMPLATEOID,
5744 : 36 : ObjectIdGetDatum(object->objectId));
5745 [ + + ]: 36 : if (!HeapTupleIsValid(tup))
5746 : : {
2145 michael@paquier.xyz 5747 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5748 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search template %u",
5749 : : object->objectId);
2145 michael@paquier.xyz 5750 :CBC 8 : break;
5751 : : }
4819 alvherre@alvh.no-ip. 5752 : 28 : formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4072 5753 : 28 : schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4594 rhaas@postgresql.org 5754 : 28 : appendStringInfoString(&buffer,
4427 alvherre@alvh.no-ip. 5755 : 28 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5756 : 28 : NameStr(formTmpl->tmplname)));
4169 alvherre@alvh.no-ip. 5757 [ + + ]: 28 : if (objname)
5758 : 4 : *objname = list_make2(schema,
5759 : : pstrdup(NameStr(formTmpl->tmplname)));
4819 5760 : 28 : ReleaseSysCache(tup);
5761 : 28 : break;
5762 : : }
5763 : :
795 peter@eisentraut.org 5764 : 40 : case TSConfigRelationId:
5765 : : {
5766 : : HeapTuple tup;
5767 : : Form_pg_ts_config formCfg;
5768 : : char *schema;
5769 : :
4819 alvherre@alvh.no-ip. 5770 : 40 : tup = SearchSysCache1(TSCONFIGOID,
5771 : 40 : ObjectIdGetDatum(object->objectId));
5772 [ + + ]: 40 : if (!HeapTupleIsValid(tup))
5773 : : {
2145 michael@paquier.xyz 5774 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5775 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for text search configuration %u",
5776 : : object->objectId);
2145 michael@paquier.xyz 5777 :CBC 8 : break;
5778 : : }
4819 alvherre@alvh.no-ip. 5779 : 32 : formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4072 5780 : 32 : schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4594 rhaas@postgresql.org 5781 : 32 : appendStringInfoString(&buffer,
4427 alvherre@alvh.no-ip. 5782 : 32 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 5783 : 32 : NameStr(formCfg->cfgname)));
4169 alvherre@alvh.no-ip. 5784 [ + + ]: 32 : if (objname)
5785 : 4 : *objname = list_make2(schema,
5786 : : pstrdup(NameStr(formCfg->cfgname)));
4819 5787 : 32 : ReleaseSysCache(tup);
5788 : 32 : break;
5789 : : }
5790 : :
795 peter@eisentraut.org 5791 : 36 : case AuthIdRelationId:
5792 : : {
5793 : : char *username;
5794 : :
2145 michael@paquier.xyz 5795 : 36 : username = GetUserNameFromId(object->objectId, missing_ok);
5796 [ + + ]: 36 : if (!username)
5797 : 8 : break;
4169 alvherre@alvh.no-ip. 5798 [ + + ]: 28 : if (objname)
5799 : 4 : *objname = list_make1(username);
4594 rhaas@postgresql.org 5800 : 28 : appendStringInfoString(&buffer,
5801 : : quote_identifier(username));
4819 alvherre@alvh.no-ip. 5802 : 28 : break;
5803 : : }
5804 : :
795 peter@eisentraut.org 5805 : 8 : case AuthMemRelationId:
5806 : : {
5807 : : Relation authMemDesc;
5808 : : ScanKeyData skey[1];
5809 : : SysScanDesc amscan;
5810 : : HeapTuple tup;
5811 : : Form_pg_auth_members amForm;
5812 : :
1381 rhaas@postgresql.org 5813 : 8 : authMemDesc = table_open(AuthMemRelationId,
5814 : : AccessShareLock);
5815 : :
5816 : 8 : ScanKeyInit(&skey[0],
5817 : : Anum_pg_auth_members_oid,
5818 : : BTEqualStrategyNumber, F_OIDEQ,
5819 : 8 : ObjectIdGetDatum(object->objectId));
5820 : :
5821 : 8 : amscan = systable_beginscan(authMemDesc, AuthMemOidIndexId, true,
5822 : : NULL, 1, skey);
5823 : :
5824 : 8 : tup = systable_getnext(amscan);
5825 : :
5826 [ + - ]: 8 : if (!HeapTupleIsValid(tup))
5827 : : {
5828 [ - + ]: 8 : if (!missing_ok)
1381 rhaas@postgresql.org 5829 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5830 : : object->objectId);
5831 : :
1381 rhaas@postgresql.org 5832 :CBC 8 : systable_endscan(amscan);
5833 : 8 : table_close(authMemDesc, AccessShareLock);
5834 : 8 : break;
5835 : : }
5836 : :
1381 rhaas@postgresql.org 5837 :UBC 0 : amForm = (Form_pg_auth_members) GETSTRUCT(tup);
5838 : :
5839 : 0 : appendStringInfo(&buffer, _("membership of role %s in role %s"),
5840 : : GetUserNameFromId(amForm->member, false),
5841 : : GetUserNameFromId(amForm->roleid, false));
5842 : :
5843 : 0 : systable_endscan(amscan);
5844 : 0 : table_close(authMemDesc, AccessShareLock);
5845 : 0 : break;
5846 : : }
5847 : :
795 peter@eisentraut.org 5848 :CBC 8 : case DatabaseRelationId:
5849 : : {
5850 : : char *datname;
5851 : :
4819 alvherre@alvh.no-ip. 5852 : 8 : datname = get_database_name(object->objectId);
5853 [ + - ]: 8 : if (!datname)
5854 : : {
2145 michael@paquier.xyz 5855 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5856 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for database %u",
5857 : : object->objectId);
2145 michael@paquier.xyz 5858 :CBC 8 : break;
5859 : : }
4169 alvherre@alvh.no-ip. 5860 [ # # ]:UBC 0 : if (objname)
5861 : 0 : *objname = list_make1(datname);
4594 rhaas@postgresql.org 5862 : 0 : appendStringInfoString(&buffer,
5863 : : quote_identifier(datname));
4819 alvherre@alvh.no-ip. 5864 : 0 : break;
5865 : : }
5866 : :
795 peter@eisentraut.org 5867 :CBC 8 : case TableSpaceRelationId:
5868 : : {
5869 : : char *tblspace;
5870 : :
4819 alvherre@alvh.no-ip. 5871 : 8 : tblspace = get_tablespace_name(object->objectId);
5872 [ + - ]: 8 : if (!tblspace)
5873 : : {
2145 michael@paquier.xyz 5874 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5875 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for tablespace %u",
5876 : : object->objectId);
2145 michael@paquier.xyz 5877 :CBC 8 : break;
5878 : : }
4169 alvherre@alvh.no-ip. 5879 [ # # ]:UBC 0 : if (objname)
5880 : 0 : *objname = list_make1(tblspace);
4594 rhaas@postgresql.org 5881 : 0 : appendStringInfoString(&buffer,
5882 : : quote_identifier(tblspace));
4819 alvherre@alvh.no-ip. 5883 : 0 : break;
5884 : : }
5885 : :
795 peter@eisentraut.org 5886 :CBC 40 : case ForeignDataWrapperRelationId:
5887 : : {
5888 : : ForeignDataWrapper *fdw;
5889 : :
2145 michael@paquier.xyz 5890 : 40 : fdw = GetForeignDataWrapperExtended(object->objectId,
5891 : : missing_ok);
5892 [ + + ]: 40 : if (fdw)
5893 : : {
5894 : 32 : appendStringInfoString(&buffer, quote_identifier(fdw->fdwname));
5895 [ + + ]: 32 : if (objname)
5896 : 8 : *objname = list_make1(pstrdup(fdw->fdwname));
5897 : : }
4819 alvherre@alvh.no-ip. 5898 : 40 : break;
5899 : : }
5900 : :
795 peter@eisentraut.org 5901 : 40 : case ForeignServerRelationId:
5902 : : {
5903 : : ForeignServer *srv;
5904 : :
2145 michael@paquier.xyz 5905 : 40 : srv = GetForeignServerExtended(object->objectId,
5906 : : missing_ok);
5907 [ + + ]: 40 : if (srv)
5908 : : {
5909 : 32 : appendStringInfoString(&buffer,
5910 : 32 : quote_identifier(srv->servername));
5911 [ + + ]: 32 : if (objname)
5912 : 8 : *objname = list_make1(pstrdup(srv->servername));
5913 : : }
4819 alvherre@alvh.no-ip. 5914 : 40 : break;
5915 : : }
5916 : :
795 peter@eisentraut.org 5917 : 40 : case UserMappingRelationId:
5918 : : {
5919 : : HeapTuple tup;
5920 : : Oid useid;
5921 : : Form_pg_user_mapping umform;
5922 : : ForeignServer *srv;
5923 : : const char *usename;
5924 : :
4819 alvherre@alvh.no-ip. 5925 : 40 : tup = SearchSysCache1(USERMAPPINGOID,
5926 : 40 : ObjectIdGetDatum(object->objectId));
5927 [ + + ]: 40 : if (!HeapTupleIsValid(tup))
5928 : : {
2145 michael@paquier.xyz 5929 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5930 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for user mapping %u",
5931 : : object->objectId);
2145 michael@paquier.xyz 5932 :CBC 8 : break;
5933 : : }
4104 alvherre@alvh.no-ip. 5934 : 32 : umform = (Form_pg_user_mapping) GETSTRUCT(tup);
5935 : 32 : useid = umform->umuser;
5936 : 32 : srv = GetForeignServer(umform->umserver);
5937 : :
4819 5938 : 32 : ReleaseSysCache(tup);
5939 : :
5940 [ + - ]: 32 : if (OidIsValid(useid))
4039 andrew@dunslane.net 5941 : 32 : usename = GetUserNameFromId(useid, false);
5942 : : else
4819 alvherre@alvh.no-ip. 5943 :UBC 0 : usename = "public";
5944 : :
4104 alvherre@alvh.no-ip. 5945 [ + + ]:CBC 32 : if (objname)
5946 : : {
5947 : 8 : *objname = list_make1(pstrdup(usename));
5948 : 8 : *objargs = list_make1(pstrdup(srv->servername));
5949 : : }
5950 : :
4084 5951 : 32 : appendStringInfo(&buffer, "%s on server %s",
5952 : : quote_identifier(usename),
5953 : : srv->servername);
4819 5954 : 32 : break;
5955 : : }
5956 : :
795 peter@eisentraut.org 5957 : 68 : case DefaultAclRelationId:
5958 : : {
5959 : : Relation defaclrel;
5960 : : ScanKeyData skey[1];
5961 : : SysScanDesc rcscan;
5962 : : HeapTuple tup;
5963 : : Form_pg_default_acl defacl;
5964 : : char *schema;
5965 : : char *username;
5966 : :
2686 andres@anarazel.de 5967 : 68 : defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
5968 : :
4819 alvherre@alvh.no-ip. 5969 : 68 : ScanKeyInit(&skey[0],
5970 : : Anum_pg_default_acl_oid,
5971 : : BTEqualStrategyNumber, F_OIDEQ,
5972 : 68 : ObjectIdGetDatum(object->objectId));
5973 : :
5974 : 68 : rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5975 : : true, NULL, 1, skey);
5976 : :
5977 : 68 : tup = systable_getnext(rcscan);
5978 : :
5979 [ + + ]: 68 : if (!HeapTupleIsValid(tup))
5980 : : {
2145 michael@paquier.xyz 5981 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 5982 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for default ACL %u",
5983 : : object->objectId);
5984 : :
2145 michael@paquier.xyz 5985 :CBC 8 : systable_endscan(rcscan);
5986 : 8 : table_close(defaclrel, AccessShareLock);
5987 : 8 : break;
5988 : : }
5989 : :
4819 alvherre@alvh.no-ip. 5990 : 60 : defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5991 : :
4039 andrew@dunslane.net 5992 : 60 : username = GetUserNameFromId(defacl->defaclrole, false);
4819 alvherre@alvh.no-ip. 5993 : 60 : appendStringInfo(&buffer,
5994 : : "for role %s",
5995 : : quote_identifier(username));
5996 : :
5997 [ + + ]: 60 : if (OidIsValid(defacl->defaclnamespace))
5998 : : {
4072 5999 : 28 : schema = get_namespace_name_or_temp(defacl->defaclnamespace);
4819 6000 : 28 : appendStringInfo(&buffer,
6001 : : " in schema %s",
6002 : : quote_identifier(schema));
6003 : : }
6004 : : else
4098 6005 : 32 : schema = NULL;
6006 : :
4819 6007 [ + - - - : 60 : switch (defacl->defaclobjtype)
- - - ]
6008 : : {
6009 : 60 : case DEFACLOBJ_RELATION:
6010 : 60 : appendStringInfoString(&buffer,
6011 : : " on tables");
6012 : 60 : break;
4819 alvherre@alvh.no-ip. 6013 :UBC 0 : case DEFACLOBJ_SEQUENCE:
6014 : 0 : appendStringInfoString(&buffer,
6015 : : " on sequences");
6016 : 0 : break;
6017 : 0 : case DEFACLOBJ_FUNCTION:
6018 : 0 : appendStringInfoString(&buffer,
6019 : : " on functions");
6020 : 0 : break;
6021 : 0 : case DEFACLOBJ_TYPE:
6022 : 0 : appendStringInfoString(&buffer,
6023 : : " on types");
6024 : 0 : break;
3350 teodor@sigaev.ru 6025 : 0 : case DEFACLOBJ_NAMESPACE:
6026 : 0 : appendStringInfoString(&buffer,
6027 : : " on schemas");
6028 : 0 : break;
421 fujii@postgresql.org 6029 : 0 : case DEFACLOBJ_LARGEOBJECT:
6030 : 0 : appendStringInfoString(&buffer,
6031 : : " on large objects");
6032 : 0 : break;
6033 : : }
6034 : :
4098 alvherre@alvh.no-ip. 6035 [ + + ]:CBC 60 : if (objname)
6036 : : {
6037 : 12 : *objname = list_make1(username);
6038 [ + + ]: 12 : if (schema)
6039 : 4 : *objname = lappend(*objname, schema);
6040 : 12 : *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
6041 : : }
6042 : :
4819 6043 : 60 : systable_endscan(rcscan);
2686 andres@anarazel.de 6044 : 60 : table_close(defaclrel, AccessShareLock);
4819 alvherre@alvh.no-ip. 6045 : 60 : break;
6046 : : }
6047 : :
795 peter@eisentraut.org 6048 : 20 : case ExtensionRelationId:
6049 : : {
6050 : : char *extname;
6051 : :
4819 alvherre@alvh.no-ip. 6052 : 20 : extname = get_extension_name(object->objectId);
6053 [ + + ]: 20 : if (!extname)
6054 : : {
2145 michael@paquier.xyz 6055 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 6056 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for extension %u",
6057 : : object->objectId);
2145 michael@paquier.xyz 6058 :CBC 8 : break;
6059 : : }
4594 rhaas@postgresql.org 6060 : 12 : appendStringInfoString(&buffer, quote_identifier(extname));
4169 alvherre@alvh.no-ip. 6061 [ - + ]: 12 : if (objname)
4169 alvherre@alvh.no-ip. 6062 :UBC 0 : *objname = list_make1(extname);
4819 alvherre@alvh.no-ip. 6063 :CBC 12 : break;
6064 : : }
6065 : :
795 peter@eisentraut.org 6066 : 32 : case EventTriggerRelationId:
6067 : : {
6068 : : HeapTuple tup;
6069 : : Form_pg_event_trigger trigForm;
6070 : : char *evtname;
6071 : :
4819 alvherre@alvh.no-ip. 6072 : 32 : tup = SearchSysCache1(EVENTTRIGGEROID,
6073 : 32 : ObjectIdGetDatum(object->objectId));
6074 [ + + ]: 32 : if (!HeapTupleIsValid(tup))
6075 : : {
2145 michael@paquier.xyz 6076 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 6077 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for event trigger %u",
6078 : : object->objectId);
2145 michael@paquier.xyz 6079 :CBC 8 : break;
6080 : : }
4819 alvherre@alvh.no-ip. 6081 : 24 : trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
1858 michael@paquier.xyz 6082 : 24 : evtname = pstrdup(NameStr(trigForm->evtname));
6083 : 24 : appendStringInfoString(&buffer, quote_identifier(evtname));
6084 [ + + ]: 24 : if (objname)
6085 : 12 : *objname = list_make1(evtname);
4819 alvherre@alvh.no-ip. 6086 : 24 : ReleaseSysCache(tup);
6087 : 24 : break;
6088 : : }
6089 : :
795 peter@eisentraut.org 6090 : 10 : case ParameterAclRelationId:
6091 : : {
6092 : : HeapTuple tup;
6093 : : Datum nameDatum;
6094 : : char *parname;
6095 : :
1515 tgl@sss.pgh.pa.us 6096 : 10 : tup = SearchSysCache1(PARAMETERACLOID,
6097 : 10 : ObjectIdGetDatum(object->objectId));
6098 [ + + ]: 10 : if (!HeapTupleIsValid(tup))
6099 : : {
6100 [ - + ]: 8 : if (!missing_ok)
1515 tgl@sss.pgh.pa.us 6101 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for parameter ACL %u",
6102 : : object->objectId);
1515 tgl@sss.pgh.pa.us 6103 :CBC 8 : break;
6104 : : }
1162 dgustafsson@postgres 6105 : 2 : nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
6106 : : Anum_pg_parameter_acl_parname);
1515 tgl@sss.pgh.pa.us 6107 : 2 : parname = TextDatumGetCString(nameDatum);
6108 : 2 : appendStringInfoString(&buffer, parname);
6109 [ + + ]: 2 : if (objname)
6110 : 1 : *objname = list_make1(parname);
6111 : 2 : ReleaseSysCache(tup);
6112 : 2 : break;
6113 : : }
6114 : :
795 peter@eisentraut.org 6115 : 64 : case PolicyRelationId:
6116 : : {
6117 : : Relation polDesc;
6118 : : HeapTuple tup;
6119 : : Form_pg_policy policy;
6120 : :
2686 andres@anarazel.de 6121 : 64 : polDesc = table_open(PolicyRelationId, AccessShareLock);
6122 : :
2748 6123 : 64 : tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
6124 : 64 : object->objectId);
6125 : :
3996 alvherre@alvh.no-ip. 6126 [ + + ]: 64 : if (!HeapTupleIsValid(tup))
6127 : : {
2145 michael@paquier.xyz 6128 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 6129 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for policy %u",
6130 : : object->objectId);
6131 : :
2145 michael@paquier.xyz 6132 :CBC 8 : table_close(polDesc, AccessShareLock);
6133 : 8 : break;
6134 : : }
6135 : :
3303 tgl@sss.pgh.pa.us 6136 : 56 : policy = (Form_pg_policy) GETSTRUCT(tup);
6137 : :
6138 : 56 : appendStringInfo(&buffer, "%s on ",
6139 : 56 : quote_identifier(NameStr(policy->polname)));
2145 michael@paquier.xyz 6140 : 56 : getRelationIdentity(&buffer, policy->polrelid, objname, false);
3996 alvherre@alvh.no-ip. 6141 [ + + ]: 56 : if (objname)
3303 tgl@sss.pgh.pa.us 6142 : 24 : *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
6143 : :
2686 andres@anarazel.de 6144 : 56 : table_close(polDesc, AccessShareLock);
3303 tgl@sss.pgh.pa.us 6145 : 56 : break;
6146 : : }
6147 : :
75 peter@eisentraut.org 6148 :GNC 148 : case PropgraphElementRelationId:
6149 : : {
6150 : : HeapTuple tup;
6151 : : Form_pg_propgraph_element pge;
6152 : :
40 6153 : 148 : tup = SearchSysCache1(PROPGRAPHELOID, ObjectIdGetDatum(object->objectId));
75 6154 [ + + ]: 148 : if (!HeapTupleIsValid(tup))
6155 : : {
6156 [ - + ]: 8 : if (!missing_ok)
75 peter@eisentraut.org 6157 [ # # ]:UNC 0 : elog(ERROR, "cache lookup failed for property graph element %u", object->objectId);
75 peter@eisentraut.org 6158 :GNC 8 : break;
6159 : : }
6160 : 140 : pge = (Form_pg_propgraph_element) GETSTRUCT(tup);
6161 : 140 : appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pge->pgealias)));
6162 : :
6163 : 140 : getRelationIdentity(&buffer, pge->pgepgid, objname, false);
6164 [ + + ]: 140 : if (objname)
6165 : 60 : *objname = lappend(*objname, pstrdup(NameStr(pge->pgealias)));
6166 : :
6167 : 140 : ReleaseSysCache(tup);
6168 : 140 : break;
6169 : : }
6170 : :
6171 : 176 : case PropgraphLabelRelationId:
6172 : : {
6173 : : HeapTuple tup;
6174 : : Form_pg_propgraph_label pgl;
6175 : :
40 6176 : 176 : tup = SearchSysCache1(PROPGRAPHLABELOID, ObjectIdGetDatum(object->objectId));
75 6177 [ + + ]: 176 : if (!HeapTupleIsValid(tup))
6178 : : {
6179 [ - + ]: 8 : if (!missing_ok)
75 peter@eisentraut.org 6180 [ # # ]:UNC 0 : elog(ERROR, "cache lookup failed for property graph label %u", object->objectId);
75 peter@eisentraut.org 6181 :GNC 8 : break;
6182 : : }
6183 : :
6184 : 168 : pgl = (Form_pg_propgraph_label) GETSTRUCT(tup);
6185 : 168 : appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pgl->pgllabel)));
6186 : 168 : getRelationIdentity(&buffer, pgl->pglpgid, objname, false);
6187 [ + + ]: 168 : if (objname)
6188 : 72 : *objname = lappend(*objname, pstrdup(NameStr(pgl->pgllabel)));
6189 : 168 : ReleaseSysCache(tup);
6190 : 168 : break;
6191 : : }
6192 : :
6193 : 260 : case PropgraphPropertyRelationId:
6194 : : {
6195 : : HeapTuple tup;
6196 : : Form_pg_propgraph_property pgp;
6197 : :
40 6198 : 260 : tup = SearchSysCache1(PROPGRAPHPROPOID, ObjectIdGetDatum(object->objectId));
75 6199 [ + + ]: 260 : if (!HeapTupleIsValid(tup))
6200 : : {
6201 [ - + ]: 8 : if (!missing_ok)
75 peter@eisentraut.org 6202 [ # # ]:UNC 0 : elog(ERROR, "cache lookup failed for property graph property %u", object->objectId);
75 peter@eisentraut.org 6203 :GNC 8 : break;
6204 : : }
6205 : :
6206 : 252 : pgp = (Form_pg_propgraph_property) GETSTRUCT(tup);
6207 : 252 : appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pgp->pgpname)));
6208 : 252 : getRelationIdentity(&buffer, pgp->pgppgid, objname, false);
6209 [ + + ]: 252 : if (objname)
6210 : 108 : *objname = lappend(*objname, pstrdup(NameStr(pgp->pgpname)));
6211 : 252 : ReleaseSysCache(tup);
6212 : 252 : break;
6213 : : }
6214 : :
795 peter@eisentraut.org 6215 :CBC 36 : case PublicationRelationId:
6216 : : {
6217 : : char *pubname;
6218 : :
2145 michael@paquier.xyz 6219 : 36 : pubname = get_publication_name(object->objectId, missing_ok);
6220 [ + + ]: 36 : if (pubname)
6221 : : {
6222 : 28 : appendStringInfoString(&buffer,
6223 : : quote_identifier(pubname));
6224 [ + + ]: 28 : if (objname)
6225 : 4 : *objname = list_make1(pubname);
6226 : : }
3418 peter_e@gmx.net 6227 : 36 : break;
6228 : : }
6229 : :
795 peter@eisentraut.org 6230 : 36 : case PublicationNamespaceRelationId:
6231 : : {
6232 : : char *pubname;
6233 : : char *nspname;
6234 : :
1676 akapila@postgresql.o 6235 [ + + ]: 36 : if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
6236 : : &nspname))
6237 : 8 : break;
1514 tomas.vondra@postgre 6238 : 28 : appendStringInfo(&buffer, "%s in publication %s",
6239 : : nspname, pubname);
6240 : :
1676 akapila@postgresql.o 6241 [ + + ]: 28 : if (objargs)
6242 : 4 : *objargs = list_make1(pubname);
6243 : : else
6244 : 24 : pfree(pubname);
6245 : :
6246 [ + + ]: 28 : if (objname)
6247 : 4 : *objname = list_make1(nspname);
6248 : : else
6249 : 24 : pfree(nspname);
6250 : :
6251 : 28 : break;
6252 : : }
6253 : :
795 peter@eisentraut.org 6254 : 36 : case PublicationRelRelationId:
6255 : : {
6256 : : HeapTuple tup;
6257 : : char *pubname;
6258 : : Form_pg_publication_rel prform;
6259 : :
3418 peter_e@gmx.net 6260 : 36 : tup = SearchSysCache1(PUBLICATIONREL,
6261 : 36 : ObjectIdGetDatum(object->objectId));
6262 [ + + ]: 36 : if (!HeapTupleIsValid(tup))
6263 : : {
2145 michael@paquier.xyz 6264 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 6265 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for publication table %u",
6266 : : object->objectId);
2145 michael@paquier.xyz 6267 :CBC 8 : break;
6268 : : }
6269 : :
3418 peter_e@gmx.net 6270 : 28 : prform = (Form_pg_publication_rel) GETSTRUCT(tup);
2811 michael@paquier.xyz 6271 : 28 : pubname = get_publication_name(prform->prpubid, false);
6272 : :
2145 6273 : 28 : getRelationIdentity(&buffer, prform->prrelid, objname, false);
2928 tgl@sss.pgh.pa.us 6274 : 28 : appendStringInfo(&buffer, " in publication %s", pubname);
6275 : :
6276 [ + + ]: 28 : if (objargs)
3418 peter_e@gmx.net 6277 : 4 : *objargs = list_make1(pubname);
6278 : :
6279 : 28 : ReleaseSysCache(tup);
6280 : 28 : break;
6281 : : }
6282 : :
795 peter@eisentraut.org 6283 : 36 : case SubscriptionRelationId:
6284 : : {
6285 : : char *subname;
6286 : :
2145 michael@paquier.xyz 6287 : 36 : subname = get_subscription_name(object->objectId, missing_ok);
6288 [ + + ]: 36 : if (subname)
6289 : : {
6290 : 28 : appendStringInfoString(&buffer,
6291 : : quote_identifier(subname));
6292 [ + + ]: 28 : if (objname)
6293 : 4 : *objname = list_make1(subname);
6294 : : }
3418 peter_e@gmx.net 6295 : 36 : break;
6296 : : }
6297 : :
795 peter@eisentraut.org 6298 : 38 : case TransformRelationId:
6299 : : {
6300 : : Relation transformDesc;
6301 : : HeapTuple tup;
6302 : : Form_pg_transform transform;
6303 : : char *transformLang;
6304 : : char *transformType;
6305 : :
2686 andres@anarazel.de 6306 : 38 : transformDesc = table_open(TransformRelationId, AccessShareLock);
6307 : :
2748 6308 : 38 : tup = get_catalog_object_by_oid(transformDesc,
6309 : : Anum_pg_transform_oid,
6310 : 38 : object->objectId);
6311 : :
3354 alvherre@alvh.no-ip. 6312 [ + + ]: 38 : if (!HeapTupleIsValid(tup))
6313 : : {
2145 michael@paquier.xyz 6314 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 6315 [ # # ]:UBC 0 : elog(ERROR, "could not find tuple for transform %u",
6316 : : object->objectId);
6317 : :
2145 michael@paquier.xyz 6318 :CBC 8 : table_close(transformDesc, AccessShareLock);
6319 : 8 : break;
6320 : : }
6321 : :
3303 tgl@sss.pgh.pa.us 6322 : 30 : transform = (Form_pg_transform) GETSTRUCT(tup);
6323 : :
6324 : 30 : transformType = format_type_be_qualified(transform->trftype);
6325 : 30 : transformLang = get_language_name(transform->trflang, false);
6326 : :
1202 alvherre@alvh.no-ip. 6327 : 30 : appendStringInfo(&buffer, "for %s language %s",
6328 : : transformType,
6329 : : transformLang);
3354 6330 [ + + ]: 30 : if (objname)
6331 : : {
3303 tgl@sss.pgh.pa.us 6332 : 5 : *objname = list_make1(transformType);
6333 : 5 : *objargs = list_make1(pstrdup(transformLang));
6334 : : }
6335 : :
2686 andres@anarazel.de 6336 : 30 : table_close(transformDesc, AccessShareLock);
6337 : : }
3354 alvherre@alvh.no-ip. 6338 : 30 : break;
6339 : :
795 peter@eisentraut.org 6340 :UBC 0 : default:
6341 [ # # ]: 0 : elog(ERROR, "unsupported object class: %u", object->classId);
6342 : : }
6343 : :
2145 michael@paquier.xyz 6344 [ + + ]:CBC 5866 : if (!missing_ok)
6345 : : {
6346 : : /*
6347 : : * If a get_object_address() representation was requested, make sure
6348 : : * we are providing one. We don't check objargs, because many of the
6349 : : * cases above leave it as NIL.
6350 : : */
6351 [ + + - + ]: 3067 : if (objname && *objname == NIL)
795 peter@eisentraut.org 6352 [ # # ]:UBC 0 : elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"",
6353 : : object->classId, buffer.data);
6354 : : }
6355 : : else
6356 : : {
6357 : : /* an empty buffer is equivalent to no object found */
2145 michael@paquier.xyz 6358 [ + + ]:CBC 2799 : if (buffer.len == 0)
6359 : : {
6360 [ + + + - : 364 : Assert((objname == NULL || *objname == NIL) &&
+ + - + ]
6361 : : (objargs == NULL || *objargs == NIL));
6362 : 364 : return NULL;
6363 : : }
6364 : : }
6365 : :
4819 alvherre@alvh.no-ip. 6366 : 5502 : return buffer.data;
6367 : : }
6368 : :
6369 : : static void
2145 michael@paquier.xyz 6370 : 98 : getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object,
6371 : : bool missing_ok)
6372 : : {
6373 : : HeapTuple opfTup;
6374 : : Form_pg_opfamily opfForm;
6375 : : HeapTuple amTup;
6376 : : Form_pg_am amForm;
6377 : : char *schema;
6378 : :
4819 alvherre@alvh.no-ip. 6379 : 98 : opfTup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfid));
6380 [ + + ]: 98 : if (!HeapTupleIsValid(opfTup))
6381 : : {
2145 michael@paquier.xyz 6382 [ - + ]: 8 : if (!missing_ok)
2145 michael@paquier.xyz 6383 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for opfamily %u", opfid);
2145 michael@paquier.xyz 6384 :CBC 8 : return;
6385 : : }
4819 alvherre@alvh.no-ip. 6386 : 90 : opfForm = (Form_pg_opfamily) GETSTRUCT(opfTup);
6387 : :
6388 : 90 : amTup = SearchSysCache1(AMOID, ObjectIdGetDatum(opfForm->opfmethod));
6389 [ - + ]: 90 : if (!HeapTupleIsValid(amTup))
4819 alvherre@alvh.no-ip. 6390 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for access method %u",
6391 : : opfForm->opfmethod);
4819 alvherre@alvh.no-ip. 6392 :CBC 90 : amForm = (Form_pg_am) GETSTRUCT(amTup);
6393 : :
4072 6394 : 90 : schema = get_namespace_name_or_temp(opfForm->opfnamespace);
4119 6395 : 90 : appendStringInfo(buffer, "%s USING %s",
6396 : : quote_qualified_identifier(schema,
4819 6397 : 90 : NameStr(opfForm->opfname)),
6398 : 90 : NameStr(amForm->amname));
6399 : :
3486 peter_e@gmx.net 6400 [ + + ]: 90 : if (object)
6401 : 12 : *object = list_make3(pstrdup(NameStr(amForm->amname)),
6402 : : pstrdup(schema),
6403 : : pstrdup(NameStr(opfForm->opfname)));
6404 : :
4819 alvherre@alvh.no-ip. 6405 : 90 : ReleaseSysCache(amTup);
6406 : 90 : ReleaseSysCache(opfTup);
6407 : : }
6408 : :
6409 : : /*
6410 : : * Append the relation identity (quoted qualified name) to the given
6411 : : * StringInfo.
6412 : : */
6413 : : static void
2145 michael@paquier.xyz 6414 : 2993 : getRelationIdentity(StringInfo buffer, Oid relid, List **object,
6415 : : bool missing_ok)
6416 : : {
6417 : : HeapTuple relTup;
6418 : : Form_pg_class relForm;
6419 : : char *schema;
6420 : :
4819 alvherre@alvh.no-ip. 6421 : 2993 : relTup = SearchSysCache1(RELOID,
6422 : : ObjectIdGetDatum(relid));
6423 [ + + ]: 2993 : if (!HeapTupleIsValid(relTup))
6424 : : {
2145 michael@paquier.xyz 6425 [ - + ]: 12 : if (!missing_ok)
2145 michael@paquier.xyz 6426 [ # # ]:UBC 0 : elog(ERROR, "cache lookup failed for relation %u", relid);
6427 : :
2145 michael@paquier.xyz 6428 [ + + ]:CBC 12 : if (object)
6429 : 4 : *object = NIL;
6430 : 12 : return;
6431 : : }
4819 alvherre@alvh.no-ip. 6432 : 2981 : relForm = (Form_pg_class) GETSTRUCT(relTup);
6433 : :
4072 6434 : 2981 : schema = get_namespace_name_or_temp(relForm->relnamespace);
4594 rhaas@postgresql.org 6435 : 2981 : appendStringInfoString(buffer,
4427 alvherre@alvh.no-ip. 6436 : 2981 : quote_qualified_identifier(schema,
3265 tgl@sss.pgh.pa.us 6437 : 2981 : NameStr(relForm->relname)));
3486 peter_e@gmx.net 6438 [ + + ]: 2981 : if (object)
6439 : 1937 : *object = list_make2(schema, pstrdup(NameStr(relForm->relname)));
6440 : :
4819 alvherre@alvh.no-ip. 6441 : 2981 : ReleaseSysCache(relTup);
6442 : : }
6443 : :
6444 : : /*
6445 : : * Auxiliary function to build a TEXT array out of a list of C-strings.
6446 : : */
6447 : : ArrayType *
4169 6448 : 1439 : strlist_to_textarray(List *list)
6449 : : {
6450 : : ArrayType *arr;
6451 : : Datum *datums;
6452 : : bool *nulls;
4025 bruce@momjian.us 6453 : 1439 : int j = 0;
6454 : : ListCell *cell;
6455 : : MemoryContext memcxt;
6456 : : MemoryContext oldcxt;
6457 : : int lb[1];
6458 : :
6459 : : /* Work in a temp context; easier than individually pfree'ing the Datums */
4169 alvherre@alvh.no-ip. 6460 : 1439 : memcxt = AllocSetContextCreate(CurrentMemoryContext,
6461 : : "strlist to array",
6462 : : ALLOCSET_DEFAULT_SIZES);
6463 : 1439 : oldcxt = MemoryContextSwitchTo(memcxt);
6464 : :
171 michael@paquier.xyz 6465 :GNC 1439 : datums = palloc_array(Datum, list_length(list));
6466 : 1439 : nulls = palloc_array(bool, list_length(list));
6467 : :
4169 alvherre@alvh.no-ip. 6468 [ + - + + :CBC 4218 : foreach(cell, list)
+ + ]
6469 : : {
4025 bruce@momjian.us 6470 : 2779 : char *name = lfirst(cell);
6471 : :
2656 alvherre@alvh.no-ip. 6472 [ + - ]: 2779 : if (name)
6473 : : {
6474 : 2779 : nulls[j] = false;
6475 : 2779 : datums[j++] = CStringGetTextDatum(name);
6476 : : }
6477 : : else
2656 alvherre@alvh.no-ip. 6478 :UBC 0 : nulls[j] = true;
6479 : : }
6480 : :
4169 alvherre@alvh.no-ip. 6481 :CBC 1439 : MemoryContextSwitchTo(oldcxt);
6482 : :
2656 6483 : 1439 : lb[0] = 1;
6484 : 1439 : arr = construct_md_array(datums, nulls, 1, &j,
6485 : : lb, TEXTOID, -1, false, TYPALIGN_INT);
6486 : :
4169 6487 : 1439 : MemoryContextDelete(memcxt);
6488 : :
6489 : 1439 : return arr;
6490 : : }
6491 : :
6492 : : /*
6493 : : * get_relkind_objtype
6494 : : *
6495 : : * Return the object type for the relkind given by the caller.
6496 : : *
6497 : : * If an unexpected relkind is passed, we say OBJECT_TABLE rather than
6498 : : * failing. That's because this is mostly used for generating error messages
6499 : : * for failed ACL checks on relations, and we'd rather produce a generic
6500 : : * message saying "table" than fail entirely.
6501 : : */
6502 : : ObjectType
3101 peter_e@gmx.net 6503 : 1112 : get_relkind_objtype(char relkind)
6504 : : {
6505 [ + + + + : 1112 : switch (relkind)
+ + + - ]
[ + + + +
+ + + +
- ]
6506 : : {
6507 : 1034 : case RELKIND_RELATION:
6508 : : case RELKIND_PARTITIONED_TABLE:
6509 : 1034 : return OBJECT_TABLE;
6510 : 17 : case RELKIND_INDEX:
6511 : : case RELKIND_PARTITIONED_INDEX:
6512 : 17 : return OBJECT_INDEX;
6513 : 4 : case RELKIND_SEQUENCE:
6514 : 4 : return OBJECT_SEQUENCE;
6515 : 24 : case RELKIND_VIEW:
6516 : 24 : return OBJECT_VIEW;
6517 : 4 : case RELKIND_MATVIEW:
6518 : 4 : return OBJECT_MATVIEW;
6519 : 1 : case RELKIND_FOREIGN_TABLE:
6520 : 1 : return OBJECT_FOREIGN_TABLE;
75 peter@eisentraut.org 6521 :GNC 20 : case RELKIND_PROPGRAPH:
6522 : 20 : return OBJECT_PROPGRAPH;
2398 tgl@sss.pgh.pa.us 6523 :CBC 8 : case RELKIND_TOASTVALUE:
6524 : 8 : return OBJECT_TABLE;
3101 peter_e@gmx.net 6525 :UBC 0 : default:
6526 : : /* Per above, don't raise an error */
2398 tgl@sss.pgh.pa.us 6527 : 0 : return OBJECT_TABLE;
6528 : : }
6529 : : }
|