10
10
11
11
/*
12
12
* Pathman config
13
- * relname - schema qualified relation name
14
- * attname - partitioning key
15
- * parttype - partitioning type:
16
- * 1 - HASH
17
- * 2 - RANGE
18
- * range_interval - base interval for RANGE partitioning in string representation
13
+ * partrel - regclass (relation type, stored as Oid)
14
+ * attname - partitioning key
15
+ * parttype - partitioning type:
16
+ * 1 - HASH
17
+ * 2 - RANGE
18
+ * range_interval - base interval for RANGE partitioning as string
19
19
*/
20
20
CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
21
21
id SERIAL PRIMARY KEY ,
22
- relname VARCHAR (127 ),
23
- attname VARCHAR (127 ),
24
- parttype INTEGER ,
25
- range_interval TEXT
22
+ partrel REGCLASS NOT NULL ,
23
+ attname TEXT NOT NULL ,
24
+ parttype INTEGER NOT NULL ,
25
+ range_interval TEXT ,
26
+
27
+ CHECK (parttype >= 1 OR parttype <= 2 ) /* check for allowed part types */
26
28
);
29
+
27
30
SELECT pg_catalog .pg_extension_config_dump (' @extschema@.pathman_config' , ' ' );
28
31
29
32
CREATE OR REPLACE FUNCTION @extschema@.on_create_partitions(relid OID )
@@ -112,13 +115,13 @@ LANGUAGE plpgsql;
112
115
/*
113
116
* Disable pathman partitioning for specified relation
114
117
*/
115
- CREATE OR REPLACE FUNCTION @extschema@.disable_partitioning(IN relation TEXT )
118
+ CREATE OR REPLACE FUNCTION @extschema@.disable_partitioning(relation regclass )
116
119
RETURNS VOID AS
117
120
$$
118
121
BEGIN
119
122
relation := @extschema@.validate_relname(relation);
120
123
121
- DELETE FROM @extschema@.pathman_config WHERE relname = relation;
124
+ DELETE FROM @extschema@.pathman_config WHERE partrel = relation;
122
125
PERFORM @extschema@.drop_triggers(relation);
123
126
124
127
/* Notify backend about changes */
@@ -176,7 +179,7 @@ DECLARE
176
179
v_rec RECORD;
177
180
is_referenced BOOLEAN ;
178
181
BEGIN
179
- IF EXISTS (SELECT * FROM @extschema@.pathman_config WHERE relname::regclass = p_relation) THEN
182
+ IF EXISTS (SELECT * FROM @extschema@.pathman_config WHERE partrel = p_relation) THEN
180
183
RAISE EXCEPTION ' Relation "%" has already been partitioned' , p_relation;
181
184
END IF;
182
185
298
301
LANGUAGE plpgsql;
299
302
300
303
/*
301
- * DDL trigger that deletes entry from pathman_config
304
+ * DDL trigger that deletes entry from pathman_config table
302
305
*/
303
306
CREATE OR REPLACE FUNCTION @extschema@.pathman_ddl_trigger_func()
304
307
RETURNS event_trigger AS
@@ -307,11 +310,12 @@ DECLARE
307
310
obj record;
308
311
BEGIN
309
312
FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects() as events
310
- JOIN @extschema@.pathman_config as cfg ON cfg .relname = events .object_identity
313
+ JOIN @extschema@.pathman_config as cfg
314
+ ON partrel::oid = events .objid
311
315
LOOP
312
316
IF obj .object_type = ' table' THEN
313
- EXECUTE ' DELETE FROM @extschema@.pathman_config WHERE relname = $1'
314
- USING obj .object_identity ;
317
+ EXECUTE ' DELETE FROM @extschema@.pathman_config WHERE partrel = $1'
318
+ USING obj .objid ;
315
319
END IF;
316
320
END LOOP;
317
321
END
@@ -375,7 +379,7 @@ BEGIN
375
379
PERFORM @extschema@.drop_triggers(relation);
376
380
377
381
WITH config_num_deleted AS (DELETE FROM @extschema@.pathman_config
378
- WHERE relname::regclass = relation
382
+ WHERE partrel = relation
379
383
RETURNING * )
380
384
SELECT count (* ) from config_num_deleted INTO conf_num_del;
381
385
@@ -417,3 +421,15 @@ RETURNS OID AS 'pg_pathman', 'get_type_hash_func' LANGUAGE C STRICT;
417
421
*/
418
422
CREATE OR REPLACE FUNCTION @extschema@.get_hash(INTEGER , INTEGER )
419
423
RETURNS INTEGER AS ' pg_pathman' , ' get_hash' LANGUAGE C STRICT;
424
+
425
+
426
+ /*
427
+ * Build check constraint name for a specified relation's column
428
+ */
429
+ CREATE OR REPLACE FUNCTION @extschema@.build_check_constraint_name(REGCLASS, INT2)
430
+ RETURNS TEXT AS ' pg_pathman' , ' build_check_constraint_name_attnum'
431
+ LANGUAGE C STRICT;
432
+
433
+ CREATE OR REPLACE FUNCTION @extschema@.build_check_constraint_name(REGCLASS, TEXT )
434
+ RETURNS TEXT AS ' pg_pathman' , ' build_check_constraint_name_attname'
435
+ LANGUAGE C STRICT;
0 commit comments