Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57305e2

Browse files
committed
[WIP] huge refactoring, use local process cache instead of shared memory
1 parent08b0125 commit57305e2

29 files changed

+2093
-1530
lines changed

‎Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# contrib/pg_pathman/Makefile
22

33
MODULE_big = pg_pathman
4-
OBJS = src/init.o src/utils.o src/partition_filter.o src/runtimeappend.o src/runtime_merge_append.o src/pg_pathman.o src/dsm_array.o\
5-
src/rangeset.o src/pl_funcs.o src/worker.o src/hooks.o src/nodes_common.o$(WIN32RES)
4+
OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o src/runtimeappend.o\
5+
src/runtime_merge_append.o src/pg_pathman.o src/dsm_array.o src/rangeset.o src/pl_funcs.o\
6+
src/worker.o src/hooks.o src/nodes_common.o$(WIN32RES)
67

78
EXTENSION = pg_pathman
89
EXTVERSION = 0.1
@@ -35,6 +36,6 @@ submake-isolation:
3536
isolationcheck: | submake-isolation
3637
$(MKDIR_P) isolation_output
3738
$(pg_isolation_regress_check)\
38-
--temp-config=$(top_srcdir)/$(subdir)/conf.add\
39-
--outputdir=./isolation_output\
40-
$(ISOLATIONCHECKS)
39+
--temp-config=$(top_srcdir)/$(subdir)/conf.add\
40+
--outputdir=./isolation_output\
41+
$(ISOLATIONCHECKS)

‎hash.sql

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,29 @@ BEGIN
3636

3737
v_hashfunc := @extschema@.get_type_hash_func(v_type::regtype::oid)::regproc;
3838

39+
/* Insert new entry to pathman config*/
40+
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype)
41+
VALUES (relation, attribute,1);
42+
3943
/* Create partitions and update pg_pathman configuration*/
4044
FOR partnumIN0..partitions_count-1
4145
LOOP
4246
v_child_relname := format('%s.%s',
4347
v_plain_schema,
4448
quote_ident(v_plain_relname||'_'|| partnum));
4549

46-
EXECUTE format('CREATE TABLE %s (LIKE %s INCLUDING ALL)'
47-
, v_child_relname
48-
, v_relname);
49-
50-
EXECUTE format('ALTER TABLE %s INHERIT %s'
50+
EXECUTE format('CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL) INHERITS (%2$s)'
5151
, v_child_relname
5252
, v_relname);
5353

54-
EXECUTE format('ALTER TABLE %s ADD CHECK (@extschema@.get_hash(%s(%s), %s) = %s)'
54+
EXECUTE format('ALTER TABLE %s ADDCONSTRAINT %sCHECK (@extschema@.get_hash(%s(%s), %s) = %s)'
5555
, v_child_relname
56+
, @extschema@.build_check_constraint_name(v_child_relname::regclass, attribute)
5657
, v_hashfunc
5758
, attribute
5859
, partitions_count
5960
, partnum);
6061
END LOOP;
61-
INSERT INTO @extschema@.pathman_config (relname, attname, parttype)
62-
VALUES (v_relname, attribute,1);
63-
64-
/* Create triggers*/
65-
/* Do not create update trigger by default*/
66-
-- PERFORM @extschema@.create_hash_update_trigger(relation, attribute, partitions_count);
6762

6863
/* Notify backend about changes*/
6964
PERFORM @extschema@.on_create_partitions(relation::oid);
@@ -83,25 +78,36 @@ CREATE OR REPLACE FUNCTION @extschema@.create_hash_update_trigger(
8378
RETURNS VOIDAS
8479
$$
8580
DECLARE
86-
funcTEXT :='
87-
CREATE OR REPLACE FUNCTION %s()
88-
RETURNS TRIGGER AS
89-
$body$
90-
DECLARE old_hash INTEGER; new_hash INTEGER; q TEXT;
91-
BEGIN
92-
old_hash := @extschema@.get_hash(%9$s(OLD.%2$s), %3$s);
93-
new_hash := @extschema@.get_hash(%9$s(NEW.%2$s), %3$s);
94-
IF old_hash = new_hash THEN RETURN NEW; END IF;
95-
q := format(''DELETE FROM %8$s WHERE %4$s'', old_hash);
96-
EXECUTE q USING %5$s;
97-
q := format(''INSERT INTO %8$s VALUES (%6$s)'', new_hash);
98-
EXECUTE q USING %7$s;
99-
RETURN NULL;
100-
END $body$ LANGUAGE plpgsql';
101-
triggerTEXT :='
102-
CREATE TRIGGER %s
103-
BEFORE UPDATE ON %s
104-
FOR EACH ROW EXECUTE PROCEDURE %s()';
81+
funcTEXT :='CREATE OR REPLACE FUNCTION %s()
82+
RETURNS TRIGGER AS
83+
$body$
84+
DECLARE
85+
old_hash INTEGER;
86+
new_hash INTEGER;
87+
q TEXT;
88+
89+
BEGIN
90+
old_hash := @extschema@.get_hash(%9$s(OLD.%2$s), %3$s);
91+
new_hash := @extschema@.get_hash(%9$s(NEW.%2$s), %3$s);
92+
93+
IF old_hash = new_hash THEN
94+
RETURN NEW;
95+
END IF;
96+
97+
q := format(''DELETE FROM %8$s WHERE %4$s'', old_hash);
98+
EXECUTE q USING %5$s;
99+
100+
q := format(''INSERT INTO %8$s VALUES (%6$s)'', new_hash);
101+
EXECUTE q USING %7$s;
102+
103+
RETURN NULL;
104+
END $body$
105+
LANGUAGE plpgsql';
106+
107+
triggerTEXT :='CREATE TRIGGER %s
108+
BEFORE UPDATE ON %s
109+
FOR EACH ROW EXECUTE PROCEDURE %s()';
110+
105111
att_namesTEXT;
106112
old_fieldsTEXT;
107113
new_fieldsTEXT;
@@ -117,6 +123,7 @@ DECLARE
117123
child_relname_formatTEXT;
118124
atttypeTEXT;
119125
hashfuncTEXT;
126+
120127
BEGIN
121128
SELECT* INTO plain_schema, plain_relname
122129
FROM @extschema@.get_plain_schema_and_relname(relation);
@@ -136,7 +143,7 @@ BEGIN
136143
att_val_fmt,
137144
att_fmt;
138145

139-
attr := attnameFROM @extschema@.pathman_configWHERErelname::regclass= relation;
146+
attr := attnameFROM @extschema@.pathman_configWHEREpartrel= relation;
140147

141148
IF attr ISNULL THEN
142149
RAISE EXCEPTION'Table % is not partitioned', quote_ident(relation::TEXT);

‎init.sql

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010

1111
/*
1212
* 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 partitioningin 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 partitioningas string
1919
*/
2020
CREATETABLEIF NOT EXISTS @extschema@.pathman_config (
2121
idSERIALPRIMARY KEY,
22-
relnameVARCHAR(127),
23-
attnameVARCHAR(127),
24-
parttypeINTEGER,
25-
range_intervalTEXT
22+
partrelREGCLASSNOT NULL,
23+
attnameTEXTNOT NULL,
24+
parttypeINTEGERNOT NULL,
25+
range_intervalTEXT,
26+
27+
CHECK (parttype>=1OR parttype<=2)/* check for allowed part types*/
2628
);
29+
2730
SELECTpg_catalog.pg_extension_config_dump('@extschema@.pathman_config','');
2831

2932
CREATEOR REPLACE FUNCTION @extschema@.on_create_partitions(relidOID)
@@ -112,13 +115,13 @@ LANGUAGE plpgsql;
112115
/*
113116
* Disable pathman partitioning for specified relation
114117
*/
115-
CREATEOR REPLACE FUNCTION @extschema@.disable_partitioning(INrelationTEXT)
118+
CREATEOR REPLACE FUNCTION @extschema@.disable_partitioning(relationregclass)
116119
RETURNS VOIDAS
117120
$$
118121
BEGIN
119122
relation := @extschema@.validate_relname(relation);
120123

121-
DELETEFROM @extschema@.pathman_configWHERErelname= relation;
124+
DELETEFROM @extschema@.pathman_configWHEREpartrel= relation;
122125
PERFORM @extschema@.drop_triggers(relation);
123126

124127
/* Notify backend about changes*/
@@ -176,7 +179,7 @@ DECLARE
176179
v_rec RECORD;
177180
is_referencedBOOLEAN;
178181
BEGIN
179-
IF EXISTS (SELECT*FROM @extschema@.pathman_configWHERErelname::regclass= p_relation) THEN
182+
IF EXISTS (SELECT*FROM @extschema@.pathman_configWHEREpartrel= p_relation) THEN
180183
RAISE EXCEPTION'Relation "%" has already been partitioned', p_relation;
181184
END IF;
182185

@@ -298,7 +301,7 @@ $$
298301
LANGUAGE plpgsql;
299302

300303
/*
301-
* DDL trigger that deletes entry from pathman_config
304+
* DDL trigger that deletes entry from pathman_config table
302305
*/
303306
CREATEOR REPLACE FUNCTION @extschema@.pathman_ddl_trigger_func()
304307
RETURNS event_triggerAS
@@ -307,11 +310,12 @@ DECLARE
307310
obj record;
308311
BEGIN
309312
FOR objINSELECT*FROM pg_event_trigger_dropped_objects()as events
310-
JOIN @extschema@.pathman_configas cfgONcfg.relname=events.object_identity
313+
JOIN @extschema@.pathman_configas cfg
314+
ON partrel::oid=events.objid
311315
LOOP
312316
IFobj.object_type='table' THEN
313-
EXECUTE'DELETE FROM @extschema@.pathman_config WHERErelname = $1'
314-
USINGobj.object_identity;
317+
EXECUTE'DELETE FROM @extschema@.pathman_config WHEREpartrel = $1'
318+
USINGobj.objid;
315319
END IF;
316320
END LOOP;
317321
END
@@ -375,7 +379,7 @@ BEGIN
375379
PERFORM @extschema@.drop_triggers(relation);
376380

377381
WITH config_num_deletedAS (DELETEFROM @extschema@.pathman_config
378-
WHERErelname::regclass= relation
382+
WHEREpartrel= relation
379383
RETURNING*)
380384
SELECTcount(*)from config_num_deleted INTO conf_num_del;
381385

@@ -417,3 +421,15 @@ RETURNS OID AS 'pg_pathman', 'get_type_hash_func' LANGUAGE C STRICT;
417421
*/
418422
CREATEOR REPLACE FUNCTION @extschema@.get_hash(INTEGER,INTEGER)
419423
RETURNSINTEGERAS'pg_pathman','get_hash' LANGUAGE C STRICT;
424+
425+
426+
/*
427+
* Build check constraint name for a specified relation's column
428+
*/
429+
CREATEOR REPLACE FUNCTION @extschema@.build_check_constraint_name(REGCLASS, INT2)
430+
RETURNSTEXTAS'pg_pathman','build_check_constraint_name_attnum'
431+
LANGUAGE C STRICT;
432+
433+
CREATEOR REPLACE FUNCTION @extschema@.build_check_constraint_name(REGCLASS,TEXT)
434+
RETURNSTEXTAS'pg_pathman','build_check_constraint_name_attname'
435+
LANGUAGE C STRICT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp