Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit056f52d

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 ofthe object, potentially producing wrong or at least highly misleadingoutput. 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-qualifiableobject 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 meDiscussion:https://postgr.es/m/20180522.182020.114074746.horiguchi.kyotaro@lab.ntt.co.jp
1 parent4431c94 commit056f52d

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
@@ -2738,15 +2738,24 @@ getObjectDescription(const ObjectAddress *object)
27382738
{
27392739
HeapTuplecollTup;
27402740
Form_pg_collationcoll;
2741+
char*nspname;
27412742

27422743
collTup=SearchSysCache1(COLLOID,
27432744
ObjectIdGetDatum(object->objectId));
27442745
if (!HeapTupleIsValid(collTup))
27452746
elog(ERROR,"cache lookup failed for collation %u",
27462747
object->objectId);
27472748
coll= (Form_pg_collation)GETSTRUCT(collTup);
2749+
2750+
/* Qualify the name if not visible in search path */
2751+
if (CollationIsVisible(object->objectId))
2752+
nspname=NULL;
2753+
else
2754+
nspname=get_namespace_name(coll->collnamespace);
2755+
27482756
appendStringInfo(&buffer,_("collation %s"),
2749-
NameStr(coll->collname));
2757+
quote_qualified_identifier(nspname,
2758+
NameStr(coll->collname)));
27502759
ReleaseSysCache(collTup);
27512760
break;
27522761
}
@@ -2786,14 +2795,25 @@ getObjectDescription(const ObjectAddress *object)
27862795
caseOCLASS_CONVERSION:
27872796
{
27882797
HeapTupleconTup;
2798+
Form_pg_conversionconv;
2799+
char*nspname;
27892800

27902801
conTup=SearchSysCache1(CONVOID,
27912802
ObjectIdGetDatum(object->objectId));
27922803
if (!HeapTupleIsValid(conTup))
27932804
elog(ERROR,"cache lookup failed for conversion %u",
27942805
object->objectId);
2806+
conv= (Form_pg_conversion)GETSTRUCT(conTup);
2807+
2808+
/* Qualify the name if not visible in search path */
2809+
if (ConversionIsVisible(object->objectId))
2810+
nspname=NULL;
2811+
else
2812+
nspname=get_namespace_name(conv->connamespace);
2813+
27952814
appendStringInfo(&buffer,_("conversion %s"),
2796-
NameStr(((Form_pg_conversion)GETSTRUCT(conTup))->conname));
2815+
quote_qualified_identifier(nspname,
2816+
NameStr(conv->conname)));
27972817
ReleaseSysCache(conTup);
27982818
break;
27992819
}
@@ -3095,17 +3115,24 @@ getObjectDescription(const ObjectAddress *object)
30953115
{
30963116
HeapTuplestxTup;
30973117
Form_pg_statistic_extstxForm;
3118+
char*nspname;
30983119

30993120
stxTup=SearchSysCache1(STATEXTOID,
31003121
ObjectIdGetDatum(object->objectId));
31013122
if (!HeapTupleIsValid(stxTup))
31023123
elog(ERROR,"could not find tuple for statistics object %u",
31033124
object->objectId);
3104-
31053125
stxForm= (Form_pg_statistic_ext)GETSTRUCT(stxTup);
31063126

3127+
/* Qualify the name if not visible in search path */
3128+
if (StatisticsObjIsVisible(object->objectId))
3129+
nspname=NULL;
3130+
else
3131+
nspname=get_namespace_name(stxForm->stxnamespace);
3132+
31073133
appendStringInfo(&buffer,_("statistics object %s"),
3108-
NameStr(stxForm->stxname));
3134+
quote_qualified_identifier(nspname,
3135+
NameStr(stxForm->stxname)));
31093136

31103137
ReleaseSysCache(stxTup);
31113138
break;
@@ -3114,59 +3141,103 @@ getObjectDescription(const ObjectAddress *object)
31143141
caseOCLASS_TSPARSER:
31153142
{
31163143
HeapTupletup;
3144+
Form_pg_ts_parserprsForm;
3145+
char*nspname;
31173146

31183147
tup=SearchSysCache1(TSPARSEROID,
31193148
ObjectIdGetDatum(object->objectId));
31203149
if (!HeapTupleIsValid(tup))
31213150
elog(ERROR,"cache lookup failed for text search parser %u",
31223151
object->objectId);
3152+
prsForm= (Form_pg_ts_parser)GETSTRUCT(tup);
3153+
3154+
/* Qualify the name if not visible in search path */
3155+
if (TSParserIsVisible(object->objectId))
3156+
nspname=NULL;
3157+
else
3158+
nspname=get_namespace_name(prsForm->prsnamespace);
3159+
31233160
appendStringInfo(&buffer,_("text search parser %s"),
3124-
NameStr(((Form_pg_ts_parser)GETSTRUCT(tup))->prsname));
3161+
quote_qualified_identifier(nspname,
3162+
NameStr(prsForm->prsname)));
31253163
ReleaseSysCache(tup);
31263164
break;
31273165
}
31283166

