]> granicus.if.org Git - postgresql/commitdiff
Properly schema-qualify additional object types in getObjectDescription().
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 May 2018 16:07:41 +0000 (12:07 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 May 2018 16:07:41 +0000 (12:07 -0400)
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

src/backend/catalog/objectaddress.c
src/test/regress/expected/alter_table.out

index 6cac2dfd1db6ced3006ca8525100e059cfca1c95..270c685333529c1fe333d6e78195d5ab9c93e409 100644 (file)
@@ -2717,6 +2717,7 @@ getObjectDescription(const ObjectAddress *object)
                        {
                                HeapTuple       collTup;
                                Form_pg_collation coll;
+                               char       *nspname;
 
                                collTup = SearchSysCache1(COLLOID,
                                                                                  ObjectIdGetDatum(object->objectId));
@@ -2724,8 +2725,16 @@ getObjectDescription(const ObjectAddress *object)
                                        elog(ERROR, "cache lookup failed for collation %u",
                                                 object->objectId);
                                coll = (Form_pg_collation) GETSTRUCT(collTup);
+
+                               /* Qualify the name if not visible in search path */
+                               if (CollationIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(coll->collnamespace);
+
                                appendStringInfo(&buffer, _("collation %s"),
-                                                                NameStr(coll->collname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(coll->collname)));
                                ReleaseSysCache(collTup);
                                break;
                        }
@@ -2765,14 +2774,25 @@ getObjectDescription(const ObjectAddress *object)
                case OCLASS_CONVERSION:
                        {
                                HeapTuple       conTup;
+                               Form_pg_conversion conv;
+                               char       *nspname;
 
                                conTup = SearchSysCache1(CONVOID,
                                                                                 ObjectIdGetDatum(object->objectId));
                                if (!HeapTupleIsValid(conTup))
                                        elog(ERROR, "cache lookup failed for conversion %u",
                                                 object->objectId);
+                               conv = (Form_pg_conversion) GETSTRUCT(conTup);
+
+                               /* Qualify the name if not visible in search path */
+                               if (ConversionIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(conv->connamespace);
+
                                appendStringInfo(&buffer, _("conversion %s"),
-                                                                NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(conv->conname)));
                                ReleaseSysCache(conTup);
                                break;
                        }
@@ -3074,17 +3094,24 @@ getObjectDescription(const ObjectAddress *object)
                        {
                                HeapTuple       stxTup;
                                Form_pg_statistic_ext stxForm;
+                               char       *nspname;
 
                                stxTup = SearchSysCache1(STATEXTOID,
                                                                                 ObjectIdGetDatum(object->objectId));
                                if (!HeapTupleIsValid(stxTup))
                                        elog(ERROR, "could not find tuple for statistics object %u",
                                                 object->objectId);
-
                                stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
 
+                               /* Qualify the name if not visible in search path */
+                               if (StatisticsObjIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(stxForm->stxnamespace);
+
                                appendStringInfo(&buffer, _("statistics object %s"),
-                                                                NameStr(stxForm->stxname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(stxForm->stxname)));
 
                                ReleaseSysCache(stxTup);
                                break;
@@ -3093,14 +3120,25 @@ getObjectDescription(const ObjectAddress *object)
                case OCLASS_TSPARSER:
                        {
                                HeapTuple       tup;
+                               Form_pg_ts_parser prsForm;
+                               char       *nspname;
 
                                tup = SearchSysCache1(TSPARSEROID,
                                                                          ObjectIdGetDatum(object->objectId));
                                if (!HeapTupleIsValid(tup))
                                        elog(ERROR, "cache lookup failed for text search parser %u",
                                                 object->objectId);
+                               prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
+
+                               /* Qualify the name if not visible in search path */
+                               if (TSParserIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(prsForm->prsnamespace);
+
                                appendStringInfo(&buffer, _("text search parser %s"),
-                                                                NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(prsForm->prsname)));
                                ReleaseSysCache(tup);
                                break;
                        }
@@ -3108,14 +3146,25 @@ getObjectDescription(const ObjectAddress *object)
                case OCLASS_TSDICT:
                        {
                                HeapTuple       tup;
+                               Form_pg_ts_dict dictForm;
+                               char       *nspname;
 
                                tup = SearchSysCache1(TSDICTOID,
                                                                          ObjectIdGetDatum(object->objectId));
                                if (!HeapTupleIsValid(tup))
                                        elog(ERROR, "cache lookup failed for text search dictionary %u",
                                                 object->objectId);
+                               dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
+
+                               /* Qualify the name if not visible in search path */
+                               if (TSDictionaryIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(dictForm->dictnamespace);
+
                                appendStringInfo(&buffer, _("text search dictionary %s"),
-                                                                NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(dictForm->dictname)));
                                ReleaseSysCache(tup);
                                break;
                        }
@@ -3123,14 +3172,25 @@ getObjectDescription(const ObjectAddress *object)
                case OCLASS_TSTEMPLATE:
                        {
                                HeapTuple       tup;
+                               Form_pg_ts_template tmplForm;
+                               char       *nspname;
 
                                tup = SearchSysCache1(TSTEMPLATEOID,
                                                                          ObjectIdGetDatum(object->objectId));
                                if (!HeapTupleIsValid(tup))
                                        elog(ERROR, "cache lookup failed for text search template %u",
                                                 object->objectId);
+                               tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
+
+                               /* Qualify the name if not visible in search path */
+                               if (TSTemplateIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(tmplForm->tmplnamespace);
+
                                appendStringInfo(&buffer, _("text search template %s"),
-                                                                NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(tmplForm->tmplname)));
                                ReleaseSysCache(tup);
                                break;
                        }
@@ -3138,14 +3198,25 @@ getObjectDescription(const ObjectAddress *object)
                case OCLASS_TSCONFIG:
                        {
                                HeapTuple       tup;
+                               Form_pg_ts_config cfgForm;
+                               char       *nspname;
 
                                tup = SearchSysCache1(TSCONFIGOID,
                                                                          ObjectIdGetDatum(object->objectId));
                                if (!HeapTupleIsValid(tup))
                                        elog(ERROR, "cache lookup failed for text search configuration %u",
                                                 object->objectId);
+                               cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
+
+                               /* Qualify the name if not visible in search path */
+                               if (TSConfigIsVisible(object->objectId))
+                                       nspname = NULL;
+                               else
+                                       nspname = get_namespace_name(cfgForm->cfgnamespace);
+
                                appendStringInfo(&buffer, _("text search configuration %s"),
-                                                                NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
+                                                                quote_qualified_identifier(nspname,
+                                                                                                                       NameStr(cfgForm->cfgname)));
                                ReleaseSysCache(tup);
                                break;
                        }
index af416ad258368b3ef67b7a6225c5624bc8f980ea..7b35d5c1bd7345eea6af04f2dd97c84e00b0c0c3 100644 (file)
@@ -2580,11 +2580,11 @@ drop cascades to operator family alter2.ctype_hash_ops for access method hash
 drop cascades to type alter2.ctype
 drop cascades to function alter2.same(alter2.ctype,alter2.ctype)
 drop cascades to operator alter2.=(alter2.ctype,alter2.ctype)
-drop cascades to conversion ascii_to_utf8
-drop cascades to text search parser prs
-drop cascades to text search configuration cfg
-drop cascades to text search template tmpl
-drop cascades to text search dictionary dict
+drop cascades to conversion alter2.ascii_to_utf8
+drop cascades to text search parser alter2.prs
+drop cascades to text search configuration alter2.cfg
+drop cascades to text search template alter2.tmpl
+drop cascades to text search dictionary alter2.dict
 --
 -- composite types
 --