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

Commitb73e6d7

Browse files
committed
Fix erroneous construction of functions' dependencies on transforms.
The list of transform objects that a function should use is specifiedin CREATE FUNCTION's TRANSFORM clause, and then represented indirectlyin pg_proc.protrftypes. However, ProcedureCreate completely ignoredthat for purposes of constructing pg_depend entries, and instead madethe function depend on any transforms that exist for its parameter orreturn data types. This is bad in both directions: the function couldbe made dependent on a transform it does not actually use, or itcould try to use a transform that's since been dropped. (The latterscenario would require use of a transform that's not for any of theparameter or return types, but that seems legit for cases where thefunction performs SQL operations internally.)To fix, pass in the list of transform objects that CreateFunctionidentified, and build pg_depend entries from that not from theparameter/return types. This results in changes in the expectedtest outputs in contrib/bool_plperl, which I guess are due todifferent ordering of pg_depend entries -- that test case issurely not exercising either of the problem scenarios.This fix is not back-patchable as-is: changing the signature ofProcedureCreate seems too risky in stable branches. We coulddo something like making ProcedureCreate a wrapper aroundProcedureCreateExt or so. However, I'm more inclined to donothing in the back branches. We had no field complaints up tonow, so the hazards don't seem to be a big issue in practice.And we couldn't do anything about existing pg_depend entries,so a back-patched fix would result in a mishmash of dependenciescreated according to different rules. That cure could be worsethan the disease, perhaps.I bumped catversion just to lay down a marker that the expectedcontents of pg_depend are a bit different than before.Reported-by: Chapman Flack <jcflack@acm.org>Author: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/3112950.1743984111@sss.pgh.pa.us
1 parenta379061 commitb73e6d7

File tree

8 files changed

+52
-22
lines changed

8 files changed

+52
-22
lines changed

‎contrib/bool_plperl/expected/bool_plperl.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ SELECT spi_test();
104104

105105
DROP EXTENSION plperl CASCADE;
106106
NOTICE: drop cascades to 6 other objects
107-
DETAIL: drop cascades to function spi_test()
108-
drop cascades to extension bool_plperl
107+
DETAIL: drop cascades to extension bool_plperl
109108
drop cascades to function perl2int(integer)
110109
drop cascades to function perl2text(text)
111110
drop cascades to function perl2undef()
112111
drop cascades to function bool2perl(boolean,boolean,boolean)
112+
drop cascades to function spi_test()

‎contrib/bool_plperl/expected/bool_plperlu.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ SELECT spi_test();
104104

105105
DROP EXTENSION plperlu CASCADE;
106106
NOTICE: drop cascades to 6 other objects
107-
DETAIL: drop cascades to function spi_test()
108-
drop cascades to extension bool_plperlu
107+
DETAIL: drop cascades to extension bool_plperlu
109108
drop cascades to function perl2int(integer)
110109
drop cascades to function perl2text(text)
111110
drop cascades to function perl2undef()
112111
drop cascades to function bool2perl(boolean,boolean,boolean)
112+
drop cascades to function spi_test()

‎src/backend/catalog/pg_aggregate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ AggregateCreate(const char *aggName,
637637
parameterNames,/* parameterNames */
638638
parameterDefaults,/* parameterDefaults */
639639
PointerGetDatum(NULL),/* trftypes */
640+
NIL,/* trfoids */
640641
PointerGetDatum(NULL),/* proconfig */
641642
InvalidOid,/* no prosupport */
642643
1,/* procost */

‎src/backend/catalog/pg_proc.c

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include"catalog/pg_proc.h"
2727
#include"catalog/pg_transform.h"
2828
#include"catalog/pg_type.h"
29-
#include"commands/defrem.h"
3029
#include"executor/functions.h"
3130
#include"funcapi.h"
3231
#include"mb/pg_wchar.h"
@@ -61,6 +60,35 @@ static bool match_prosrc_to_literal(const char *prosrc, const char *literal,
6160
/* ----------------------------------------------------------------
6261
*ProcedureCreate
6362
*
63+
*procedureName: string name of routine (proname)
64+
*procNamespace: OID of namespace (pronamespace)
65+
*replace: true to allow replacement of an existing pg_proc entry
66+
*returnsSet: returns set? (proretset)
67+
*returnType: OID of result type (prorettype)
68+
*proowner: OID of owner role (proowner)
69+
*languageObjectId: OID of function language (prolang)
70+
*languageValidator: OID of validator function to apply, if any
71+
*prosrc: string form of function definition (prosrc)
72+
*probin: string form of binary reference, or NULL (probin)
73+
*prosqlbody: Node tree of pre-parsed SQL body, or NULL (prosqlbody)
74+
*prokind: function/aggregate/procedure/etc code (prokind)
75+
*security_definer: security definer? (prosecdef)
76+
*isLeakProof: leak proof? (proleakproof)
77+
*isStrict: strict? (proisstrict)
78+
*volatility: volatility code (provolatile)
79+
*parallel: parallel safety code (proparallel)
80+
*parameterTypes: input parameter types, as an oidvector (proargtypes)
81+
*allParameterTypes: all parameter types, as an OID array (proallargtypes)
82+
*parameterModes: parameter modes, as a "char" array (proargmodes)
83+
*parameterNames: parameter names, as a text array (proargnames)
84+
*parameterDefaults: defaults, as a List of Node trees (proargdefaults)
85+
*trftypes: transformable type OIDs, as an OID array (protrftypes)
86+
*trfoids: List of transform OIDs that routine should depend on
87+
*proconfig: GUC set clauses, as a text array (proconfig)
88+
*prosupport: OID of support function, if any (prosupport)
89+
*procost: cost factor (procost)
90+
*prorows: estimated output rows for a SRF (prorows)
91+
*
6492
* Note: allParameterTypes, parameterModes, parameterNames, trftypes, and proconfig
6593
* are either arrays of the proper types or NULL. We declare them Datum,
6694
* not "ArrayType *", to avoid importing array.h into pg_proc.h.
@@ -90,6 +118,7 @@ ProcedureCreate(const char *procedureName,
90118
DatumparameterNames,
91119
List*parameterDefaults,
92120
Datumtrftypes,
121+
List*trfoids,
93122
Datumproconfig,
94123
Oidprosupport,
95124
float4procost,
@@ -115,7 +144,6 @@ ProcedureCreate(const char *procedureName,
115144
referenced;
116145
char*detailmsg;
117146
inti;
118-
Oidtrfid;
119147
ObjectAddresses*addrs;
120148

121149
/*
@@ -609,25 +637,18 @@ ProcedureCreate(const char *procedureName,
609637
ObjectAddressSet(referenced,TypeRelationId,returnType);
610638
add_exact_object_address(&referenced,addrs);
611639

612-
/* dependency on transform used by return type, if any */
613-
if ((trfid=get_transform_oid(returnType,languageObjectId, true)))
614-
{
615-
ObjectAddressSet(referenced,TransformRelationId,trfid);
616-
add_exact_object_address(&referenced,addrs);
617-
}
618-
619640
/* dependency on parameter types */
620641
for (i=0;i<allParamCount;i++)
621642
{
622643
ObjectAddressSet(referenced,TypeRelationId,allParams[i]);
623644
add_exact_object_address(&referenced,addrs);
645+
}
624646

625-
/* dependency on transform used by parameter type, if any */
626-
if ((trfid=get_transform_oid(allParams[i],languageObjectId, true)))
627-
{
628-
ObjectAddressSet(referenced,TransformRelationId,trfid);
629-
add_exact_object_address(&referenced,addrs);
630-
}
647+
/* dependency on transforms, if any */
648+
foreach_oid(transformid,trfoids)
649+
{
650+
ObjectAddressSet(referenced,TransformRelationId,transformid);
651+
add_exact_object_address(&referenced,addrs);
631652
}
632653

633654
/* dependency on support function, if any */

‎src/backend/commands/functioncmds.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
10461046
List*parameterDefaults;
10471047
OidvariadicArgType;
10481048
List*trftypes_list=NIL;
1049+
List*trfoids_list=NIL;
10491050
ArrayType*trftypes;
10501051
OidrequiredResultType;
10511052
boolisWindowFunc,
@@ -1157,11 +1158,12 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
11571158
Oidtypeid=typenameTypeId(NULL,
11581159
lfirst_node(TypeName,lc));
11591160
Oidelt=get_base_element_type(typeid);
1161+
Oidtransformid;
11601162

11611163
typeid=elt ?elt :typeid;
1162-
1163-
get_transform_oid(typeid,languageOid, false);
1164+
transformid=get_transform_oid(typeid,languageOid, false);
11641165
trftypes_list=lappend_oid(trftypes_list,typeid);
1166+
trfoids_list=lappend_oid(trfoids_list,transformid);
11651167
}
11661168
}
11671169

@@ -1292,6 +1294,7 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
12921294
PointerGetDatum(parameterNames),
12931295
parameterDefaults,
12941296
PointerGetDatum(trftypes),
1297+
trfoids_list,
12951298
PointerGetDatum(proconfig),
12961299
prosupport,
12971300
procost,

‎src/backend/commands/typecmds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,7 @@ makeRangeConstructors(const char *name, Oid namespace,
18101810
PointerGetDatum(NULL),/* parameterNames */
18111811
NIL,/* parameterDefaults */
18121812
PointerGetDatum(NULL),/* trftypes */
1813+
NIL,/* trfoids */
18131814
PointerGetDatum(NULL),/* proconfig */
18141815
InvalidOid,/* prosupport */
18151816
1.0,/* procost */
@@ -1875,6 +1876,7 @@ makeMultirangeConstructors(const char *name, Oid namespace,
18751876
PointerGetDatum(NULL),/* parameterNames */
18761877
NIL,/* parameterDefaults */
18771878
PointerGetDatum(NULL),/* trftypes */
1879+
NIL,/* trfoids */
18781880
PointerGetDatum(NULL),/* proconfig */
18791881
InvalidOid,/* prosupport */
18801882
1.0,/* procost */
@@ -1919,6 +1921,7 @@ makeMultirangeConstructors(const char *name, Oid namespace,
19191921
PointerGetDatum(NULL),/* parameterNames */
19201922
NIL,/* parameterDefaults */
19211923
PointerGetDatum(NULL),/* trftypes */
1924+
NIL,/* trfoids */
19221925
PointerGetDatum(NULL),/* proconfig */
19231926
InvalidOid,/* prosupport */
19241927
1.0,/* procost */
@@ -1957,6 +1960,7 @@ makeMultirangeConstructors(const char *name, Oid namespace,
19571960
PointerGetDatum(NULL),/* parameterNames */
19581961
NIL,/* parameterDefaults */
19591962
PointerGetDatum(NULL),/* trftypes */
1963+
NIL,/* trfoids */
19601964
PointerGetDatum(NULL),/* proconfig */
19611965
InvalidOid,/* prosupport */
19621966
1.0,/* procost */

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/*yyyymmddN */
60-
#defineCATALOG_VERSION_NO202504041
60+
#defineCATALOG_VERSION_NO202504071
6161

6262
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ extern ObjectAddress ProcedureCreate(const char *procedureName,
211211
DatumparameterNames,
212212
List*parameterDefaults,
213213
Datumtrftypes,
214+
List*trfoids,
214215
Datumproconfig,
215216
Oidprosupport,
216217
float4procost,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp