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

Commit e9041c7

Browse files
committed
Remove cooked_expr column from pathman_config
1 parent b5f7633 commit e9041c7

16 files changed

+132
-197
lines changed

expected/pathman_basic.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,16 +1438,16 @@ INSERT INTO test.range_rel (dt) VALUES ('2015-06-01');
14381438
*/
14391439
ALTER TABLE test.range_rel DROP COLUMN data;
14401440
SELECT * FROM pathman.pathman_config;
1441-
partrel | expr | parttype | range_interval | cooked_expr
1442-
----------------+------+----------+----------------+-------------------------------------------------------------------------------------------------------------------------
1443-
test.range_rel | dt | 2 | @ 10 days | {VAR :varno 1 :varattno 2 :vartype 1114 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 2 :location 8}
1441+
partrel | expr | parttype | range_interval
1442+
----------------+------+----------+----------------
1443+
test.range_rel | dt | 2 | @ 10 days
14441444
(1 row)
14451445

14461446
DROP TABLE test.range_rel CASCADE;
14471447
NOTICE: drop cascades to 21 other objects
14481448
SELECT * FROM pathman.pathman_config;
1449-
partrel | expr | parttype | range_interval | cooked_expr
1450-
---------+------+----------+----------------+-------------
1449+
partrel | expr | parttype | range_interval
1450+
---------+------+----------+----------------
14511451
(0 rows)
14521452

14531453
/* Check overlaps */
@@ -1544,9 +1544,9 @@ SELECT pathman.split_range_partition('test."RangeRel_1"', '2015-01-01'::DATE);
15441544
DROP TABLE test."RangeRel" CASCADE;
15451545
NOTICE: drop cascades to 6 other objects
15461546
SELECT * FROM pathman.pathman_config;
1547-
partrel | expr | parttype | range_interval | cooked_expr
1548-
--------------------+------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------
1549-
test.num_range_rel | id | 2 | 1000 | {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
1547+
partrel | expr | parttype | range_interval
1548+
--------------------+------+----------+----------------
1549+
test.num_range_rel | id | 2 | 1000
15501550
(1 row)
15511551

15521552
CREATE TABLE test."RangeRel" (

expected/pathman_calamity.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,21 +281,21 @@ SELECT build_range_condition('calamity.part_test', 'val', NULL, 10); /* OK */
281281
(1 row)
282282

283283
/* check function validate_interval_value() */
284-
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
284+
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon'); /* not ok */
285285
ERROR: relation "1" does not exist
286-
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
286+
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon'); /* not ok */
287287
ERROR: 'partrel' should not be NULL
288-
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon', 'cooked_expr'); /* not ok */
288+
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon'); /* not ok */
289289
ERROR: 'expression' should not be NULL
290-
SELECT validate_interval_value('pg_class', 'relname', NULL, '1 mon', 'cooked_expr'); /* not ok */
290+
SELECT validate_interval_value('pg_class', 'relname', NULL, '1 mon'); /* not ok */
291291
ERROR: 'parttype' should not be NULL
292-
SELECT validate_interval_value('pg_class', 'relname', 1, 'HASH', NULL); /* not ok */
292+
SELECT validate_interval_value('pg_class', 'relname', 1, 'HASH'); /* not ok */
293293
ERROR: interval should be NULL for HASH partitioned table
294-
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon', NULL); /* not ok */
294+
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon'); /* not ok */
295295
ERROR: failed to analyze partitioning expression "expr"
296-
SELECT validate_interval_value('pg_class', 'expr', 2, NULL, 'cooked_expr'); /* not ok */
297-
ERROR: unrecognized token: "cooked_expr"
298-
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH', NULL); /* not ok */
296+
SELECT validate_interval_value('pg_class', 'expr', 2, NULL); /* not ok */
297+
ERROR: failed to analyze partitioning expression "expr"
298+
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH'); /* not ok */
299299
ERROR: failed to analyze partitioning expression "EXPR"
300300
/* check function validate_relname() */
301301
SELECT validate_relname('calamity.part_test');

expected/pathman_column_type.out

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,30 @@ SELECT context, entries FROM pathman_cache_stats ORDER BY context;
2929
(4 rows)
3030

3131
/* change column's type (should flush caches) */
32+
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
33+
get_partition_cooked_key
34+
-----------------------------------------------------------------------------------------------------------------------
35+
{VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
36+
(1 row)
37+
38+
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
39+
get_partition_key_type
40+
------------------------
41+
integer
42+
(1 row)
43+
3244
ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC;
33-
/* check that parsed expression was cleared */
34-
SELECT partrel, cooked_expr FROM pathman_config;
35-
partrel | cooked_expr
36-
-----------------------+-------------
37-
test_column_type.test |
45+
/* check that expression has been built */
46+
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
47+
get_partition_key_type
48+
------------------------
49+
numeric
50+
(1 row)
51+
52+
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
53+
get_partition_cooked_key
54+
-------------------------------------------------------------------------------------------------------------------------
55+
{VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
3856
(1 row)
3957

4058
/* make sure that everything works properly */
@@ -43,13 +61,6 @@ SELECT * FROM test_column_type.test;
4361
-----
4462
(0 rows)
4563

46-
/* check that expression has been built */
47-
SELECT partrel, cooked_expr FROM pathman_config;
48-
partrel | cooked_expr
49-
-----------------------+-------------------------------------------------------------------------------------------------------------------------
50-
test_column_type.test | {VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
51-
(1 row)
52-
5364
SELECT context, entries FROM pathman_cache_stats ORDER BY context;
5465
context | entries
5566
-------------------------+---------

expected/pathman_permissions.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ SELECT create_range_partitions('permissions.user1_table', 'id', 1, 10, 2);
4444
/* Should be able to see */
4545
SET ROLE user2;
4646
SELECT * FROM pathman_config;
47-
partrel | expr | parttype | range_interval | cooked_expr
48-
-------------------------+------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------
49-
permissions.user1_table | id | 2 | 10 | {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
47+
partrel | expr | parttype | range_interval
48+
-------------------------+------+----------+----------------
49+
permissions.user1_table | id | 2 | 10
5050
(1 row)
5151

5252
SELECT * FROM pathman_config_params;

init.sql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ CREATE OR REPLACE FUNCTION @extschema@.validate_interval_value(
1818
partrel REGCLASS,
1919
expr TEXT,
2020
parttype INTEGER,
21-
range_interval TEXT,
22-
cooked_expr TEXT)
21+
range_interval TEXT)
2322
RETURNS BOOL AS 'pg_pathman', 'validate_interval_value'
2423
LANGUAGE C;
2524

@@ -37,7 +36,6 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
3736
expr TEXT NOT NULL,
3837
parttype INTEGER NOT NULL,
3938
range_interval TEXT DEFAULT NULL,
40-
cooked_expr TEXT DEFAULT NULL,
4139

4240
/* check for allowed part types */
4341
CONSTRAINT pathman_config_parttype_check CHECK (parttype IN (1, 2)),
@@ -47,8 +45,7 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
4745
CHECK (@extschema@.validate_interval_value(partrel,
4846
expr,
4947
parttype,
50-
range_interval,
51-
cooked_expr))
48+
range_interval))
5249
);
5350

5451

@@ -674,6 +671,14 @@ CREATE OR REPLACE FUNCTION @extschema@.get_partition_key_type(
674671
RETURNS REGTYPE AS 'pg_pathman', 'get_partition_key_type_pl'
675672
LANGUAGE C STRICT;
676673

674+
/*
675+
* Get parsed and analyzed expression.
676+
*/
677+
CREATE OR REPLACE FUNCTION @extschema@.get_partition_cooked_key(
678+
parent_relid REGCLASS)
679+
RETURNS TEXT AS 'pg_pathman', 'get_partition_cooked_key_pl'
680+
LANGUAGE C STRICT;
681+
677682
/*
678683
* Get partitioning type.
679684
*/

pg_pathman--1.4--1.5.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
ALTER TABLE @extschema@.pathman_config DROP CONSTRAINT pathman_config_interval_check;
2+
3+
DROP FUNCTION @extschema@.validate_interval_value(REGCLASS, TEXT, INTEGER,
4+
TEXT, TEXT);
5+
CREATE OR REPLACE FUNCTION @extschema@.validate_interval_value(
6+
partrel REGCLASS,
7+
expr TEXT,
8+
parttype INTEGER,
9+
range_interval TEXT)
10+
RETURNS BOOL AS 'pg_pathman', 'validate_interval_value'
11+
LANGUAGE C;
12+
13+
ALTER TABLE @extschema@.pathman_config DROP COLUMN cooked_expr;
14+
ALTER TABLE @extschema@.pathman_config ADD CONSTRAINT pathman_config_interval_check
15+
CHECK (@extschema@.validate_interval_value(partrel,
16+
expr,
17+
parttype,
18+
range_interval));
19+
20+
/*
21+
* Get parsed and analyzed expression.
22+
*/
23+
CREATE OR REPLACE FUNCTION @extschema@.get_partition_cooked_key(
24+
parent_relid REGCLASS)
25+
RETURNS TEXT AS 'pg_pathman', 'get_partition_cooked_key_pl'
26+
LANGUAGE C STRICT;
27+
128
/*
229
* Add new partition
330
*/

sql/pathman_calamity.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ SELECT build_range_condition('calamity.part_test', 'val', 10, NULL); /* OK */
132132
SELECT build_range_condition('calamity.part_test', 'val', NULL, 10); /* OK */
133133

134134
/* check function validate_interval_value() */
135-
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
136-
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
137-
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon', 'cooked_expr'); /* not ok */
138-
SELECT validate_interval_value('pg_class', 'relname', NULL, '1 mon', 'cooked_expr'); /* not ok */
139-
SELECT validate_interval_value('pg_class', 'relname', 1, 'HASH', NULL); /* not ok */
140-
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon', NULL); /* not ok */
141-
SELECT validate_interval_value('pg_class', 'expr', 2, NULL, 'cooked_expr'); /* not ok */
142-
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH', NULL); /* not ok */
135+
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon'); /* not ok */
136+
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon'); /* not ok */
137+
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon'); /* not ok */
138+
SELECT validate_interval_value('pg_class', 'relname', NULL, '1 mon'); /* not ok */
139+
SELECT validate_interval_value('pg_class', 'relname', 1, 'HASH'); /* not ok */
140+
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon'); /* not ok */
141+
SELECT validate_interval_value('pg_class', 'expr', 2, NULL); /* not ok */
142+
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH'); /* not ok */
143143

144144
/* check function validate_relname() */
145145
SELECT validate_relname('calamity.part_test');

sql/pathman_column_type.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ SELECT * FROM test_column_type.test;
1818
SELECT context, entries FROM pathman_cache_stats ORDER BY context;
1919

2020
/* change column's type (should flush caches) */
21+
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
22+
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
2123
ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC;
2224

23-
/* check that parsed expression was cleared */
24-
SELECT partrel, cooked_expr FROM pathman_config;
25+
/* check that expression has been built */
26+
SELECT get_partition_key_type('test_column_type.test'::REGCLASS);
27+
SELECT get_partition_cooked_key('test_column_type.test'::REGCLASS);
2528

2629
/* make sure that everything works properly */
2730
SELECT * FROM test_column_type.test;
2831

29-
/* check that expression has been built */
30-
SELECT partrel, cooked_expr FROM pathman_config;
31-
3232
SELECT context, entries FROM pathman_cache_stats ORDER BY context;
3333

3434
/* check insert dispatching */

src/hooks.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,6 @@ pathman_process_utility_hook(Node *first_arg,
949949
" of table \"%s\" partitioned by HASH",
950950
get_attname_compat(relation_oid, attr_number),
951951
get_rel_name(relation_oid))));
952-
953-
/* Don't forget to invalidate parsed partitioning expression */
954-
pathman_config_invalidate_parsed_expression(relation_oid);
955952
}
956953
}
957954

