Skip to content

Commit 8f2143b

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 09fb2d5 commit 8f2143b

File tree

3 files changed

+80
-16
lines changed

3 files changed

+80
-16
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,15 +1590,24 @@ getObjectDescription(const ObjectAddress *object)
15901590
{
15911591
HeapTuple collTup;
15921592
Form_pg_collation coll;
1593+
char *nspname;
15931594

15941595
collTup = SearchSysCache1(COLLOID,
15951596
ObjectIdGetDatum(object->objectId));
15961597
if (!HeapTupleIsValid(collTup))
15971598
elog(ERROR, "cache lookup failed for collation %u",
15981599
object->objectId);
15991600
coll = (Form_pg_collation) GETSTRUCT(collTup);
1601+
1602+
/* Qualify the name if not visible in search path */
1603+
if (CollationIsVisible(object->objectId))
1604+
nspname = NULL;
1605+
else
1606+
nspname = get_namespace_name(coll->collnamespace);
1607+
16001608
appendStringInfo(&buffer, _("collation %s"),
1601-
NameStr(coll->collname));
1609+
quote_qualified_identifier(nspname,
1610+
NameStr(coll->collname)));
16021611
ReleaseSysCache(collTup);
16031612
break;
16041613
}
@@ -1638,14 +1647,25 @@ getObjectDescription(const ObjectAddress *object)
16381647
case OCLASS_CONVERSION:
16391648
{
16401649
HeapTuple conTup;
1650+
Form_pg_conversion conv;
1651+
char *nspname;
16411652

16421653
conTup = SearchSysCache1(CONVOID,
16431654
ObjectIdGetDatum(object->objectId));
16441655
if (!HeapTupleIsValid(conTup))
16451656
elog(ERROR, "cache lookup failed for conversion %u",
16461657
object->objectId);
1658+
conv = (Form_pg_conversion) GETSTRUCT(conTup);
1659+
1660+
/* Qualify the name if not visible in search path */
1661+
if (ConversionIsVisible(object->objectId))
1662+
nspname = NULL;
1663+
else
1664+
nspname = get_namespace_name(conv->connamespace);
1665+
16471666
appendStringInfo(&buffer, _("conversion %s"),
1648-
NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
1667+
quote_qualified_identifier(nspname,
1668+
NameStr(conv->conname)));
16491669
ReleaseSysCache(conTup);
16501670
break;
16511671
}
@@ -1940,59 +1960,103 @@ getObjectDescription(const ObjectAddress *object)
19401960
case OCLASS_TSPARSER:
19411961
{
19421962
HeapTuple tup;
1963+
Form_pg_ts_parser prsForm;
1964+
char *nspname;
19431965

19441966
tup = SearchSysCache1(TSPARSEROID,
19451967
ObjectIdGetDatum(object->objectId));
19461968
if (!HeapTupleIsValid(tup))
19471969
elog(ERROR, "cache lookup failed for text search parser %u",
19481970
object->objectId);
1971+
prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
1972+
1973+
/* Qualify the name if not visible in search path */
1974+
if (TSParserIsVisible(object->objectId))
1975+
nspname = NULL;
1976+
else
1977+
nspname = get_namespace_name(prsForm->prsnamespace);
1978+
19491979
appendStringInfo(&buffer, _("text search parser %s"),
1950-
NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
1980+
quote_qualified_identifier(nspname,
1981+
NameStr(prsForm->prsname)));
19511982
ReleaseSysCache(tup);
19521983
break;
19531984
}
19541985

19551986
case OCLASS_TSDICT:
19561987
{
19571988
HeapTuple tup;
1989+
Form_pg_ts_dict dictForm;
1990+
char *nspname;
19581991

19591992
tup = SearchSysCache1(TSDICTOID,
19601993
ObjectIdGetDatum(object->objectId));
19611994
if (!HeapTupleIsValid(tup))
19621995
elog(ERROR, "cache lookup failed for text search dictionary %u",
19631996
object->objectId);
1997+
dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
1998+
1999+
/* Qualify the name if not visible in search path */
2000+
if (TSDictionaryIsVisible(object->objectId))
2001+
nspname = NULL;
2002+
else
2003+
nspname = get_namespace_name(dictForm->dictnamespace);
2004+
19642005
appendStringInfo(&buffer, _("text search dictionary %s"),
1965-
NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
2006+
quote_qualified_identifier(nspname,
2007+
NameStr(dictForm->dictname)));
19662008
ReleaseSysCache(tup);
19672009
break;
19682010
}
19692011

19702012
case OCLASS_TSTEMPLATE:
19712013
{
19722014
HeapTuple tup;
2015+
Form_pg_ts_template tmplForm;
2016+
char *nspname;
19732017

19742018
tup = SearchSysCache1(TSTEMPLATEOID,
19752019
ObjectIdGetDatum(object->objectId));
19762020
if (!HeapTupleIsValid(tup))
19772021
elog(ERROR, "cache lookup failed for text search template %u",
19782022
object->objectId);
2023+
tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
2024+
2025+
/* Qualify the name if not visible in search path */
2026+
if (TSTemplateIsVisible(object->objectId))
2027+
nspname = NULL;
2028+
else
2029+
nspname = get_namespace_name(tmplForm->tmplnamespace);
2030+
19792031
appendStringInfo(&buffer, _("text search template %s"),
1980-
NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
2032+
quote_qualified_identifier(nspname,
2033+
NameStr(tmplForm->tmplname)));
19812034
ReleaseSysCache(tup);
19822035
break;
19832036
}
19842037

19852038
case OCLASS_TSCONFIG:
19862039
{
19872040
HeapTuple tup;
2041+
Form_pg_ts_config cfgForm;
2042+
char *nspname;
19882043

19892044
tup = SearchSysCache1(TSCONFIGOID,
19902045
ObjectIdGetDatum(object->objectId));
19912046
if (!HeapTupleIsValid(tup))
19922047
elog(ERROR, "cache lookup failed for text search configuration %u",
19932048
object->objectId);
2049+
cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
2050+
2051+
/* Qualify the name if not visible in search path */
2052+
if (TSConfigIsVisible(object->objectId))
2053+
nspname = NULL;
2054+
else
2055+
nspname = get_namespace_name(cfgForm->cfgnamespace);
2056+
19942057
appendStringInfo(&buffer, _("text search configuration %s"),
1995-
NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
2058+
quote_qualified_identifier(nspname,
2059+
NameStr(cfgForm->cfgname)));
19962060
ReleaseSysCache(tup);
19972061
break;
19982062
}

src/test/regress/expected/alter_generic.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,13 @@ DROP SCHEMA alt_nsp2 CASCADE;
669669
NOTICE: drop cascades to 9 other objects
670670
DETAIL: drop cascades to function alt_nsp2.alt_func2(integer)
671671
drop cascades to function alt_nsp2.alt_agg2(integer)
672-
drop cascades to conversion alt_conv2
672+
drop cascades to conversion alt_nsp2.alt_conv2
673673
drop cascades to operator alt_nsp2.@-@(integer,integer)
674674
drop cascades to operator family alt_nsp2.alt_opf2 for access method hash
675-
drop cascades to text search dictionary alt_ts_dict2
676-
drop cascades to text search configuration alt_ts_conf2
677-
drop cascades to text search template alt_ts_temp2
678-
drop cascades to text search parser alt_ts_prs2
675+
drop cascades to text search dictionary alt_nsp2.alt_ts_dict2
676+
drop cascades to text search configuration alt_nsp2.alt_ts_conf2
677+
drop cascades to text search template alt_nsp2.alt_ts_temp2
678+
drop cascades to text search parser alt_nsp2.alt_ts_prs2
679679
DROP USER regtest_alter_user1;
680680
DROP USER regtest_alter_user2;
681681
DROP USER regtest_alter_user3;

src/test/regress/expected/alter_table.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,11 +2470,11 @@ drop cascades to operator family alter2.ctype_hash_ops for access method hash
24702470
drop cascades to type alter2.ctype
24712471
drop cascades to function alter2.same(alter2.ctype,alter2.ctype)
24722472
drop cascades to operator alter2.=(alter2.ctype,alter2.ctype)
2473-
drop cascades to conversion ascii_to_utf8
2474-
drop cascades to text search parser prs
2475-
drop cascades to text search configuration cfg
2476-
drop cascades to text search template tmpl
2477-
drop cascades to text search dictionary dict
2473+
drop cascades to conversion alter2.ascii_to_utf8
2474+
drop cascades to text search parser alter2.prs
2475+
drop cascades to text search configuration alter2.cfg
2476+
drop cascades to text search template alter2.tmpl
2477+
drop cascades to text search dictionary alter2.dict
24782478
--
24792479
-- composite types
24802480
--

0 commit comments

Comments
 (0)