Skip to content

Commit 04ca436

Browse files
committed
improve pathman_cache_search_relid(), tests
1 parent 1bbbd78 commit 04ca436

File tree

3 files changed

+114
-7
lines changed

3 files changed

+114
-7
lines changed

expected/pathman_calamity.out

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,78 @@ NOTICE: drop cascades to table calamity.test_range_oid_1
670670
DROP SCHEMA calamity CASCADE;
671671
NOTICE: drop cascades to 18 other objects
672672
DROP EXTENSION pg_pathman;
673+
/*
674+
* ------------------------------------------
675+
* Special tests (uninitialized pg_pathman)
676+
* ------------------------------------------
677+
*/
678+
CREATE SCHEMA calamity;
679+
CREATE EXTENSION pg_pathman;
680+
/* check function pathman_cache_search_relid() */
681+
CREATE TABLE calamity.survivor(val INT NOT NULL);
682+
SELECT create_range_partitions('calamity.survivor', 'val', 1, 10, 2);
683+
NOTICE: sequence "survivor_seq" does not exist, skipping
684+
create_range_partitions
685+
-------------------------
686+
2
687+
(1 row)
688+
689+
DROP EXTENSION pg_pathman CASCADE;
690+
SET pg_pathman.enable = f; /* DON'T LOAD CONFIG */
691+
NOTICE: RuntimeAppend, RuntimeMergeAppend and PartitionFilter nodes and some other options have been disabled
692+
CREATE EXTENSION pg_pathman;
693+
SHOW pg_pathman.enable;
694+
pg_pathman.enable
695+
-------------------
696+
off
697+
(1 row)
698+
699+
SELECT add_to_pathman_config('calamity.survivor', 'val', '10'); /* not ok */
700+
ERROR: pg_pathman is not initialized yet
701+
SELECT * FROM pathman_partition_list; /* not ok */
702+
ERROR: pg_pathman is not initialized yet
703+
SELECT get_part_range('calamity.survivor', 0, NULL::INT); /* not ok */
704+
ERROR: pg_pathman is not initialized yet
705+
EXPLAIN (COSTS OFF) SELECT * FROM calamity.survivor; /* OK */
706+
QUERY PLAN
707+
------------------------------
708+
Append
709+
-> Seq Scan on survivor
710+
-> Seq Scan on survivor_1
711+
-> Seq Scan on survivor_2
712+
(4 rows)
713+
714+
SET pg_pathman.enable = t; /* LOAD CONFIG */
715+
NOTICE: RuntimeAppend, RuntimeMergeAppend and PartitionFilter nodes and some other options have been enabled
716+
SELECT add_to_pathman_config('calamity.survivor', 'val', '10'); /* OK */
717+
add_to_pathman_config
718+
-----------------------
719+
t
720+
(1 row)
721+
722+
SELECT * FROM pathman_partition_list; /* OK */
723+
parent | partition | parttype | partattr | range_min | range_max
724+
-------------------+---------------------+----------+----------+-----------+-----------
725+
calamity.survivor | calamity.survivor_1 | 2 | val | 1 | 11
726+
calamity.survivor | calamity.survivor_2 | 2 | val | 11 | 21
727+
(2 rows)
728+
729+
SELECT get_part_range('calamity.survivor', 0, NULL::INT); /* OK */
730+
get_part_range
731+
----------------
732+
{1,11}
733+
(1 row)
734+
735+
EXPLAIN (COSTS OFF) SELECT * FROM calamity.survivor; /* OK */
736+
QUERY PLAN
737+
------------------------------
738+
Append
739+
-> Seq Scan on survivor_1
740+
-> Seq Scan on survivor_2
741+
(3 rows)
742+
743+
DROP TABLE calamity.survivor CASCADE;
744+
NOTICE: drop cascades to 2 other objects
745+
DROP SCHEMA calamity CASCADE;
746+
NOTICE: drop cascades to sequence calamity.survivor_seq
747+
DROP EXTENSION pg_pathman;

sql/pathman_calamity.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,44 @@ SELECT get_part_range('calamity.test_range_oid_1', NULL::INT4); /* OK */
261261
DROP TABLE calamity.test_range_oid CASCADE;
262262

263263

264+
DROP SCHEMA calamity CASCADE;
265+
DROP EXTENSION pg_pathman;
266+
267+
268+
269+
/*
270+
* ------------------------------------------
271+
* Special tests (uninitialized pg_pathman)
272+
* ------------------------------------------
273+
*/
274+
275+
CREATE SCHEMA calamity;
276+
CREATE EXTENSION pg_pathman;
277+
278+
279+
/* check function pathman_cache_search_relid() */
280+
CREATE TABLE calamity.survivor(val INT NOT NULL);
281+
SELECT create_range_partitions('calamity.survivor', 'val', 1, 10, 2);
282+
283+
DROP EXTENSION pg_pathman CASCADE;
284+
SET pg_pathman.enable = f; /* DON'T LOAD CONFIG */
285+
CREATE EXTENSION pg_pathman;
286+
SHOW pg_pathman.enable;
287+
288+
SELECT add_to_pathman_config('calamity.survivor', 'val', '10'); /* not ok */
289+
SELECT * FROM pathman_partition_list; /* not ok */
290+
SELECT get_part_range('calamity.survivor', 0, NULL::INT); /* not ok */
291+
EXPLAIN (COSTS OFF) SELECT * FROM calamity.survivor; /* OK */
292+
293+
SET pg_pathman.enable = t; /* LOAD CONFIG */
294+
295+
SELECT add_to_pathman_config('calamity.survivor', 'val', '10'); /* OK */
296+
SELECT * FROM pathman_partition_list; /* OK */
297+
SELECT get_part_range('calamity.survivor', 0, NULL::INT); /* OK */
298+
EXPLAIN (COSTS OFF) SELECT * FROM calamity.survivor; /* OK */
299+
300+
DROP TABLE calamity.survivor CASCADE;
301+
264302

265303
DROP SCHEMA calamity CASCADE;
266304
DROP EXTENSION pg_pathman;

src/init.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,8 @@ pathman_cache_search_relid(HTAB *cache_table,
117117
{
118118
switch (action)
119119
{
120-
/* May return NULL */
121120
case HASH_FIND:
122121
case HASH_REMOVE:
123-
if (!cache_table)
124-
return NULL;
125-
break;
126-
127-
/* Must return valid pointer */
128122
case HASH_ENTER:
129123
if (!cache_table)
130124
elog(ERROR, "pg_pathman is not initialized yet");
@@ -137,7 +131,7 @@ pathman_cache_search_relid(HTAB *cache_table,
137131
break;
138132
}
139133

140-
Assert(cache_table);
134+
AssertArg(cache_table);
141135

142136
/* Everything is fine */
143137
return hash_search(cache_table, (const void *) &relid, action, found);

0 commit comments

Comments
 (0)