src/include/pathman.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@
4545
* Definitions for the "pathman_config" table.
4646
*/
4747
#define PATHMAN_CONFIG "pathman_config"
48-
#define Natts_pathman_config 5
48+
#define Natts_pathman_config 4
4949
#define Anum_pathman_config_partrel 1 /* partitioned relation (regclass) */
5050
#define Anum_pathman_config_expr 2 /* partition expression (original) */
5151
#define Anum_pathman_config_parttype 3 /* partitioning type (1|2) */
5252
#define Anum_pathman_config_range_interval 4 /* interval for RANGE pt. (text) */
53-
#define Anum_pathman_config_cooked_expr 5 /* parsed partitioning expression (text) */
5453

5554
/* type modifier (typmod) for 'range_interval' */
5655
#define PATHMAN_CONFIG_interval_typmod -1

src/include/relation_info.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,27 +384,13 @@ Node *parse_partitioning_expression(const Oid relid,
384384
char **query_string_out,
385385
Node **parsetree_out);
386386

387-
Datum cook_partitioning_expression(const Oid relid,
387+
Node *cook_partitioning_expression(const Oid relid,
388388
const char *expr_cstr,
389389
Oid *expr_type);
390390

391391
char *canonicalize_partitioning_expression(const Oid relid,
392392
const char *expr_cstr);
393393

394-
/* Partitioning expression routines */
395-
Node *parse_partitioning_expression(const Oid relid,
396-
const char *expr_cstr,
397-
char **query_string_out,
398-
Node **parsetree_out);
399-
400-
Datum cook_partitioning_expression(const Oid relid,
401-
const char *expr_cstr,
402-
Oid *expr_type);
403-
404-
char *canonicalize_partitioning_expression(const Oid relid,
405-
const char *expr_cstr);
406-
407-
408394
/* Global invalidation routines */
409395
void delay_pathman_shutdown(void);
410396
void finish_delayed_invalidation(void);

src/init.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -675,66 +675,6 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
675675
return contains_rel;
676676
}
677677

678-
/* Invalidate parsed partitioning expression in PATHMAN_CONFIG */
679-
void
680-
pathman_config_invalidate_parsed_expression(Oid relid)
681-
{
682-
ItemPointerData iptr; /* pointer to tuple */
683-
Datum values[Natts_pathman_config];
684-
bool nulls[Natts_pathman_config];
685-
686-
/* Check that PATHMAN_CONFIG table contains this relation */
687-
if (pathman_config_contains_relation(relid, values, nulls, NULL, &iptr))
688-
{
689-
Relation rel;
690-
HeapTuple new_htup;
691-
692-
/* Reset parsed expression */
693-
values[Anum_pathman_config_cooked_expr - 1] = (Datum) 0;
694-
nulls[Anum_pathman_config_cooked_expr - 1] = true;
695-
696-
rel = heap_open(get_pathman_config_relid(false), RowExclusiveLock);
697-
698-
/* Form new tuple and perform an update */
699-
new_htup = heap_form_tuple(RelationGetDescr(rel), values, nulls);
700-
CatalogTupleUpdate(rel, &iptr, new_htup);
701-
heap_freetuple(new_htup);
702-
703-
heap_close(rel, RowExclusiveLock);
704-
}
705-
}
706-
707-
/* Refresh parsed partitioning expression in PATHMAN_CONFIG */
708-
void
709-
pathman_config_refresh_parsed_expression(Oid relid,
710-
Datum *values,
711-
bool *isnull,
712-
ItemPointer iptr)
713-
{
714-
char *expr_cstr;
715-
Datum expr_datum;
716-
717-
Relation rel;
718-
HeapTuple htup_new;
719-
720-
/* get and parse expression */
721-
expr_cstr = TextDatumGetCString(values[Anum_pathman_config_expr - 1]);
722-
expr_datum = cook_partitioning_expression(relid, expr_cstr, NULL);
723-
pfree(expr_cstr);
724-
725-
/* prepare tuple values */
726-
values[Anum_pathman_config_cooked_expr - 1] = expr_datum;
727-
isnull[Anum_pathman_config_cooked_expr - 1] = false;
728-
729-
rel = heap_open(get_pathman_config_relid(false), RowExclusiveLock);
730-
731-
htup_new = heap_form_tuple(RelationGetDescr(rel), values, isnull);
732-
CatalogTupleUpdate(rel, iptr, htup_new);
733-
734-
heap_close(rel, RowExclusiveLock);
735-
}
736-
737-
738678
/*
739679
* Loads additional pathman parameters like 'enable_parent'
740680
* or 'auto' from PATHMAN_CONFIG_PARAMS.

src/partition_creation.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,20 +1854,15 @@ build_partitioning_expression(Oid parent_relid,
18541854

18551855
expr_cstr = TextDatumGetCString(values[Anum_pathman_config_expr - 1]);
18561856
expr = parse_partitioning_expression(parent_relid, expr_cstr, NULL, NULL);
1857-
pfree(expr_cstr);
18581857

18591858
/* We need expression type for hash functions */
18601859
if (expr_type)
18611860
{
1862-
char *expr_p_cstr;
1863-
1864-
/* We can safely assume that this field will always remain not null */
1865-
Assert(!isnull[Anum_pathman_config_cooked_expr - 1]);
1866-
expr_p_cstr =
1867-
TextDatumGetCString(values[Anum_pathman_config_cooked_expr - 1]);
1861+
Node *expr;
1862+
expr = cook_partitioning_expression(parent_relid, expr_cstr, NULL);
18681863

18691864
/* Finally return expression type */
1870-
*expr_type = exprType(stringToNode(expr_p_cstr));
1865+
*expr_type = exprType(expr);
18711866
}
18721867

18731868
if (columns)
@@ -1877,5 +1872,6 @@ build_partitioning_expression(Oid parent_relid,
18771872
extract_column_names(expr, columns);
18781873
}
18791874

1875+
pfree(expr_cstr);
18801876
return expr;
18811877
}

0 commit comments

Comments
 (0)