Skip to content

Commit 2bb067d

Browse files
committed
[PGPRO-8041] Fixed restrictions for pg_pathman.enable
Tags: pg_pathman
1 parent ceed706 commit 2bb067d

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

expected/pathman_runtime_nodes.out

+15-9
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,12 @@ DROP SCHEMA test;
465465
-- Variable pg_pathman.enable must be called before any query.
466466
--
467467
CREATE TABLE part_test (val int NOT NULL);
468-
SELECT create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
469-
ERROR: function create_hash_partitions(unknown, unknown, integer, partition_names => text[]) does not exist at character 8
468+
SELECT pathman.create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
469+
create_hash_partitions
470+
------------------------
471+
2
472+
(1 row)
473+
470474
CREATE OR REPLACE FUNCTION part_test_trigger() RETURNS TRIGGER AS $$
471475
BEGIN
472476
RAISE NOTICE '%', format('%s %s %s (%s)', TG_WHEN, TG_OP, TG_LEVEL, TG_TABLE_NAME);
@@ -478,22 +482,24 @@ END;
478482
$$ LANGUAGE PLPGSQL;
479483
SET pg_pathman.enable_partitionrouter = t;
480484
CREATE TRIGGER ad AFTER DELETE ON part_test_1 FOR EACH ROW EXECUTE PROCEDURE part_test_trigger ();
481-
ERROR: relation "part_test_1" does not exist
482485
INSERT INTO part_test VALUES (1);
483486
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
484-
val | tableoid
485-
-----+-----------
486-
2 | part_test
487+
val | tableoid
488+
-----+-------------
489+
2 | part_test_1
487490
(1 row)
488491

489492
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
490-
val | tableoid
491-
-----+-----------
492-
3 | part_test
493+
NOTICE: AFTER DELETE ROW (part_test_1)
494+
WARNING: "SET pg_pathman.enable" must be called before any query. Command ignored.
495+
val | tableoid
496+
-----+------------
497+
3 | pg_pathman
493498
(1 row)
494499

495500
RESET pg_pathman.enable_partitionrouter;
496501
DROP TABLE part_test CASCADE;
502+
NOTICE: drop cascades to 2 other objects
497503
DROP FUNCTION part_test_trigger();
498504
DROP EXTENSION pg_pathman CASCADE;
499505
DROP SCHEMA pathman;

expected/pathman_runtime_nodes_1.out

+15-9
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,12 @@ DROP SCHEMA test;
465465
-- Variable pg_pathman.enable must be called before any query.
466466
--
467467
CREATE TABLE part_test (val int NOT NULL);
468-
SELECT create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
469-
ERROR: function create_hash_partitions(unknown, unknown, integer, partition_names => text[]) does not exist at character 8
468+
SELECT pathman.create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
469+
create_hash_partitions
470+
------------------------
471+
2
472+
(1 row)
473+
470474
CREATE OR REPLACE FUNCTION part_test_trigger() RETURNS TRIGGER AS $$
471475
BEGIN
472476
RAISE NOTICE '%', format('%s %s %s (%s)', TG_WHEN, TG_OP, TG_LEVEL, TG_TABLE_NAME);
@@ -478,22 +482,24 @@ END;
478482
$$ LANGUAGE PLPGSQL;
479483
SET pg_pathman.enable_partitionrouter = t;
480484
CREATE TRIGGER ad AFTER DELETE ON part_test_1 FOR EACH ROW EXECUTE PROCEDURE part_test_trigger ();
481-
ERROR: relation "part_test_1" does not exist
482485
INSERT INTO part_test VALUES (1);
483486
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
484-
val | tableoid
485-
-----+-----------
486-
2 | part_test
487+
val | tableoid
488+
-----+-------------
489+
2 | part_test_1
487490
(1 row)
488491

489492
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
490-
val | tableoid
491-
-----+-----------
492-
3 | part_test
493+
NOTICE: AFTER DELETE ROW (part_test_1)
494+
WARNING: "SET pg_pathman.enable" must be called before any query. Command ignored.
495+
val | tableoid
496+
-----+------------
497+
3 | pg_pathman
493498
(1 row)
494499

495500
RESET pg_pathman.enable_partitionrouter;
496501
DROP TABLE part_test CASCADE;
502+
NOTICE: drop cascades to 2 other objects
497503
DROP FUNCTION part_test_trigger();
498504
DROP EXTENSION pg_pathman CASCADE;
499505
DROP SCHEMA pathman;

sql/pathman_runtime_nodes.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ DROP SCHEMA test;
348348
-- Variable pg_pathman.enable must be called before any query.
349349
--
350350
CREATE TABLE part_test (val int NOT NULL);
351-
SELECT create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
351+
SELECT pathman.create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
352352
CREATE OR REPLACE FUNCTION part_test_trigger() RETURNS TRIGGER AS $$
353353
BEGIN
354354
RAISE NOTICE '%', format('%s %s %s (%s)', TG_WHEN, TG_OP, TG_LEVEL, TG_TABLE_NAME);

src/hooks.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,29 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
621621
bool
622622
pathman_enable_check_hook(bool *newval, void **extra, GucSource source)
623623
{
624+
/* The top level statement requires immediate commit: accept GUC change */
625+
if (MyXactFlags & XACT_FLAGS_NEEDIMMEDIATECOMMIT)
626+
return true;
627+
628+
/* Ignore the case of re-setting the same value */
629+
if (*newval == pathman_init_state.pg_pathman_enable)
630+
return true;
631+
632+
/* Command must be at top level of a fresh transaction. */
624633
if (FirstSnapshotSet ||
625634
GetTopTransactionIdIfAny() != InvalidTransactionId ||
626635
#ifdef PGPRO_EE
627636
getNestLevelATX() > 0 ||
628637
#endif
629638
IsSubTransaction())
630639
{
631-
GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
632-
GUC_check_errmsg("\"pg_pathman.enable\" must be called before any query");
633-
return false;
640+
/* Keep the old value. */
641+
*newval = pathman_init_state.pg_pathman_enable;
642+
643+
ereport(WARNING,
644+
(errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
645+
errmsg("\"SET pg_pathman.enable\" must be called before any query. "
646+
"Command ignored.")));
634647
}
635648

636649
return true;

0 commit comments

Comments
 (0)