Skip to content

Commit 497ab20

Browse files
committed
Return private function for cached cooked key to fix tests coverage
1 parent 38b48da commit 497ab20

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

expected/pathman_column_type.out

+21-2
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,33 @@ SELECT context, entries FROM pathman_cache_stats ORDER BY context;
2828
partition status cache | 3
2929
(4 rows)
3030

31-
/* change column's type (should flush caches) */
31+
/*
32+
* Get parsed and analyzed expression.
33+
*/
34+
CREATE FUNCTION get_cached_partition_cooked_key(REGCLASS)
35+
RETURNS TEXT AS 'pg_pathman', 'get_cached_partition_cooked_key_pl'
36+
LANGUAGE C STRICT;
3237
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
3338
get_partition_cooked_key
3439
-----------------------------------------------------------------------------------------------------------------------
3540
{VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
3641
(1 row)
3742

43+
SELECT get_cached_partition_cooked_key('test_column_type.test'::REGCLASS);
44+
get_cached_partition_cooked_key
45+
-----------------------------------------------------------------------------------------------------------------------
46+
{VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
47+
(1 row)
48+
3849
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
3950
get_partition_key_type
4051
------------------------
4152
integer
4253
(1 row)
4354

55+
/* change column's type (should also flush caches) */
4456
ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC;
45-
/* check that expression has been built */
57+
/* check that correct expression has been built */
4658
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
4759
get_partition_key_type
4860
------------------------
@@ -55,6 +67,13 @@ SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
5567
{VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
5668
(1 row)
5769

70+
SELECT get_cached_partition_cooked_key('test_column_type.test'::REGCLASS);
71+
get_cached_partition_cooked_key
72+
-------------------------------------------------------------------------------------------------------------------------
73+
{VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
74+
(1 row)
75+
76+
DROP FUNCTION get_cached_partition_cooked_key(REGCLASS);
5877
/* make sure that everything works properly */
5978
SELECT * FROM test_column_type.test;
6079
val

sql/pathman_column_type.sql

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@ SELECT create_range_partitions('test_column_type.test', 'val', 1, 10, 10);
1717
SELECT * FROM test_column_type.test;
1818
SELECT context, entries FROM pathman_cache_stats ORDER BY context;
1919

20-
/* change column's type (should flush caches) */
20+
/*
21+
* Get parsed and analyzed expression.
22+
*/
23+
CREATE FUNCTION get_cached_partition_cooked_key(REGCLASS)
24+
RETURNS TEXT AS 'pg_pathman', 'get_cached_partition_cooked_key_pl'
25+
LANGUAGE C STRICT;
26+
2127
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
28+
SELECT get_cached_partition_cooked_key('test_column_type.test'::REGCLASS);
2229
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
30+
31+
/* change column's type (should also flush caches) */
2332
ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC;
2433

25-
/* check that expression has been built */
34+
/* check that correct expression has been built */
2635
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
2736
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
37+
SELECT get_cached_partition_cooked_key('test_column_type.test'::REGCLASS);
38+
DROP FUNCTION get_cached_partition_cooked_key(REGCLASS);
2839

2940
/* make sure that everything works properly */
3041
SELECT * FROM test_column_type.test;

src/pl_funcs.c

+21
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
PG_FUNCTION_INFO_V1( get_number_of_partitions_pl );
4949
PG_FUNCTION_INFO_V1( get_partition_key_type_pl );
5050
PG_FUNCTION_INFO_V1( get_partition_cooked_key_pl );
51+
PG_FUNCTION_INFO_V1( get_cached_partition_cooked_key_pl );
5152
PG_FUNCTION_INFO_V1( get_parent_of_partition_pl );
5253
PG_FUNCTION_INFO_V1( get_base_type_pl );
5354
PG_FUNCTION_INFO_V1( get_tablespace_pl );
@@ -171,6 +172,26 @@ get_partition_cooked_key_pl(PG_FUNCTION_ARGS)
171172
PG_RETURN_TEXT_P(CStringGetTextDatum(cooked_cstr));
172173
}
173174

175+
/*
176+
* Return cached cooked partition key.
177+
*
178+
* Used in tests for invalidation.
179+
*/
180+
Datum
181+
get_cached_partition_cooked_key_pl(PG_FUNCTION_ARGS)
182+
{
183+
Oid relid = PG_GETARG_OID(0);
184+
PartRelationInfo *prel;
185+
Datum res;
186+
187+
prel = get_pathman_relation_info(relid);
188+
shout_if_prel_is_invalid(relid, prel, PT_ANY);
189+
res = CStringGetTextDatum(nodeToString(prel->expr));
190+
close_pathman_relation_info(prel);
191+
192+
PG_RETURN_TEXT_P(res);
193+
}
194+
174195
/*
175196
* Extract basic type of a domain.
176197
*/

0 commit comments

Comments
 (0)