Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

[PGPRO-7928] Variable pg_pathman.enable must be called before any query #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions expected/pathman_runtime_nodes.out
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_2() returns text as $$
Expand Down Expand Up @@ -100,7 +99,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_3() returns text as $$
Expand Down Expand Up @@ -133,7 +131,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_4() returns text as $$
Expand Down Expand Up @@ -172,7 +169,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_5() returns text as $$
Expand Down Expand Up @@ -233,7 +229,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_hashjoin = off
set enable_mergejoin = off;
create table test.run_values as select generate_series(1, 10000) val;
Expand Down Expand Up @@ -464,5 +459,41 @@ DROP FUNCTION test.pathman_test_3();
DROP FUNCTION test.pathman_test_4();
DROP FUNCTION test.pathman_test_5();
DROP SCHEMA test;
--
--
-- PGPRO-7928
-- Variable pg_pathman.enable must be called before any query.
--
CREATE TABLE part_test (val int NOT NULL);
SELECT create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
ERROR: function create_hash_partitions(unknown, unknown, integer, partition_names => text[]) does not exist at character 8
CREATE OR REPLACE FUNCTION part_test_trigger() RETURNS TRIGGER AS $$
BEGIN
RAISE NOTICE '%', format('%s %s %s (%s)', TG_WHEN, TG_OP, TG_LEVEL, TG_TABLE_NAME);
IF TG_OP::text = 'DELETE'::text then
SET pg_pathman.enable = f;
RETURN new;
END IF;
END;
$$ LANGUAGE PLPGSQL;
SET pg_pathman.enable_partitionrouter = t;
CREATE TRIGGER ad AFTER DELETE ON part_test_1 FOR EACH ROW EXECUTE PROCEDURE part_test_trigger ();
ERROR: relation "part_test_1" does not exist
INSERT INTO part_test VALUES (1);
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
val | tableoid
-----+-----------
2 | part_test
(1 row)

UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
val | tableoid
-----+-----------
3 | part_test
(1 row)

RESET pg_pathman.enable_partitionrouter;
DROP TABLE part_test CASCADE;
DROP FUNCTION part_test_trigger();
DROP EXTENSION pg_pathman CASCADE;
DROP SCHEMA pathman;
41 changes: 36 additions & 5 deletions expected/pathman_runtime_nodes_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_2() returns text as $$
Expand Down Expand Up @@ -100,7 +99,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_3() returns text as $$
Expand Down Expand Up @@ -133,7 +131,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_4() returns text as $$
Expand Down Expand Up @@ -172,7 +169,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;
create or replace function test.pathman_test_5() returns text as $$
Expand Down Expand Up @@ -233,7 +229,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_hashjoin = off
set enable_mergejoin = off;
create table test.run_values as select generate_series(1, 10000) val;
Expand Down Expand Up @@ -464,5 +459,41 @@ DROP FUNCTION test.pathman_test_3();
DROP FUNCTION test.pathman_test_4();
DROP FUNCTION test.pathman_test_5();
DROP SCHEMA test;
--
--
-- PGPRO-7928
-- Variable pg_pathman.enable must be called before any query.
--
CREATE TABLE part_test (val int NOT NULL);
SELECT create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
ERROR: function create_hash_partitions(unknown, unknown, integer, partition_names => text[]) does not exist at character 8
CREATE OR REPLACE FUNCTION part_test_trigger() RETURNS TRIGGER AS $$
BEGIN
RAISE NOTICE '%', format('%s %s %s (%s)', TG_WHEN, TG_OP, TG_LEVEL, TG_TABLE_NAME);
IF TG_OP::text = 'DELETE'::text then
SET pg_pathman.enable = f;
RETURN new;
END IF;
END;
$$ LANGUAGE PLPGSQL;
SET pg_pathman.enable_partitionrouter = t;
CREATE TRIGGER ad AFTER DELETE ON part_test_1 FOR EACH ROW EXECUTE PROCEDURE part_test_trigger ();
ERROR: relation "part_test_1" does not exist
INSERT INTO part_test VALUES (1);
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
val | tableoid
-----+-----------
2 | part_test
(1 row)

UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
val | tableoid
-----+-----------
3 | part_test
(1 row)

RESET pg_pathman.enable_partitionrouter;
DROP TABLE part_test CASCADE;
DROP FUNCTION part_test_trigger();
DROP EXTENSION pg_pathman CASCADE;
DROP SCHEMA pathman;
32 changes: 26 additions & 6 deletions sql/pathman_runtime_nodes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;

Expand Down Expand Up @@ -106,7 +105,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;

Expand Down Expand Up @@ -140,7 +138,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;

Expand Down Expand Up @@ -180,7 +177,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_mergejoin = off
set enable_hashjoin = off;

Expand Down Expand Up @@ -242,7 +238,6 @@ begin
return 'ok';
end;
$$ language plpgsql
set pg_pathman.enable = true
set enable_hashjoin = off
set enable_mergejoin = off;

Expand Down Expand Up @@ -347,6 +342,31 @@ DROP FUNCTION test.pathman_test_3();
DROP FUNCTION test.pathman_test_4();
DROP FUNCTION test.pathman_test_5();
DROP SCHEMA test;
--
--
-- PGPRO-7928
-- Variable pg_pathman.enable must be called before any query.
--
CREATE TABLE part_test (val int NOT NULL);
SELECT create_hash_partitions('part_test', 'val', 2, partition_names := array['part_test_1','pg_pathman']);
CREATE OR REPLACE FUNCTION part_test_trigger() RETURNS TRIGGER AS $$
BEGIN
RAISE NOTICE '%', format('%s %s %s (%s)', TG_WHEN, TG_OP, TG_LEVEL, TG_TABLE_NAME);
IF TG_OP::text = 'DELETE'::text then
SET pg_pathman.enable = f;
RETURN new;
END IF;
END;
$$ LANGUAGE PLPGSQL;
SET pg_pathman.enable_partitionrouter = t;
CREATE TRIGGER ad AFTER DELETE ON part_test_1 FOR EACH ROW EXECUTE PROCEDURE part_test_trigger ();
INSERT INTO part_test VALUES (1);
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;
UPDATE part_test SET val = val + 1 RETURNING *, tableoid::regclass;

RESET pg_pathman.enable_partitionrouter;
DROP TABLE part_test CASCADE;
DROP FUNCTION part_test_trigger();

DROP EXTENSION pg_pathman CASCADE;
DROP SCHEMA pathman;

24 changes: 23 additions & 1 deletion src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
#include "optimizer/prep.h"
#include "optimizer/restrictinfo.h"
#include "rewrite/rewriteManip.h"
#include "utils/typcache.h"
#include "utils/lsyscache.h"
#include "utils/typcache.h"
#include "utils/snapmgr.h"


#ifdef USE_ASSERT_CHECKING
Expand Down Expand Up @@ -614,6 +615,27 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
close_pathman_relation_info(prel);
}

/*
* 'pg_pathman.enable' GUC check.
*/
bool
pathman_enable_check_hook(bool *newval, void **extra, GucSource source)
{
if (FirstSnapshotSet ||
GetTopTransactionIdIfAny() != InvalidTransactionId ||
#ifdef PGPRO_EE
getNestLevelATX() > 0 ||
#endif
IsSubTransaction())
{
GUC_check_errcode(ERRCODE_ACTIVE_SQL_TRANSACTION);
GUC_check_errmsg("\"pg_pathman.enable\" must be called before any query");
return false;
}

return true;
}

/*
* Intercept 'pg_pathman.enable' GUC assignments.
*/
Expand Down
1 change: 1 addition & 0 deletions src/include/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void pathman_rel_pathlist_hook(PlannerInfo *root,
RangeTblEntry *rte);

void pathman_enable_assign_hook(bool newval, void *extra);
bool pathman_enable_check_hook(bool *newval, void **extra, GucSource source);

PlannedStmt * pathman_planner_hook(Query *parse,
#if PG_VERSION_NUM >= 130000
Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ init_main_pathman_toggles(void)
DEFAULT_PATHMAN_ENABLE,
PGC_SUSET,
0,
NULL,
pathman_enable_check_hook,
pathman_enable_assign_hook,
NULL);

Expand Down