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

Commitf0a0cfe

Browse files
committed
pathman: simple regression test
1 parentaca6586 commitf0a0cfe

File tree

6 files changed

+127
-9
lines changed

6 files changed

+127
-9
lines changed

‎contrib/pathman/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ OBJS = init.o pathman.o dsm_array.o $(WIN32RES)
55

66
EXTENSION = pathman
77
EXTVERSION = 0.1
8-
DATA =$(EXTENSION)--$(EXTVERSION).sql
98
DATA_built =$(EXTENSION)--$(EXTVERSION).sql
109
PGFILEDESC = "pathman - partitioning tool"
1110

‎contrib/pathman/expected/pathman.out

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
CREATE EXTENSION pathman;
2+
CREATE TABLE hash_rel (
3+
id SERIAL PRIMARY KEY,
4+
value INTEGER);
5+
SELECT create_hash_partitions('hash_rel', 'value', 3);
6+
NOTICE: trigger "hash_rel_insert_trigger" for relation "hash_rel" does not exist, skipping
7+
NOTICE: function hash_rel_hash_insert_trigger_func() does not exist, skipping
8+
NOTICE: trigger "hash_rel_update_trigger" for relation "hash_rel" does not exist, skipping
9+
NOTICE: function hash_rel_hash_update_trigger_func() does not exist, skipping
10+
create_hash_partitions
11+
------------------------
12+
13+
(1 row)
14+
15+
INSERT INTO hash_rel VALUES (1, 1);
16+
INSERT INTO hash_rel VALUES (2, 2);
17+
INSERT INTO hash_rel VALUES (3, 3);
18+
INSERT INTO hash_rel VALUES (4, 4);
19+
INSERT INTO hash_rel VALUES (5, 5);
20+
INSERT INTO hash_rel VALUES (6, 6);
21+
EXPLAIN SELECT * FROM hash_rel;
22+
QUERY PLAN
23+
-----------------------------------------------------------------
24+
Append (cost=0.00..97.80 rows=0 width=0)
25+
-> Seq Scan on hash_rel_0 (cost=0.00..32.60 rows=0 width=0)
26+
-> Seq Scan on hash_rel_1 (cost=0.00..32.60 rows=0 width=0)
27+
-> Seq Scan on hash_rel_2 (cost=0.00..32.60 rows=0 width=0)
28+
(4 rows)
29+
30+
EXPLAIN SELECT * FROM hash_rel WHERE value = 2;
31+
QUERY PLAN
32+
-----------------------------------------------------------------
33+
Append (cost=0.00..32.60 rows=0 width=0)
34+
-> Seq Scan on hash_rel_2 (cost=0.00..32.60 rows=0 width=0)
35+
Filter: (value = 2)
36+
(3 rows)
37+
38+
SELECT drop_hash_partitions('hash_rel');
39+
NOTICE: trigger "hash_rel_update_trigger" for relation "hash_rel" does not exist, skipping
40+
NOTICE: function hash_rel_hash_update_trigger_func() does not exist, skipping
41+
drop_hash_partitions
42+
----------------------
43+
44+
(1 row)
45+
46+
DROP TABLE hash_rel CASCADE;
47+
NOTICE: drop cascades to 3 other objects
48+
DETAIL: drop cascades to table hash_rel_0
49+
drop cascades to table hash_rel_1
50+
drop cascades to table hash_rel_2
51+
CREATE TABLE num_range_rel (
52+
id SERIAL PRIMARY KEY,
53+
txt TEXT);
54+
SELECT create_range_partitions('num_range_rel', 'id', 'num', '0', '1000', 3);
55+
create_range_partitions
56+
-------------------------
57+
58+
(1 row)
59+
60+
INSERT INTO num_range_rel SELECT g, md5(g::TEXT) FROM generate_series(1, 3000) as g;
61+
VACUUM;
62+
EXPLAIN SELECT * FROM num_range_rel WHERE id > 2500;
63+
QUERY PLAN
64+
-------------------------------------------------------------------------
65+
Append (cost=0.00..20.01 rows=0 width=0)
66+
-> Seq Scan on num_range_rel_2000 (cost=0.00..19.00 rows=0 width=0)
67+
Filter: (id > 2500)
68+
-> Seq Scan on num_range_rel_3000 (cost=0.00..1.01 rows=0 width=0)
69+
Filter: (id > 2500)
70+
(5 rows)
71+
72+
SELECT drop_range_partitions('num_range_rel');
73+
drop_range_partitions
74+
-----------------------
75+
76+
(1 row)
77+
78+
DROP TABLE num_range_rel CASCADE;
79+
DROP EXTENSION pathman;

‎contrib/pathman/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ load_part_relations_hashtable()
3333
ListCell*lc;
3434

3535
/* if hashtable is empty */
36-
if (hash_get_num_entries(relations)==0)
37-
{
36+
//if (hash_get_num_entries(relations) == 0)
37+
//{
3838
SPI_connect();
3939
ret=SPI_exec("SELECT pg_class.relfilenode, pg_attribute.attnum, pg_pathman_rels.parttype, pg_attribute.atttypid "
4040
"FROM pg_pathman_rels "
@@ -86,7 +86,7 @@ load_part_relations_hashtable()
8686
}
8787
}
8888
SPI_finish();
89-
}
89+
//}
9090
}
9191

9292
void

‎contrib/pathman/pathman.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,15 @@ accumulate_append_subpath(List *subpaths, Path *path)
829829
*/
830830
Datum
831831
on_partitions_created(PG_FUNCTION_ARGS) {
832-
/* Reload config */
832+
Oidrelid;
833+
833834
LWLockAcquire(load_config_lock,LW_EXCLUSIVE);
835+
836+
/* Reload config */
837+
/* TODO: reload just the specified relation */
838+
// relid = DatumGetInt32(PG_GETARG_DATUM(0))
834839
load_part_relations_hashtable();
840+
835841
LWLockRelease(load_config_lock);
836842

837843
PG_RETURN_NULL();

‎contrib/pathman/sql/hash.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,18 @@ BEGIN
121121
relid := relfilenodeFROM pg_classWHERE relname= relation;
122122
partitions_count :=COUNT(*)FROM pg_pathman_hash_relsWHERE parent= relation;
123123

124+
DELETEFROM pg_pathman_relsWHERE relname= relation;
125+
DELETEFROM pg_pathman_hash_relsWHERE parent= relation;
126+
124127
IF partitions_count>0 THEN
125-
RETURN
128+
RETURN;
129+
END IF;
126130

127131
FOR partnumIN0..partitions_count-1
128132
LOOP
129133
EXECUTE format(q, relation, partnum);
130134
END LOOP;
131135

132-
DELETEFROM pg_pathman_relsWHERE relname= relation;
133-
DELETEFROM pg_pathman_hash_relsWHERE parent= relation;
134-
135136
/* Notify backend about changes*/
136137
PERFORM pg_pathman_on_remove_partitions(relid);
137138
END

‎contrib/pathman/sql/pathman.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CREATE EXTENSION pathman;
2+
3+
CREATETABLEhash_rel (
4+
idSERIALPRIMARY KEY,
5+
valueINTEGER);
6+
7+
SELECT create_hash_partitions('hash_rel','value',3);
8+
9+
INSERT INTO hash_relVALUES (1,1);
10+
INSERT INTO hash_relVALUES (2,2);
11+
INSERT INTO hash_relVALUES (3,3);
12+
INSERT INTO hash_relVALUES (4,4);
13+
INSERT INTO hash_relVALUES (5,5);
14+
INSERT INTO hash_relVALUES (6,6);
15+
16+
EXPLAINSELECT*FROM hash_rel;
17+
EXPLAINSELECT*FROM hash_relWHERE value=2;
18+
19+
SELECT drop_hash_partitions('hash_rel');
20+
DROPTABLE hash_rel CASCADE;
21+
22+
CREATETABLEnum_range_rel (
23+
idSERIALPRIMARY KEY,
24+
txtTEXT);
25+
SELECT create_range_partitions('num_range_rel','id','num','0','1000',3);
26+
INSERT INTO num_range_relSELECT g, md5(g::TEXT)FROM generate_series(1,3000)as g;
27+
VACUUM;
28+
EXPLAINSELECT*FROM num_range_relWHERE id>2500;
29+
30+
SELECT drop_range_partitions('num_range_rel');
31+
DROPTABLE num_range_rel CASCADE;
32+
33+
DROP EXTENSION pathman;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp