Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3d31652

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 bbaf75e commit 3d31652

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
@@ -2552,15 +2552,24 @@ getObjectDescription(const ObjectAddress *object)
25522552
{
25532553
HeapTuple collTup;
25542554
Form_pg_collation coll;
2555+
char *nspname;
25552556

25562557
collTup = SearchSysCache1(COLLOID,
25572558
ObjectIdGetDatum(object->objectId));
25582559
if (!HeapTupleIsValid(collTup))
25592560
elog(ERROR, "cache lookup failed for collation %u",
25602561
object->objectId);
25612562
coll = (Form_pg_collation) GETSTRUCT(collTup);
2563+
2564+
/* Qualify the name if not visible in search path */
2565+
if (CollationIsVisible(object->objectId))
2566+
nspname = NULL;
2567+
else
2568+
nspname = get_namespace_name(coll->collnamespace);
2569+
25622570
appendStringInfo(&buffer, _("collation %s"),
2563-
NameStr(coll->collname));
2571+
quote_qualified_identifier(nspname,
2572+
NameStr(coll->collname)));
25642573
ReleaseSysCache(collTup);
25652574
break;
25662575
}
@@ -2600,14 +2609,25 @@ getObjectDescription(const ObjectAddress *object)
26002609
case OCLASS_CONVERSION:
26012610
{
26022611
HeapTuple conTup;
2612+
Form_pg_conversion conv;
2613+
char *nspname;
26032614

26042615
conTup = SearchSysCache1(CONVOID,
26052616
ObjectIdGetDatum(object->objectId));
26062617
if (!HeapTupleIsValid(conTup))
26072618
elog(ERROR, "cache lookup failed for conversion %u",
26082619
object->objectId);
2620+
conv = (Form_pg_conversion) GETSTRUCT(conTup);
2621+
2622+
/* Qualify the name if not visible in search path */
2623+
if (ConversionIsVisible(object->objectId))
2624+
nspname = NULL;
2625+
else
2626+
nspname = get_namespace_name(conv->connamespace);
2627+
26092628
appendStringInfo(&buffer, _("conversion %s"),
2610-
NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2629+
quote_qualified_identifier(nspname,
2630+
NameStr(conv->conname)));
26112631
ReleaseSysCache(conTup);
26122632
break;
26132633
}
@@ -2914,59 +2934,103 @@ getObjectDescription(const ObjectAddress *object)
29142934
case OCLASS_TSPARSER:
29152935
{
29162936
HeapTuple tup;
2937+
Form_pg_ts_parser prsForm;
2938+
char *nspname;
29172939

29182940
tup = SearchSysCache1(TSPARSEROID,
29192941
ObjectIdGetDatum(object->objectId));
29202942
if (!HeapTupleIsValid(tup))
29212943
elog(ERROR, "cache lookup failed for text search parser %u",
29222944
object->objectId);
2945+
prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
2946+
2947+
/* Qualify the name if not visible in search path */
2948+
if (TSParserIsVisible(object->objectId))
2949+
nspname = NULL;
2950+
else
2951+
nspname = get_namespace_name(prsForm->prsnamespace);
2952+
29232953
appendStringInfo(&buffer, _("text search parser %s"),
2924-
NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
2954+
quote_qualified_identifier(nspname,
2955+
NameStr(prsForm->prsname)));
29252956
ReleaseSysCache(tup);
29262957
break;
29272958
}
29282959

29292960
case OCLASS_TSDICT:
29302961
{
29312962
HeapTuple tup;
2963+
Form_pg_ts_dict dictForm;
2964+
char *nspname;
29322965

29332966
tup = SearchSysCache1(TSDICTOID,
29342967
ObjectIdGetDatum(object->objectId));
29352968
if (!HeapTupleIsValid(tup))
29362969
elog(ERROR, "cache lookup failed for text search dictionary %u",
29372970
object->objectId);
2971+
dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
2972+
2973+
/* Qualify the name if not visible in search path */
2974+
if (TSDictionaryIsVisible(object->objectId))
2975+
nspname = NULL;
2976+
else
2977+
nspname = get_namespace_name(dictForm->dictnamespace);
2978+
29382979
appendStringInfo(&buffer, _("text search dictionary %s"),
2939-
NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
2980+
quote_qualified_identifier(nspname,
2981+
NameStr(dictForm->dictname)));
29402982
ReleaseSysCache(tup);
29412983
break;
29422984
}
29432985

29442986
case OCLASS_TSTEMPLATE:
29452987
{
29462988
HeapTuple tup;
2989+
Form_pg_ts_template tmplForm;
2990+
char *nspname;
29472991

29482992
tup = SearchSysCache1(TSTEMPLATEOID,
29492993
ObjectIdGetDatum(object->objectId));
29502994
if (!HeapTupleIsValid(tup))
29512995
elog(ERROR, "cache lookup failed for text search template %u",
29522996
object->objectId);
2997+
tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
2998+
2999+
/* Qualify the name if not visible in search path */
3000+
if (TSTemplateIsVisible(object->objectId))
3001+
nspname = NULL;
3002+
else
3003+
nspname = get_namespace_name(tmplForm->tmplnamespace);
3004+
29533005
appendStringInfo(&buffer, _("text search template %s"),
2954-
NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
3006+
quote_qualified_identifier(nspname,
3007+
NameStr(tmplForm->tmplname)));
29553008
ReleaseSysCache(tup);
29563009
break;
29573010
}
29583011

29593012
case OCLASS_TSCONFIG:
29603013
{
29613014
HeapTuple tup;
3015+
Form_pg_ts_config cfgForm;
3016+
char *nspname;
29623017

29633018
tup = SearchSysCache1(TSCONFIGOID,
29643019
ObjectIdGetDatum(object->objectId));
29653020
if (!HeapTupleIsValid(tup))
29663021
elog(ERROR, "cache lookup failed for text search configuration %u",
29673022
object->objectId);
3023+
cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3024+
3025+
/* Qualify the name if not visible in search path */
3026+
if (TSConfigIsVisible(object->objectId))
3027+
nspname = NULL;
3028+
else
3029+
nspname = get_namespace_name(cfgForm->cfgnamespace);
3030+
29683031
appendStringInfo(&buffer, _("text search configuration %s"),
2969-
NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
3032+
quote_qualified_identifier(nspname,
3033+
NameStr(cfgForm->cfgname)));
29703034
ReleaseSysCache(tup);
29713035
break;
29723036
}

src/test/regress/expected/alter_generic.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,13 @@ DROP SCHEMA alt_nsp2 CASCADE;
670670
NOTICE: drop cascades to 9 other objects
671671
DETAIL: drop cascades to function alt_nsp2.alt_func2(integer)
672672
drop cascades to function alt_nsp2.alt_agg2(integer)
673-
drop cascades to conversion alt_conv2
673+
drop cascades to conversion alt_nsp2.alt_conv2
674674
drop cascades to operator alt_nsp2.@-@(integer,integer)
675675
drop cascades to operator family alt_nsp2.alt_opf2 for access method hash
676-
drop cascades to text search dictionary alt_ts_dict2
677-
drop cascades to text search configuration alt_ts_conf2
678-
drop cascades to text search template alt_ts_temp2
679-
drop cascades to text search parser alt_ts_prs2
676+
drop cascades to text search dictionary alt_nsp2.alt_ts_dict2
677+
drop cascades to text search configuration alt_nsp2.alt_ts_conf2
678+
drop cascades to text search template alt_nsp2.alt_ts_temp2
679+
drop cascades to text search parser alt_nsp2.alt_ts_prs2
680680
DROP USER regress_alter_user1;
681681
DROP USER regress_alter_user2;
682682
DROP USER regress_alter_user3;

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)