31293167
caseOCLASS_TSDICT:
31303168
{
31313169
HeapTupletup;
3170+
Form_pg_ts_dictdictForm;
3171+
char*nspname;
31323172

31333173
tup=SearchSysCache1(TSDICTOID,
31343174
ObjectIdGetDatum(object->objectId));
31353175
if (!HeapTupleIsValid(tup))
31363176
elog(ERROR,"cache lookup failed for text search dictionary %u",
31373177
object->objectId);
3178+
dictForm= (Form_pg_ts_dict)GETSTRUCT(tup);
3179+
3180+
/* Qualify the name if not visible in search path */
3181+
if (TSDictionaryIsVisible(object->objectId))
3182+
nspname=NULL;
3183+
else
3184+
nspname=get_namespace_name(dictForm->dictnamespace);
3185+
31383186
appendStringInfo(&buffer,_("text search dictionary %s"),
3139-
NameStr(((Form_pg_ts_dict)GETSTRUCT(tup))->dictname));
3187+
quote_qualified_identifier(nspname,
3188+
NameStr(dictForm->dictname)));
31403189
ReleaseSysCache(tup);
31413190
break;
31423191
}
31433192

31443193
caseOCLASS_TSTEMPLATE:
31453194
{
31463195
HeapTupletup;
3196+
Form_pg_ts_templatetmplForm;
3197+
char*nspname;
31473198

31483199
tup=SearchSysCache1(TSTEMPLATEOID,
31493200
ObjectIdGetDatum(object->objectId));
31503201
if (!HeapTupleIsValid(tup))
31513202
elog(ERROR,"cache lookup failed for text search template %u",
31523203
object->objectId);
3204+
tmplForm= (Form_pg_ts_template)GETSTRUCT(tup);
3205+
3206+
/* Qualify the name if not visible in search path */
3207+
if (TSTemplateIsVisible(object->objectId))
3208+
nspname=NULL;
3209+
else
3210+
nspname=get_namespace_name(tmplForm->tmplnamespace);
3211+
31533212
appendStringInfo(&buffer,_("text search template %s"),
3154-
NameStr(((Form_pg_ts_template)GETSTRUCT(tup))->tmplname));
3213+
quote_qualified_identifier(nspname,
3214+
NameStr(tmplForm->tmplname)));
31553215
ReleaseSysCache(tup);
31563216
break;
31573217
}
31583218

31593219
caseOCLASS_TSCONFIG:
31603220
{
31613221
HeapTupletup;
3222+
Form_pg_ts_configcfgForm;
3223+
char*nspname;
31623224

31633225
tup=SearchSysCache1(TSCONFIGOID,
31643226
ObjectIdGetDatum(object->objectId));
31653227
if (!HeapTupleIsValid(tup))
31663228
elog(ERROR,"cache lookup failed for text search configuration %u",
31673229
object->objectId);
3230+
cfgForm= (Form_pg_ts_config)GETSTRUCT(tup);
3231+
3232+
/* Qualify the name if not visible in search path */
3233+
if (TSConfigIsVisible(object->objectId))
3234+
nspname=NULL;
3235+
else
3236+
nspname=get_namespace_name(cfgForm->cfgnamespace);
3237+
31683238
appendStringInfo(&buffer,_("text search configuration %s"),
3169-
NameStr(((Form_pg_ts_config)GETSTRUCT(tup))->cfgname));
3239+
quote_qualified_identifier(nspname,
3240+
NameStr(cfgForm->cfgname)));
31703241
ReleaseSysCache(tup);
31713242
break;
31723243
}

‎src/test/regress/expected/alter_table.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,11 +2680,11 @@ drop cascades to operator family alter2.ctype_hash_ops for access method hash
26802680
drop cascades to type alter2.ctype
26812681
drop cascades to function alter2.same(alter2.ctype,alter2.ctype)
26822682
drop cascades to operator alter2.=(alter2.ctype,alter2.ctype)
2683-
drop cascades to conversion ascii_to_utf8
2684-
drop cascades to text search parser prs
2685-
drop cascades to text search configuration cfg
2686-
drop cascades to text search template tmpl
2687-
drop cascades to text search dictionary dict
2683+
drop cascades to conversionalter2.ascii_to_utf8
2684+
drop cascades to text search parseralter2.prs
2685+
drop cascades to text search configurationalter2.cfg
2686+
drop cascades to text search templatealter2.tmpl
2687+
drop cascades to text search dictionaryalter2.dict
26882688
--
26892689
-- composite types
26902690
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp