Skip to content

Commit 3d46cbf

Browse files
committed
pathman: full qualified names for hash partitioning
1 parent da4d209 commit 3d46cbf

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

contrib/pathman/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ load_part_relations_hashtable(bool reinitialize)
6767

6868
ret = SPI_exec("SELECT pg_class.relfilenode, pg_attribute.attnum, pathman_config.parttype, pg_attribute.atttypid "
6969
"FROM pathman_config "
70-
"JOIN pg_class ON pg_class.relname = pathman_config.relname "
70+
"JOIN pg_class ON pg_class.relfilenode = pathman_config.relname::regclass::oid "
7171
"JOIN pg_attribute ON pg_attribute.attname = pathman_config.attname "
7272
"AND attrelid = pg_class.relfilenode", 0);
7373
proc = SPI_processed;

contrib/pathman/sql/hash.sql

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,8 @@ CREATE OR REPLACE FUNCTION create_hash_partitions(
77
, partitions_count INTEGER
88
) RETURNS VOID AS
99
$$
10-
DECLARE
11-
row INTEGER;
12-
q TEXT;
13-
relid INTEGER;
14-
attnum INTEGER;
15-
child_oid INTEGER;
1610
BEGIN
17-
relid := relfilenode FROM pg_class WHERE relname = relation;
18-
attnum := pg_attribute.attnum FROM pg_attribute WHERE attrelid = relid AND attname = attribute;
11+
relation := lower(relation);
1912

2013
IF EXISTS (SELECT * FROM pathman_config WHERE relname = relation) THEN
2114
RAISE EXCEPTION 'Reltion "%s" has already been partitioned', relation;
@@ -38,11 +31,6 @@ BEGIN
3831
, attribute
3932
, partitions_count
4033
, partnum);
41-
42-
-- EXECUTE format('CREATE TABLE %s_%s () INHERITS (%1$s)', relation, partnum);
43-
-- child_oid := relfilenode FROM pg_class WHERE relname = format('%s_%s', relation, partnum);
44-
-- INSERT INTO pg_pathman_hash_rels (parent, hash, child)
45-
-- VALUES (relation, partnum, format('%s_%s', relation, partnum));
4634
END LOOP;
4735
INSERT INTO pathman_config (relname, attname, parttype)
4836
VALUES (relation, attribute, 1);
@@ -51,6 +39,7 @@ BEGIN
5139
PERFORM create_hash_insert_trigger(relation, attribute, partitions_count);
5240
/* TODO: вернуть */
5341
-- PERFORM create_hash_update_trigger(relation, attribute, partitions_count);
42+
5443
/* Notify backend about changes */
5544
PERFORM on_create_partitions(relid);
5645
END
@@ -80,7 +69,6 @@ DECLARE
8069
CREATE TRIGGER %s_insert_trigger
8170
BEFORE INSERT ON %1$s
8271
FOR EACH ROW EXECUTE PROCEDURE %1$s_hash_insert_trigger_func();';
83-
relid INTEGER;
8472
fields TEXT;
8573
fields_format TEXT;
8674
insert_stmt TEXT;
@@ -89,23 +77,21 @@ BEGIN
8977
PERFORM drop_hash_triggers(relation);
9078

9179
/* determine fields for INSERT */
92-
relid := relfilenode FROM pg_class WHERE relname = relation;
9380
SELECT string_agg('NEW.' || attname, ', '), string_agg('$' || attnum, ', ')
9481
FROM pg_attribute
95-
WHERE attrelid=relid AND attnum>0
82+
WHERE attrelid=relation::regclass::oid AND attnum>0
9683
INTO fields, fields_format;
9784

9885
/* generate INSERT statement for trigger */
9986
insert_stmt = format('EXECUTE format(''INSERT INTO %s_%%s VALUES (%s)'', hash) USING %s;'
10087
, relation
10188
, fields_format
10289
, fields);
103-
-- insert_stmt = format('EXECUTE format(''INSERT INTO %s_%%s VALUES (NEW.*)'', hash);', relation);
10490

10591
/* format and create new trigger for relation */
10692
func := format(func, relation, attr, partitions_count, insert_stmt);
10793

108-
trigger := format(trigger, relation);
94+
trigger := format(trigger, relation::regclass::text);
10995
EXECUTE func;
11096
EXECUTE trigger;
11197
END
@@ -139,8 +125,8 @@ CREATE OR REPLACE FUNCTION drop_hash_triggers(IN relation TEXT)
139125
RETURNS VOID AS
140126
$$
141127
BEGIN
142-
EXECUTE format('DROP TRIGGER IF EXISTS %s_insert_trigger ON %1$s', relation);
143-
EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_insert_trigger_func()', relation);
128+
EXECUTE format('DROP TRIGGER IF EXISTS %s_insert_trigger ON %1$s', relation::regclass::text);
129+
EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_insert_trigger_func()', relation::regclass::text);
144130
-- EXECUTE format('DROP TRIGGER IF EXISTS %s_update_trigger ON %1$s', relation);
145131
-- EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_update_trigger_func()', relation);
146132
END

0 commit comments

Comments
 (0)