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

Commit998022d

Browse files
committed
Merge branch 'master' into picky_nodes
2 parentsb1a70f7 +337a092 commit998022d

File tree

8 files changed

+54
-43
lines changed

8 files changed

+54
-43
lines changed

‎expected/pg_pathman.out

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ INSERT INTO test.hash_rel VALUES (3, 3);
1111
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
1212
ERROR: Partitioning key 'value' must be NOT NULL
1313
ALTER TABLE test.hash_rel ALTER COLUMN value SET NOT NULL;
14-
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
15-
NOTICE: function test.hash_rel_hash_insert_trigger_func() does not exist, skipping
16-
NOTICE: function test.hash_rel_hash_update_trigger_func() does not exist, skipping
14+
SELECT pathman.create_hash_partitions('test.hash_rel', 'Value', 3);
15+
NOTICE: function test.hash_rel_insert_trigger_func() does not exist, skipping
16+
NOTICE: function test.hash_rel_update_trigger_func() does not exist, skipping
1717
NOTICE: Copying data to partitions...
1818
create_hash_partitions
1919
------------------------
@@ -59,7 +59,7 @@ ERROR: Partitioning key 'dt' must be NOT NULL P0001
5959
ALTER TABLE test.range_rel ALTER COLUMN dt SET NOT NULL;
6060
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
6161
ERROR: Not enough partitions to fit all the values of 'dt' P0001
62-
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL);
62+
SELECT pathman.create_range_partitions('test.range_rel', 'DT', '2015-01-01'::DATE, '1 month'::INTERVAL);
6363
NOTICE: sequence "range_rel_seq" does not exist, skipping
6464
NOTICE: Copying data to partitions...
6565
create_range_partitions
@@ -600,15 +600,26 @@ CREATE TABLE test.range_rel_test2 (
600600
dt TIMESTAMP);
601601
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
602602
ERROR: Partition must have the exact same structure as parent P0001
603+
/*
604+
* Check that altering table columns doesn't break trigger
605+
*/
606+
ALTER TABLE test.hash_rel ADD COLUMN abc int;
607+
INSERT INTO test.hash_rel (id, value, abc) VALUES (123, 456, 789);
608+
SELECT * FROM test.hash_rel WHERE id = 123;
609+
id | value | abc
610+
-----+-------+-----
611+
123 | 456 | 789
612+
(1 row)
613+
603614
/*
604615
* Clean up
605616
*/
606617
SELECT pathman.drop_hash_partitions('test.hash_rel');
607618
NOTICE: drop cascades to trigger test_hash_rel_insert_trigger on table test.hash_rel
608-
NOTICE:function test.hash_rel_hash_update_trigger_func() does not exist, skipping
619+
NOTICE:drop cascades to 3 other objects
609620
NOTICE: 2 rows copied from test.hash_rel_2
610621
NOTICE: 3 rows copied from test.hash_rel_1
611-
NOTICE:1 rows copied from test.hash_rel_0
622+
NOTICE:2 rows copied from test.hash_rel_0
612623
drop_hash_partitions
613624
----------------------
614625
3
@@ -617,12 +628,12 @@ NOTICE: 1 rows copied from test.hash_rel_0
617628
SELECT COUNT(*) FROM ONLY test.hash_rel;
618629
count
619630
-------
620-
6
631+
7
621632
(1 row)
622633

623634
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
624-
NOTICE: function test.hash_rel_hash_insert_trigger_func() does not exist, skipping
625-
NOTICE: function test.hash_rel_hash_update_trigger_func() does not exist, skipping
635+
NOTICE: function test.hash_rel_insert_trigger_func() does not exist, skipping
636+
NOTICE: function test.hash_rel_update_trigger_func() does not exist, skipping
626637
NOTICE: Copying data to partitions...
627638
create_hash_partitions
628639
------------------------
@@ -631,7 +642,7 @@ NOTICE: Copying data to partitions...
631642

632643
SELECT pathman.drop_hash_partitions('test.hash_rel', TRUE);
633644
NOTICE: drop cascades to trigger test_hash_rel_insert_trigger on table test.hash_rel
634-
NOTICE: function test.hash_rel_hash_update_trigger_func() does not exist, skipping
645+
NOTICE: function test.hash_rel_update_trigger_func() does not exist, skipping
635646
drop_hash_partitions
636647
----------------------
637648
3
@@ -770,8 +781,8 @@ CREATE TABLE hash_rel (
770781
valueINTEGER NOT NULL);
771782
INSERT INTO hash_rel (value) SELECT g FROM generate_series(1, 10000) as g;
772783
SELECT create_hash_partitions('hash_rel', 'value', 3);
773-
NOTICE: functionhash_rel_hash_insert_trigger_func() does not exist, skipping
774-
NOTICE: functionhash_rel_hash_update_trigger_func() does not exist, skipping
784+
NOTICE: functionhash_rel_insert_trigger_func() does not exist, skipping
785+
NOTICE: functionhash_rel_update_trigger_func() does not exist, skipping
775786
NOTICE: Copying data to partitions...
776787
create_hash_partitions
777788
------------------------

‎hash.sql

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ DECLARE
2121
v_typeTEXT;
2222
BEGIN
2323
relation := @extschema@.validate_relname(relation);
24+
attribute :=lower(attribute);
2425
PERFORM @extschema@.common_relation_checks(relation, attribute);
2526

2627
v_type := @extschema@.get_attribute_type_name(relation, attribute);
@@ -75,7 +76,7 @@ RETURNS VOID AS
7576
$$
7677
DECLARE
7778
funcTEXT :='
78-
CREATE OR REPLACE FUNCTION %s_hash_insert_trigger_func()
79+
CREATE OR REPLACE FUNCTION %s_insert_trigger_func()
7980
RETURNS TRIGGER AS $body$
8081
DECLARE
8182
hash INTEGER;
@@ -87,7 +88,7 @@ DECLARE
8788
triggerTEXT :='
8889
CREATE TRIGGER %s_insert_trigger
8990
BEFORE INSERT ON %s
90-
FOR EACH ROW EXECUTE PROCEDURE %2$s_hash_insert_trigger_func();';
91+
FOR EACH ROW EXECUTE PROCEDURE %2$s_insert_trigger_func();';
9192
fieldsTEXT;
9293
fields_formatTEXT;
9394
insert_stmtTEXT;
@@ -102,10 +103,8 @@ BEGIN
102103
INTO fields, fields_format;
103104

104105
/* generate INSERT statement for trigger*/
105-
insert_stmt= format('EXECUTE format(''INSERT INTO %s_%%s VALUES (%s)'', hash) USING %s;'
106-
, relation
107-
, fields_format
108-
, fields);
106+
insert_stmt= format('EXECUTE format(''INSERT INTO %s_%%s SELECT $1.*'', hash) USING NEW;'
107+
, relation);
109108

110109
/* format and create new trigger for relation*/
111110
func := format(func, relation, attr, partitions_count, insert_stmt);
@@ -163,9 +162,9 @@ CREATE OR REPLACE FUNCTION @extschema@.drop_hash_triggers(IN relation TEXT)
163162
RETURNS VOIDAS
164163
$$
165164
BEGIN
166-
EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_insert_trigger_func() CASCADE'
165+
EXECUTE format('DROP FUNCTION IF EXISTS %s_insert_trigger_func() CASCADE'
167166
, relation::regclass::text);
168-
EXECUTE format('DROP FUNCTION IF EXISTS %s_hash_update_trigger_func() CASCADE'
167+
EXECUTE format('DROP FUNCTION IF EXISTS %s_update_trigger_func() CASCADE'
169168
, relation::regclass::text);
170169
END
171170
$$ LANGUAGE plpgsql;

‎init.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ load_relations_hashtable(bool reinitialize)
175175
charsql[]="SELECT pg_class.relfilenode, pg_attribute.attnum, cfg.parttype, pg_attribute.atttypid "
176176
"FROM %s.pathman_config as cfg "
177177
"JOIN pg_class ON pg_class.relfilenode = cfg.relname::regclass::oid "
178-
"JOIN pg_attribute ON pg_attribute.attname = cfg.attname "
178+
"JOIN pg_attribute ON pg_attribute.attname =lower(cfg.attname) "
179179
"AND attrelid = pg_class.relfilenode";
180180
char*query;
181181

@@ -262,11 +262,8 @@ create_relations_hashtable()
262262
/* Already exists, recreate */
263263
if (relations!=NULL)
264264
hash_destroy(relations);
265-
#ifPG_VERSION_NUM >=90600
266-
relations=ShmemInitHash("Partitioning relation info",1024,&ctl,HASH_ELEM |HASH_BLOBS);
267-
#else
265+
268266
relations=ShmemInitHash("Partitioning relation info",1024,1024,&ctl,HASH_ELEM |HASH_BLOBS);
269-
#endif
270267
}
271268

272269
/*
@@ -562,13 +559,8 @@ create_range_restrictions_hashtable()
562559
memset(&ctl,0,sizeof(ctl));
563560
ctl.keysize=sizeof(RelationKey);
564561
ctl.entrysize=sizeof(RangeRelation);
565-
#ifPG_VERSION_NUM >=90600
566-
range_restrictions=ShmemInitHash("pg_pathman range restrictions",
567-
1024,&ctl,HASH_ELEM |HASH_BLOBS);
568-
#else
569562
range_restrictions=ShmemInitHash("pg_pathman range restrictions",
570563
1024,1024,&ctl,HASH_ELEM |HASH_BLOBS);
571-
#endif
572564
}
573565

574566
/*

‎init.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,18 @@ LANGUAGE plpgsql;
119119
CREATEOR REPLACE FUNCTION @extschema@.disable_partitioning(IN relationTEXT)
120120
RETURNS VOIDAS
121121
$$
122+
DECLARE
123+
parttypeINTEGER;
122124
BEGIN
123125
relation := @extschema@.validate_relname(relation);
126+
parttype := parttypeFROM pathman_configWHERE relname= relation;
124127

125128
DELETEFROM @extschema@.pathman_configWHERE relname= relation;
126-
EXECUTE format('DROP FUNCTION IF EXISTS %s_insert_trigger_func() CASCADE', relation);
129+
IF parttype=1 THEN
130+
PERFORM @extschema@.drop_hash_triggers(relation);
131+
ELSIF parttype=2 THEN
132+
PERFORM @extschema@.drop_range_triggers(relation);
133+
END IF;
127134

128135
/* Notify backend about changes*/
129136
PERFORM on_remove_partitions(relation::regclass::integer);

‎pg_pathman.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ handle_modification_query(Query *parse)
359359
staticvoid
360360
pathman_shmem_startup(void)
361361
{
362-
363362
/* Allocate shared memory objects */
364363
LWLockAcquire(AddinShmemInitLock,LW_EXCLUSIVE);
365364
init_dsm_config();

‎range.sql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ DECLARE
2626
iINTEGER;
2727
BEGIN
2828
p_relation := @extschema@.validate_relname(p_relation);
29+
p_attribute :=lower(p_attribute);
2930
PERFORM @extschema@.common_relation_checks(p_relation, p_attribute);
3031

3132
/* Try to determine partitions count if not set*/
@@ -110,6 +111,7 @@ DECLARE
110111
iINTEGER;
111112
BEGIN
112113
p_relation := @extschema@.validate_relname(p_relation);
114+
p_attribute :=lower(p_attribute);
113115
PERFORM @extschema@.common_relation_checks(p_relation, p_attribute);
114116

115117
IF p_count<=0 THEN
@@ -195,6 +197,7 @@ DECLARE
195197
iINTEGER :=0;
196198
BEGIN
197199
p_relation := @extschema@.validate_relname(p_relation);
200+
p_attribute :=lower(p_attribute);
198201
PERFORM @extschema@.common_relation_checks(p_relation, p_attribute);
199202

200203
IF p_interval<=0 THEN
@@ -258,6 +261,7 @@ DECLARE
258261
iINTEGER :=0;
259262
BEGIN
260263
p_relation := @extschema@.validate_relname(p_relation);
264+
p_attribute :=lower(p_attribute);
261265
PERFORM @extschema@.common_relation_checks(p_relation, p_attribute);
262266

263267
EXECUTE format('DROP SEQUENCE IF EXISTS %s_seq', p_relation);
@@ -402,9 +406,6 @@ BEGIN
402406
LIMIT1;
403407
EXIT WHEN v_child_relname_exists=0;
404408
END LOOP;
405-
-- v_child_relname := format('%s_%s'
406-
-- , p_parent_relname
407-
-- , regexp_replace(p_start_value::text, '[ :-]*', '', 'g'));
408409

409410
/* Skip existing partitions*/
410411
IF EXISTS (SELECT*FROM pg_tablesWHERE tablename= v_child_relname) THEN
@@ -427,7 +428,6 @@ BEGIN
427428
, v_cond);
428429

429430
EXECUTE v_sql;
430-
-- RAISE NOTICE 'partition % created', v_child_relname;
431431
RETURN v_child_relname;
432432
END
433433
$$ LANGUAGE plpgsql;
@@ -759,9 +759,6 @@ DECLARE
759759
BEGIN
760760
p_range := @extschema@.get_range_by_idx(p_relation::regclass::oid,0,0);
761761
RAISE NOTICE'Prepending new partition...';
762-
-- v_part_name := @extschema@.create_single_range_partition(p_relation
763-
-- , p_range[1] - (p_range[2] - p_range[1])
764-
-- , p_range[1]);
765762

766763
IF @extschema@.is_date(p_atttype::regtype) THEN
767764
v_part_name := @extschema@.create_single_range_partition(p_relation
@@ -1113,7 +1110,6 @@ BEGIN
11131110
END LOOP;
11141111

11151112
DELETEFROM @extschema@.pathman_configWHERE relname= relation;
1116-
-- DELETE FROM pg_pathman_range_rels WHERE parent = relation;
11171113

11181114
/* Notify backend about changes*/
11191115
PERFORM @extschema@.on_remove_partitions(relation::regclass::oid);

‎sql/pg_pathman.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ INSERT INTO test.hash_rel VALUES (2, 2);
1212
INSERT INTOtest.hash_relVALUES (3,3);
1313
SELECTpathman.create_hash_partitions('test.hash_rel','value',3);
1414
ALTERTABLEtest.hash_rel ALTER COLUMN valueSETNOT NULL;
15-
SELECTpathman.create_hash_partitions('test.hash_rel','value',3);
15+
SELECTpathman.create_hash_partitions('test.hash_rel','Value',3);
1616
SELECTCOUNT(*)FROMtest.hash_rel;
1717
SELECTCOUNT(*)FROM ONLYtest.hash_rel;
1818
INSERT INTOtest.hash_relVALUES (4,4);
@@ -31,7 +31,7 @@ SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2015-04-30', '1 day':
3131
SELECTpathman.create_range_partitions('test.range_rel','dt','2015-01-01'::DATE,'1 month'::INTERVAL,2);
3232
ALTERTABLEtest.range_rel ALTER COLUMN dtSETNOT NULL;
3333
SELECTpathman.create_range_partitions('test.range_rel','dt','2015-01-01'::DATE,'1 month'::INTERVAL,2);
34-
SELECTpathman.create_range_partitions('test.range_rel','dt','2015-01-01'::DATE,'1 month'::INTERVAL);
34+
SELECTpathman.create_range_partitions('test.range_rel','DT','2015-01-01'::DATE,'1 month'::INTERVAL);
3535
SELECTCOUNT(*)FROMtest.range_rel;
3636
SELECTCOUNT(*)FROM ONLYtest.range_rel;
3737

@@ -149,6 +149,13 @@ CREATE TABLE test.range_rel_test2 (
149149
dtTIMESTAMP);
150150
SELECTpathman.attach_range_partition('test.range_rel','test.range_rel_test2','2013-01-01'::DATE,'2014-01-01'::DATE);
151151

152+
/*
153+
* Check that altering table columns doesn't break trigger
154+
*/
155+
ALTERTABLEtest.hash_rel ADD COLUMN abcint;
156+
INSERT INTOtest.hash_rel (id, value, abc)VALUES (123,456,789);
157+
SELECT*FROMtest.hash_relWHERE id=123;
158+
152159
/*
153160
* Clean up
154161
*/

‎worker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ bg_worker_main(Datum main_arg)
124124
if (!handle)
125125
{
126126
ereport(WARNING,
127-
(errmsg("pg_pathman worker:ivalid dsm_handle")));
127+
(errmsg("pg_pathman worker:invalid dsm_handle")));
128128
}
129129
segment=dsm_attach(handle);
130130
args=dsm_segment_address(segment);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp