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

Commitb8f179d

Browse files
author
Maksim Milyutin
committed
Replace column type of pathman_config_params from oid to text
1 parent592efd0 commitb8f179d

File tree

7 files changed

+70
-14
lines changed

7 files changed

+70
-14
lines changed

‎expected/pathman_permissions.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ SELECT * FROM pathman_config;
4141
SELECT * FROM pathman_config_params;
4242
partrel | enable_parent | auto | init_callback | spawn_using_bgw
4343
-------------------------+---------------+------+---------------+-----------------
44-
permissions.user1_table | f | t |- | f
44+
permissions.user1_table | f | t | | f
4545
(1 row)
4646

4747
/* Should fail */

‎hash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ BEGIN
141141

142142
/* Fetch init_callback from 'params' table*/
143143
WITH stub_callback(stub)as (values (0))
144-
SELECT coalesce(init_callback,0::REGPROCEDURE)
144+
SELECT coalesce(init_callback,NULL)
145145
FROM stub_callback
146146
LEFT JOIN @extschema@.pathman_config_paramsAS params
147147
ONparams.partrel= parent_relid

‎init.sql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,25 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
3434
* NOTE: this function is used in CHECK CONSTRAINT.
3535
*/
3636
CREATEOR REPLACE FUNCTION @extschema@.validate_part_callback(
37-
callbackREGPROC,
37+
callbackTEXT,
3838
raise_errorBOOL DEFAULT TRUE)
3939
RETURNS BOOLAS'pg_pathman','validate_part_callback_pl'
40-
LANGUAGE C STRICT;
40+
LANGUAGE C;
4141

4242

4343
/*
4444
* Optional parameters for partitioned tables.
4545
*partrel - regclass (relation type, stored as Oid)
4646
*enable_parent - add parent table to plan
4747
*auto - enable automatic partition creation
48-
*init_callback - cb to be executed on partition creation
48+
*init_callback - text signature of cb to be executed on partition
49+
* creation
4950
*/
5051
CREATETABLEIF NOT EXISTS @extschema@.pathman_config_params (
5152
partrelREGCLASSNOT NULLPRIMARY KEY,
5253
enable_parentBOOLEANNOT NULL DEFAULT FALSE,
5354
autoBOOLEANNOT NULL DEFAULT TRUE,
54-
init_callbackREGPROCEDURENOT NULL DEFAULT0,
55+
init_callbackTEXT,
5556
spawn_using_bgwBOOLEANNOT NULL DEFAULT FALSE
5657

5758
CHECK (@extschema@.validate_part_callback(init_callback))/* check signature*/
@@ -118,7 +119,7 @@ BEGIN
118119
USING relation, value;
119120
END
120121
$$
121-
LANGUAGE plpgsql STRICT;
122+
LANGUAGE plpgsql;
122123

123124
/*
124125
* Include\exclude parent relation in query plan.
@@ -157,7 +158,11 @@ CREATE OR REPLACE FUNCTION @extschema@.set_init_callback(
157158
RETURNS VOIDAS
158159
$$
159160
BEGIN
160-
PERFORM @extschema@.pathman_set_param(relation,'init_callback', callback);
161+
PERFORM @extschema@.pathman_set_param(relation,'init_callback',
162+
CASE WHEN callback<>0
163+
THEN regprocedureout(callback)::text
164+
ELSENULL END);
165+
161166
END
162167
$$
163168
LANGUAGE plpgsql STRICT;

‎range.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ BEGIN
10511051

10521052
/* Fetch init_callback from 'params' table*/
10531053
WITH stub_callback(stub)as (values (0))
1054-
SELECT coalesce(init_callback,0::REGPROCEDURE)
1054+
SELECT coalesce(init_callback,NULL)
10551055
FROM stub_callback
10561056
LEFT JOIN @extschema@.pathman_config_paramsAS params
10571057
ONparams.partrel= parent_relid

‎src/init.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
750750
Assert(!isnull[Anum_pathman_config_params_partrel-1]);
751751
Assert(!isnull[Anum_pathman_config_params_enable_parent-1]);
752752
Assert(!isnull[Anum_pathman_config_params_auto-1]);
753-
Assert(!isnull[Anum_pathman_config_params_init_callback-1]);
754753
Assert(!isnull[Anum_pathman_config_params_spawn_using_bgw-1]);
755754
}
756755

‎src/partition_creation.c

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ static ObjectAddress create_table_using_stmt(CreateStmt *create_stmt,
7878
staticvoidcopy_foreign_keys(Oidparent_relid,Oidpartition_oid);
7979
staticvoidcopy_acl_privileges(Oidparent_relid,Oidpartition_relid);
8080

81+
staticOidtext2regprocedure(text*proname_args);
82+
8183
staticConstraint*make_constraint_common(char*name,Node*raw_expr);
8284

8385
staticValuemake_string_value_struct(char*str);
@@ -1377,6 +1379,34 @@ make_int_value_struct(int int_val)
13771379
returnval;
13781380
}
13791381

1382+
/*
1383+
* Utility function that converts signature of procedure into regprocedure.
1384+
*
1385+
* Precondition: proname_args != NULL.
1386+
*
1387+
* Returns InvalidOid if proname_args is not found.
1388+
* Raise error if it's incorrect.
1389+
*/
1390+
staticOid
1391+
text2regprocedure(text*proname_args)
1392+
{
1393+
FunctionCallInfoDatafcinfo;
1394+
Datumresult;
1395+
1396+
InitFunctionCallInfoData(fcinfo,NULL,1,InvalidOid,NULL,NULL);
1397+
1398+
#ifPG_VERSION_NUM >=90600
1399+
fcinfo.arg[0]=PointerGetDatum(proname_args);
1400+
#else
1401+
fcinfo.arg[0]=CStringGetDatum(text_to_cstring(proname_args));
1402+
#endif
1403+
fcinfo.argnull[0]= false;
1404+
1405+
result=to_regprocedure(&fcinfo);
1406+
1407+
returnDatumGetObjectId(result);
1408+
}
1409+
13801410

13811411
/*
13821412
* ---------------------
@@ -1416,14 +1446,26 @@ invoke_init_callback_internal(init_callback_params *cb_params)
14161446
/* Search for init_callback entry in PATHMAN_CONFIG_PARAMS */
14171447
if (read_pathman_params(parent_oid,param_values,param_isnull))
14181448
{
1419-
Datuminit_cb_datum;/*Oid of init_callback */
1449+
Datuminit_cb_datum;/*signature of init_callback */
14201450
AttrNumberinit_cb_attno=Anum_pathman_config_params_init_callback;
14211451

1422-
/* Extract Datum storing callback'sOid */
1452+
/* Extract Datum storing callback'ssignature */
14231453
init_cb_datum=param_values[init_cb_attno-1];
14241454

14251455
/* Cache init_callback's Oid */
1426-
cb_params->callback=DatumGetObjectId(init_cb_datum);
1456+
if (init_cb_datum)
1457+
{
1458+
cb_params->callback=text2regprocedure(
1459+
DatumGetTextP(init_cb_datum));
1460+
1461+
if (!RegProcedureIsValid(cb_params->callback))
1462+
ereport(ERROR,
1463+
(errcode(ERRCODE_INTEGRITY_CONSTRAINT_VIOLATION),
1464+
errmsg("callback function \"%s\" doesn't exist",
1465+
DatumGetCString(init_cb_datum))));
1466+
}
1467+
else
1468+
cb_params->callback=InvalidOid;
14271469
cb_params->callback_is_cached= true;
14281470
}
14291471
}

‎src/pl_funcs.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,17 @@ prevent_relation_modification(PG_FUNCTION_ARGS)
792792
Datum
793793
validate_part_callback_pl(PG_FUNCTION_ARGS)
794794
{
795-
PG_RETURN_BOOL(validate_part_callback(PG_GETARG_OID(0),PG_GETARG_BOOL(1)));
795+
constchar*cb_cstring;
796+
Oidcb_oid;
797+
798+
if (PG_ARGISNULL(0))
799+
PG_RETURN_BOOL(true);
800+
801+
cb_cstring=text_to_cstring(PG_GETARG_TEXT_P(0));
802+
cb_oid=DatumGetObjectId(DirectFunctionCall1(regprocedurein,
803+
CStringGetDatum(cb_cstring)));
804+
805+
PG_RETURN_BOOL(validate_part_callback(cb_oid,PG_GETARG_BOOL(1)));
796806
}
797807

798808
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp