Skip to content

Commit a3a841b

Browse files
committed
refactoring, remove column 'atttype' from table pathman_config
1 parent 6ee0093 commit a3a841b

17 files changed

+196
-150
lines changed

expected/pathman_basic.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,16 +1461,16 @@ INSERT INTO test.range_rel (dt) VALUES ('2015-06-01');
14611461
*/
14621462
ALTER TABLE test.range_rel DROP COLUMN data;
14631463
SELECT * FROM pathman.pathman_config;
1464-
partrel | attname | parttype | range_interval | expression_p | atttype
1465-
----------------+---------+----------+----------------+-------------------------------------------------------------------------------------------------------------------------+---------
1466-
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} | 1114
1464+
partrel | attname | parttype | range_interval | expression_p
1465+
----------------+---------+----------+----------------+-------------------------------------------------------------------------------------------------------------------------
1466+
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}
14671467
(1 row)
14681468

14691469
DROP TABLE test.range_rel CASCADE;
14701470
NOTICE: drop cascades to 20 other objects
14711471
SELECT * FROM pathman.pathman_config;
1472-
partrel | attname | parttype | range_interval | expression_p | atttype
1473-
---------+---------+----------+----------------+--------------+---------
1472+
partrel | attname | parttype | range_interval | expression_p
1473+
---------+---------+----------+----------------+--------------
14741474
(0 rows)
14751475

14761476
/* Check overlaps */
@@ -1632,9 +1632,9 @@ SELECT pathman.create_partitions_from_range('test."RangeRel"', 'dt', '2015-01-01
16321632
DROP TABLE test."RangeRel" CASCADE;
16331633
NOTICE: drop cascades to 5 other objects
16341634
SELECT * FROM pathman.pathman_config;
1635-
partrel | attname | parttype | range_interval | expression_p | atttype
1636-
--------------------+---------+----------+----------------+------------------------------------------------------------------------------------------------------------------------+---------
1637-
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 -1} | 23
1635+
partrel | attname | parttype | range_interval | expression_p
1636+
--------------------+---------+----------+----------------+------------------------------------------------------------------------------------------------------------------------
1637+
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 -1}
16381638
(1 row)
16391639

16401640
CREATE TABLE test."RangeRel" (

expected/pathman_calamity.out

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,20 @@ SELECT build_range_condition('calamity.part_test', 'val', NULL, 10); /* OK */
270270
(1 row)
271271

272272
/* check function validate_interval_value() */
273-
SELECT validate_interval_value(NULL, 2, '1 mon'); /* not ok */
274-
ERROR: 'atttype' should not be NULL
275-
SELECT validate_interval_value('interval'::regtype, NULL, '1 mon'); /* not ok */
276-
ERROR: 'parttype' should not be NULL
277-
SELECT validate_interval_value('int4'::regtype, 2, '1 mon'); /* not ok */
278-
ERROR: invalid input syntax for integer: "1 mon"
279-
SELECT validate_interval_value('interval'::regtype, 1, '1 mon'); /* not ok */
273+
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
274+
ERROR: relation "1" does not exist
275+
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
276+
ERROR: 'partrel' should not be NULL
277+
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon', 'cooked_expr'); /* not ok */
278+
ERROR: 'expression' should not be NULL
279+
SELECT validate_interval_value('pg_class', 'oid', 1, 'HASH', NULL); /* not ok */
280280
ERROR: interval should be NULL for HASH partitioned table
281-
SELECT validate_interval_value('interval'::regtype, 2, NULL); /* OK */
282-
validate_interval_value
283-
-------------------------
284-
t
285-
(1 row)
286-
281+
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon', NULL); /* not ok */
282+
ERROR: cannot find type name for attribute "expr" of relation "pg_class"
283+
SELECT validate_interval_value('pg_class', 'expr', 2, NULL, 'cooked_expr'); /* not ok */
284+
ERROR: unrecognized token: "cooked_expr"
285+
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH', NULL); /* not ok */
286+
ERROR: cannot find type name for attribute "expr" of relation "pg_class"
287287
/* check function validate_relname() */
288288
SELECT validate_relname('calamity.part_test');
289289
validate_relname

expected/pathman_column_type.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ SELECT context, entries FROM pathman_cache_stats ORDER BY context;
3232
/* change column's type (should flush caches) */
3333
ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC;
3434
/* check that parsed expression was cleared */
35-
SELECT * FROM pathman_config;
36-
partrel | attname | parttype | range_interval | expression_p | atttype
37-
-----------------------+---------+----------+----------------+--------------+---------
38-
test_column_type.test | val | 2 | 10 | |
35+
SELECT partrel, expression_p FROM pathman_config;
36+
partrel | expression_p
37+
-----------------------+--------------
38+
test_column_type.test |
3939
(1 row)
4040

4141
/* make sure that everything works properly */
@@ -44,11 +44,11 @@ SELECT * FROM test_column_type.test;
4444
-----
4545
(0 rows)
4646

47-
/* check that expression, atttype is changed */
48-
SELECT * FROM pathman_config;
49-
partrel | attname | parttype | range_interval | expression_p | atttype
50-
-----------------------+---------+----------+----------------+-------------------------------------------------------------------------------------------------------------------------+---------
51-
test_column_type.test | val | 2 | 10 | {VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8} | 1700
47+
/* check that expression has been built */
48+
SELECT partrel, expression_p FROM pathman_config;
49+
partrel | expression_p
50+
-----------------------+-------------------------------------------------------------------------------------------------------------------------
51+
test_column_type.test | {VAR :varno 1 :varattno 1 :vartype 1700 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8}
5252
(1 row)
5353

5454
SELECT context, entries FROM pathman_cache_stats ORDER BY context;

expected/pathman_interval.out

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ SELECT set_interval('test_interval.abc', 1000);
3737
(1 row)
3838

3939
INSERT INTO test_interval.abc VALUES (250);
40-
SELECT * FROM pathman_config;
41-
partrel | attname | parttype | range_interval | expression_p | atttype
42-
-------------------+---------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------+---------
43-
test_interval.abc | id | 2 | 1000 | {VAR :varno 1 :varattno 1 :vartype 21 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8} | 21
40+
SELECT partrel, range_interval FROM pathman_config;
41+
partrel | range_interval
42+
-------------------+----------------
43+
test_interval.abc | 1000
4444
(1 row)
4545

4646
DROP TABLE test_interval.abc CASCADE;
@@ -80,10 +80,10 @@ SELECT set_interval('test_interval.abc', 1000);
8080
(1 row)
8181

8282
INSERT INTO test_interval.abc VALUES (250);
83-
SELECT * FROM pathman_config;
84-
partrel | attname | parttype | range_interval | expression_p | atttype
85-
-------------------+---------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------+---------
86-
test_interval.abc | id | 2 | 1000 | {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8} | 23
83+
SELECT partrel, range_interval FROM pathman_config;
84+
partrel | range_interval
85+
-------------------+----------------
86+
test_interval.abc | 1000
8787
(1 row)
8888

8989
DROP TABLE test_interval.abc CASCADE;
@@ -123,10 +123,10 @@ SELECT set_interval('test_interval.abc', 1000);
123123
(1 row)
124124

125125
INSERT INTO test_interval.abc VALUES (250);
126-
SELECT * FROM pathman_config;
127-
partrel | attname | parttype | range_interval | expression_p | atttype
128-
-------------------+---------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------+---------
129-
test_interval.abc | id | 2 | 1000 | {VAR :varno 1 :varattno 1 :vartype 20 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8} | 20
126+
SELECT partrel, range_interval FROM pathman_config;
127+
partrel | range_interval
128+
-------------------+----------------
129+
test_interval.abc | 1000
130130
(1 row)
131131

132132
DROP TABLE test_interval.abc CASCADE;
@@ -156,10 +156,10 @@ SELECT set_interval('test_interval.abc', '1 month'::INTERVAL);
156156

157157
(1 row)
158158

159-
SELECT * FROM pathman_config;
160-
partrel | attname | parttype | range_interval | expression_p | atttype
161-
-------------------+---------+----------+----------------+-------------------------------------------------------------------------------------------------------------------------+---------
162-
test_interval.abc | dt | 2 | @ 1 mon | {VAR :varno 1 :varattno 1 :vartype 1082 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 8} | 1082
159+
SELECT partrel, range_interval FROM pathman_config;
160+
partrel | range_interval
161+
-------------------+----------------
162+
test_interval.abc | @ 1 mon
163163
(1 row)
164164

165165
DROP TABLE test_interval.abc CASCADE;

expected/pathman_permissions.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ NOTICE: sequence "user1_table_seq" does not exist, skipping
3333
/* Should be able to see */
3434
SET ROLE user2;
3535
SELECT * FROM pathman_config;
36-
partrel | attname | parttype | range_interval | expression_p | atttype
37-
-------------------------+---------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------+---------
38-
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} | 23
36+
partrel | attname | parttype | range_interval | expression_p
37+
-------------------------+---------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------
38+
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}
3939
(1 row)
4040

4141
SELECT * FROM pathman_config_params;

init.sql

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,40 @@
1515
* text to Datum
1616
*/
1717
CREATE OR REPLACE FUNCTION @extschema@.validate_interval_value(
18-
atttype OID,
18+
partrel REGCLASS,
19+
expression TEXT,
1920
parttype INTEGER,
20-
range_interval TEXT)
21+
range_interval TEXT,
22+
expression_p TEXT)
2123
RETURNS BOOL AS 'pg_pathman', 'validate_interval_value'
2224
LANGUAGE C;
2325

2426

2527
/*
26-
* Pathman config
27-
* partrel - regclass (relation type, stored as Oid)
28-
* attname - partitioning key
29-
* parttype - partitioning type:
30-
* 1 - HASH
31-
* 2 - RANGE
32-
* range_interval - base interval for RANGE partitioning as string
28+
* Main config.
29+
* partrel - regclass (relation type, stored as Oid)
30+
* attname - partitioning expression (key)
31+
* parttype - partitioning type: (1 - HASH, 2 - RANGE)
32+
* range_interval - base interval for RANGE partitioning as string
33+
* expression_p - cooked partitioning expression (parsed & rewritten)
3334
*/
3435
CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
3536
partrel REGCLASS NOT NULL PRIMARY KEY,
36-
attname TEXT NOT NULL, /* expression */
37+
attname TEXT NOT NULL,
3738
parttype INTEGER NOT NULL,
38-
range_interval TEXT,
39-
expression_p TEXT, /* parsed expression (until plan) */
40-
atttype OID, /* expression type */
39+
range_interval TEXT DEFAULT NULL,
40+
expression_p TEXT DEFAULT NULL,
4141

4242
/* check for allowed part types */
4343
CONSTRAINT pathman_config_parttype_check CHECK (parttype IN (1, 2)),
4444

4545
/* check for correct interval */
46-
CONSTRAINT pathman_config_interval_check CHECK (@extschema@.validate_interval_value(atttype,
47-
parttype,
48-
range_interval))
46+
CONSTRAINT pathman_config_interval_check
47+
CHECK (@extschema@.validate_interval_value(partrel,
48+
attname,
49+
parttype,
50+
range_interval,
51+
expression_p))
4952
);
5053

5154

@@ -64,11 +67,11 @@ LANGUAGE C STRICT;
6467

6568
/*
6669
* Optional parameters for partitioned tables.
67-
* partrel - regclass (relation type, stored as Oid)
68-
* enable_parent - add parent table to plan
69-
* auto - enable automatic partition creation
70-
* init_callback - text signature of cb to be executed on partition
71-
* creation
70+
* partrel - regclass (relation type, stored as Oid)
71+
* enable_parent - add parent table to plan
72+
* auto - enable automatic partition creation
73+
* init_callback - text signature of cb to be executed on partition creation
74+
* spawn_using_bgw - use background worker in order to auto create partitions
7275
*/
7376
CREATE TABLE IF NOT EXISTS @extschema@.pathman_config_params (
7477
partrel REGCLASS NOT NULL PRIMARY KEY,

sql/pathman_calamity.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ SELECT build_range_condition('calamity.part_test', 'val', 10, NULL); /* OK */
126126
SELECT build_range_condition('calamity.part_test', 'val', NULL, 10); /* OK */
127127

128128
/* check function validate_interval_value() */
129-
SELECT validate_interval_value(NULL, 2, '1 mon'); /* not ok */
130-
SELECT validate_interval_value('interval'::regtype, NULL, '1 mon'); /* not ok */
131-
SELECT validate_interval_value('int4'::regtype, 2, '1 mon'); /* not ok */
132-
SELECT validate_interval_value('interval'::regtype, 1, '1 mon'); /* not ok */
133-
SELECT validate_interval_value('interval'::regtype, 2, NULL); /* OK */
129+
SELECT validate_interval_value(1::REGCLASS, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
130+
SELECT validate_interval_value(NULL, 'expr', 2, '1 mon', 'cooked_expr'); /* not ok */
131+
SELECT validate_interval_value('pg_class', NULL, 2, '1 mon', 'cooked_expr'); /* not ok */
132+
SELECT validate_interval_value('pg_class', 'oid', 1, 'HASH', NULL); /* not ok */
133+
SELECT validate_interval_value('pg_class', 'expr', 2, '1 mon', NULL); /* not ok */
134+
SELECT validate_interval_value('pg_class', 'expr', 2, NULL, 'cooked_expr'); /* not ok */
135+
SELECT validate_interval_value('pg_class', 'EXPR', 1, 'HASH', NULL); /* not ok */
134136

135137
/* check function validate_relname() */
136138
SELECT validate_relname('calamity.part_test');

sql/pathman_column_type.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ SELECT context, entries FROM pathman_cache_stats ORDER BY context;
2121
ALTER TABLE test_column_type.test ALTER val TYPE NUMERIC;
2222

2323
/* check that parsed expression was cleared */
24-
SELECT * FROM pathman_config;
24+
SELECT partrel, expression_p FROM pathman_config;
2525

2626
/* make sure that everything works properly */
2727
SELECT * FROM test_column_type.test;
2828

29-
/* check that expression, atttype is changed */
30-
SELECT * FROM pathman_config;
29+
/* check that expression has been built */
30+
SELECT partrel, expression_p FROM pathman_config;
3131

3232
SELECT context, entries FROM pathman_cache_stats ORDER BY context;
3333

sql/pathman_interval.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ WHERE partrel = 'test_interval.abc'::REGCLASS;
2626
/* Set a normal interval */
2727
SELECT set_interval('test_interval.abc', 1000);
2828
INSERT INTO test_interval.abc VALUES (250);
29-
SELECT * FROM pathman_config;
29+
SELECT partrel, range_interval FROM pathman_config;
3030

3131
DROP TABLE test_interval.abc CASCADE;
3232

@@ -52,7 +52,7 @@ WHERE partrel = 'test_interval.abc'::REGCLASS;
5252
/* Set a normal interval */
5353
SELECT set_interval('test_interval.abc', 1000);
5454
INSERT INTO test_interval.abc VALUES (250);
55-
SELECT * FROM pathman_config;
55+
SELECT partrel, range_interval FROM pathman_config;
5656

5757
DROP TABLE test_interval.abc CASCADE;
5858

@@ -78,7 +78,7 @@ WHERE partrel = 'test_interval.abc'::REGCLASS;
7878
/* Set a normal interval */
7979
SELECT set_interval('test_interval.abc', 1000);
8080
INSERT INTO test_interval.abc VALUES (250);
81-
SELECT * FROM pathman_config;
81+
SELECT partrel, range_interval FROM pathman_config;
8282

8383
DROP TABLE test_interval.abc CASCADE;
8484

@@ -95,7 +95,7 @@ SELECT set_interval('test_interval.abc', '1 second'::INTERVAL);
9595
/* Set a normal interval */
9696
SELECT set_interval('test_interval.abc', '1 month'::INTERVAL);
9797

98-
SELECT * FROM pathman_config;
98+
SELECT partrel, range_interval FROM pathman_config;
9999

100100
DROP TABLE test_interval.abc CASCADE;
101101

src/include/partition_creation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ Oid create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
3030

3131
/* Create one RANGE partition */
3232
Oid create_single_range_partition_internal(Oid parent_relid,
33-
Oid value_type,
3433
const Bound *start_value,
3534
const Bound *end_value,
35+
Oid value_type,
3636
RangeVar *partition_rv,
3737
char *tablespace);
3838

src/include/pathman.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@
4444
* Definitions for the "pathman_config" table.
4545
*/
4646
#define PATHMAN_CONFIG "pathman_config"
47-
#define Natts_pathman_config 6
47+
#define Natts_pathman_config 5
4848
#define Anum_pathman_config_partrel 1 /* partitioned relation (regclass) */
4949
#define Anum_pathman_config_expression 2 /* partition expression (original) */
5050
#define Anum_pathman_config_parttype 3 /* partitioning type (1|2) */
5151
#define Anum_pathman_config_range_interval 4 /* interval for RANGE pt. (text) */
5252
#define Anum_pathman_config_expression_p 5 /* parsed partitioning expression (text) */
53-
#define Anum_pathman_config_atttype 6 /* partitioned atttype (oid) */
5453

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

src/include/relation_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Node *parse_partitioning_expression(const Oid relid,
288288
char **query_string_out,
289289
Node **parsetree_out);
290290

291-
Datum plan_partitioning_expression(const Oid relid,
291+
Datum cook_partitioning_expression(const Oid relid,
292292
const char *expr_cstr,
293293
Oid *expr_type);
294294

0 commit comments

Comments
 (0)