Skip to content

Commit b8f179d

Browse files
author
Maksim Milyutin
committed
Replace column type of pathman_config_params from oid to text
1 parent 592efd0 commit b8f179d

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_params AS params
147147
ON params.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
CREATE OR REPLACE FUNCTION @extschema@.validate_part_callback(
37-
callback REGPROC,
37+
callback TEXT,
3838
raise_error BOOL DEFAULT TRUE)
3939
RETURNS BOOL AS '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
CREATE TABLE IF NOT EXISTS @extschema@.pathman_config_params (
5152
partrel REGCLASS NOT NULL PRIMARY KEY,
5253
enable_parent BOOLEAN NOT NULL DEFAULT FALSE,
5354
auto BOOLEAN NOT NULL DEFAULT TRUE,
54-
init_callback REGPROCEDURE NOT NULL DEFAULT 0,
55+
init_callback TEXT,
5556
spawn_using_bgw BOOLEAN NOT 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 VOID AS
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+
ELSE NULL 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_params AS params
10571057
ON params.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
static void copy_foreign_keys(Oid parent_relid, Oid partition_oid);
7979
static void copy_acl_privileges(Oid parent_relid, Oid partition_relid);
8080

81+
static Oid text2regprocedure(text *proname_args);
82+
8183
static Constraint *make_constraint_common(char *name, Node *raw_expr);
8284

8385
static Value make_string_value_struct(char *str);
@@ -1377,6 +1379,34 @@ make_int_value_struct(int int_val)
13771379
return val;
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+
static Oid
1391+
text2regprocedure(text *proname_args)
1392+
{
1393+
FunctionCallInfoData fcinfo;
1394+
Datum result;
1395+
1396+
InitFunctionCallInfoData(fcinfo, NULL, 1, InvalidOid, NULL, NULL);
1397+
1398+
#if PG_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+
return DatumGetObjectId(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-
Datum init_cb_datum; /* Oid of init_callback */
1449+
Datum init_cb_datum; /* signature of init_callback */
14201450
AttrNumber init_cb_attno = Anum_pathman_config_params_init_callback;
14211451

1422-
/* Extract Datum storing callback's Oid */
1452+
/* Extract Datum storing callback's signature */
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+
const char *cb_cstring;
796+
Oid cb_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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy