Skip to content

Commit eb1aa1b

Browse files
committed
Properly schema-qualify additional object types in getObjectDescription().
Collations, conversions, extended statistics objects (in >= v10), and all four types of text search objects have schema-qualified names. getObjectDescription() ignored that and would emit just the base name of the object, potentially producing wrong or at least highly misleading output. Fix it to add the schema name whenever the object is not "visible" in the current search path, as is the rule for other schema-qualifiable object types. Although in common situations the output won't change, this seems to me (tgl) to be a bug worthy of back-patching, hence do so. Kyotaro Horiguchi, per a complaint from me Discussion: https://postgr.es/m/20180522.182020.114074746.horiguchi.kyotaro@lab.ntt.co.jp
1 parent bed74e9 commit eb1aa1b

File tree

2 files changed

+84
-13
lines changed

2 files changed

+84
-13
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,15 +2717,24 @@ getObjectDescription(const ObjectAddress *object)
27172717
{
27182718
HeapTuple collTup;
27192719
Form_pg_collation coll;
2720+
char *nspname;
27202721

27212722
collTup = SearchSysCache1(COLLOID,
27222723
ObjectIdGetDatum(object->objectId));
27232724
if (!HeapTupleIsValid(collTup))
27242725
elog(ERROR, "cache lookup failed for collation %u",
27252726
object->objectId);
27262727
coll = (Form_pg_collation) GETSTRUCT(collTup);
2728+
2729+
/* Qualify the name if not visible in search path */
2730+
if (CollationIsVisible(object->objectId))
2731+
nspname = NULL;
2732+
else
2733+
nspname = get_namespace_name(coll->collnamespace);
2734+
27272735
appendStringInfo(&buffer, _("collation %s"),
2728-
NameStr(coll->collname));
2736+
quote_qualified_identifier(nspname,
2737+
NameStr(coll->collname)));
27292738
ReleaseSysCache(collTup);
27302739
break;
27312740
}
@@ -2765,14 +2774,25 @@ getObjectDescription(const ObjectAddress *object)
27652774
case OCLASS_CONVERSION:
27662775
{
27672776
HeapTuple conTup;
2777+
Form_pg_conversion conv;
2778+
char *nspname;
27682779

27692780
conTup = SearchSysCache1(CONVOID,
27702781
ObjectIdGetDatum(object->objectId));
27712782
if (!HeapTupleIsValid(conTup))
27722783
elog(ERROR, "cache lookup failed for conversion %u",
27732784
object->objectId);
2785+
conv = (Form_pg_conversion) GETSTRUCT(conTup);
2786+
2787+
/* Qualify the name if not visible in search path */
2788+
if (ConversionIsVisible(object->objectId))
2789+
nspname = NULL;
2790+
else
2791+
nspname = get_namespace_name(conv->connamespace);
2792+
27742793
appendStringInfo(&buffer, _("conversion %s"),
2775-
NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2794+
quote_qualified_identifier(nspname,
2795+
NameStr(conv->conname)));
27762796
ReleaseSysCache(conTup);
27772797
break;
27782798
}
@@ -3074,17 +3094,24 @@ getObjectDescription(const ObjectAddress *object)
30743094
{
30753095
HeapTuple stxTup;
30763096
Form_pg_statistic_ext stxForm;
3097+
char *nspname;
30773098

30783099
stxTup = SearchSysCache1(STATEXTOID,
30793100
ObjectIdGetDatum(object->objectId));
30803101
if (!HeapTupleIsValid(stxTup))
30813102
elog(ERROR, "could not find tuple for statistics object %u",
30823103
object->objectId);
3083-
30843104
stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
30853105

3106+
/* Qualify the name if not visible in search path */
3107+
if (StatisticsObjIsVisible(object->objectId))
3108+
nspname = NULL;
3109+
else
3110+
nspname = get_namespace_name(stxForm->stxnamespace);
3111+
30863112
appendStringInfo(&buffer, _("statistics object %s"),
3087-
NameStr(stxForm->stxname));
3113+
quote_qualified_identifier(nspname,
3114+
NameStr(stxForm->stxname)));
30883115

30893116
ReleaseSysCache(stxTup);
30903117
break;
@@ -3093,59 +3120,103 @@ getObjectDescription(const ObjectAddress *object)
30933120
case OCLASS_TSPARSER:
30943121
{
30953122
HeapTuple tup;
3123+
Form_pg_ts_parser prsForm;
3124+
char *nspname;
30963125

30973126
tup = SearchSysCache1(TSPARSEROID,
30983127
ObjectIdGetDatum(object->objectId));
30993128
if (!HeapTupleIsValid(tup))
31003129
elog(ERROR, "cache lookup failed for text search parser %u",
31013130
object->objectId);
3131+
prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3132+
3133+
/* Qualify the name if not visible in search path */
3134+
if (TSParserIsVisible(object->objectId))
3135+
nspname = NULL;
3136+
else
3137+
nspname = get_namespace_name(prsForm->prsnamespace);
3138+
31023139
appendStringInfo(&buffer, _("text search parser %s"),
3103-
NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
3140+
quote_qualified_identifier(nspname,
3141+
NameStr(prsForm->prsname)));
31043142
ReleaseSysCache(tup);
31053143
break;
31063144
}
31073145

31083146
case OCLASS_TSDICT:
31093147
{
31103148
HeapTuple tup;
3149+
Form_pg_ts_dict dictForm;
3150+
char *nspname;
31113151

31123152
tup = SearchSysCache1(TSDICTOID,
31133153
ObjectIdGetDatum(object->objectId));
31143154
if (!HeapTupleIsValid(tup))
31153155
elog(ERROR, "cache lookup failed for text search dictionary %u",
31163156
object->objectId);
3157+
dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3158+
3159+
/* Qualify the name if not visible in search path */
3160+
if (TSDictionaryIsVisible(object->objectId))
3161+
nspname = NULL;
3162+
else
3163+
nspname = get_namespace_name(dictForm->dictnamespace);
3164+
31173165
appendStringInfo(&buffer, _("text search dictionary %s"),
3118-
NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
3166+
quote_qualified_identifier(nspname,
3167+
NameStr(dictForm->dictname)));
31193168
ReleaseSysCache(tup);
31203169
break;
31213170
}
31223171

31233172
case OCLASS_TSTEMPLATE:
31243173
{
31253174
HeapTuple tup;
3175+
Form_pg_ts_template tmplForm;
3176+
char *nspname;
31263177

31273178
tup = SearchSysCache1(TSTEMPLATEOID,
31283179
ObjectIdGetDatum(object->objectId));
31293180
if (!HeapTupleIsValid(tup))
31303181
elog(ERROR, "cache lookup failed for text search template %u",
31313182
object->objectId);
3183+
tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3184+
3185+
/* Qualify the name if not visible in search path */
3186+
if (TSTemplateIsVisible(object->objectId))
3187+
nspname = NULL;
3188+
else
3189+
nspname = get_namespace_name(tmplForm->tmplnamespace);
3190+
31323191
appendStringInfo(&buffer, _("text search template %s"),
3133-
NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
3192+
quote_qualified_identifier(nspname,
3193+
NameStr(tmplForm->tmplname)));
31343194
ReleaseSysCache(tup);
31353195
break;
31363196
}
31373197

31383198
case OCLASS_TSCONFIG:
31393199
{
31403200
HeapTuple tup;
3201+
Form_pg_ts_config cfgForm;
3202+
char *nspname;
31413203

31423204
tup = SearchSysCache1(TSCONFIGOID,
31433205
ObjectIdGetDatum(object->objectId));
31443206
if (!HeapTupleIsValid(tup))
31453207
elog(ERROR, "cache lookup failed for text search configuration %u",
31463208
object->objectId);
3209+
cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3210+
3211+
/* Qualify the name if not visible in search path */
3212+
if (TSConfigIsVisible(object->objectId))
3213+
nspname = NULL;
3214+
else
3215+
nspname = get_namespace_name(cfgForm->cfgnamespace);
3216+
31473217
appendStringInfo(&buffer, _("text search configuration %s"),
3148-
NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
3218+
quote_qualified_identifier(nspname,
3219+
NameStr(cfgForm->cfgname)));
31493220
ReleaseSysCache(tup);
31503221
break;
31513222
}

src/test/regress/expected/alter_table.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,11 +2580,11 @@ drop cascades to operator family alter2.ctype_hash_ops for access method hash
25802580
drop cascades to type alter2.ctype
25812581
drop cascades to function alter2.same(alter2.ctype,alter2.ctype)
25822582
drop cascades to operator alter2.=(alter2.ctype,alter2.ctype)
2583-
drop cascades to conversion ascii_to_utf8
2584-
drop cascades to text search parser prs
2585-
drop cascades to text search configuration cfg
2586-
drop cascades to text search template tmpl
2587-
drop cascades to text search dictionary dict
2583+
drop cascades to conversion alter2.ascii_to_utf8
2584+
drop cascades to text search parser alter2.prs
2585+
drop cascades to text search configuration alter2.cfg
2586+
drop cascades to text search template alter2.tmpl
2587+
drop cascades to text search dictionary alter2.dict
25882588
--
25892589
-- composite types
25902590
--

0 commit comments

Comments
 (0)