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

Commit76fbfd5

Browse files
committed
pathman: schemas support
1 parent60f12d1 commit76fbfd5

File tree

11 files changed

+205
-177
lines changed

11 files changed

+205
-177
lines changed

‎contrib/pathman/README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ Based on partitioning type and operator the `pathman` searches corresponding par
3434

3535
##Installation
3636

37-
To install pathman run:
37+
To install pathman run in psql:
3838
```
39-
make install
39+
CREATE SCHEMA pathman;
40+
CREATE EXTENSION pathman SCHEMA pathman;
4041
```
41-
from its directory.Then modify shared_preload_libraries parameter in postgres.conf as following:
42+
Then modify shared_preload_libraries parameter in postgres.conf as following:
4243
```
4344
shared_preload_libraries = 'pathman'
4445
```

‎contrib/pathman/README.rus.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ WHERE id = 150
3535

3636
##Installation
3737

38-
Для установки pathman выполните вдиректории расширения команду:
38+
Для установки pathman выполните вкомандной строке:
3939
```
40-
make install
40+
CREATE SCHEMA pathman;
41+
CREATE EXTENSION pathman SCHEMA pathman;
42+
4143
```
4244
Затем модифицируйте параметр shared_preload_libraries в конфигурационном файле postgres.conf:
4345
```

‎contrib/pathman/expected/pathman.out‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
\set VERBOSITY terse
2+
CREATE SCHEMA pathman;
3+
CREATE EXTENSION pathman SCHEMA pathman;
24
CREATE SCHEMA test;
3-
CREATE EXTENSION pathman;
45
CREATE TABLE test.hash_rel (
56
id SERIAL PRIMARY KEY,
67
value INTEGER);
7-
SELECT create_hash_partitions('test.hash_rel', 'value', 3);
8+
SELECTpathman.create_hash_partitions('test.hash_rel', 'value', 3);
89
NOTICE: trigger "test_hash_rel_insert_trigger" for relation "test.hash_rel" does not exist, skipping
910
NOTICE: function test.hash_rel_hash_insert_trigger_func() does not exist, skipping
1011
create_hash_partitions
@@ -16,7 +17,7 @@ CREATE TABLE test.range_rel (
1617
id SERIAL PRIMARY KEY,
1718
dt TIMESTAMP,
1819
txt TEXT);
19-
SELECT create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 3);
20+
SELECTpathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 3);
2021
NOTICE: sequence "range_rel_seq" does not exist, skipping
2122
create_range_partitions
2223
-------------------------
@@ -26,7 +27,7 @@ NOTICE: sequence "range_rel_seq" does not exist, skipping
2627
CREATE TABLE test.num_range_rel (
2728
id SERIAL PRIMARY KEY,
2829
txt TEXT);
29-
SELECT create_range_partitions('test.num_range_rel', 'id', 0, 1000, 3);
30+
SELECTpathman.create_range_partitions('test.num_range_rel', 'id', 0, 1000, 3);
3031
NOTICE: sequence "num_range_rel_seq" does not exist, skipping
3132
create_range_partitions
3233
-------------------------
@@ -185,7 +186,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.num_range_rel WHERE (id >= 500 AND id < 1
185186
* Test split and merge
186187
*/
187188
/* Split first partition in half */
188-
SELECT split_range_partition('test.num_range_rel_1', 500);
189+
SELECTpathman.split_range_partition('test.num_range_rel_1', 500);
189190
NOTICE: Creating new partition...
190191
NOTICE: Copying data to new partition...
191192
NOTICE: Altering original partition...
@@ -205,7 +206,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.num_range_rel WHERE id BETWEEN 100 AND 70
205206
Index Cond: (id <= 700)
206207
(5 rows)
207208

208-
SELECT split_range_partition('test.range_rel_1', '2015-01-15'::DATE);
209+
SELECTpathman.split_range_partition('test.range_rel_1', '2015-01-15'::DATE);
209210
NOTICE: Creating new partition...
210211
NOTICE: Copying data to new partition...
211212
NOTICE: Altering original partition...
@@ -216,7 +217,7 @@ NOTICE: Done!
216217
(1 row)
217218

218219
/* Merge two partitions into one */
219-
SELECT merge_range_partitions('test.num_range_rel_1', 'test.num_range_rel_' || currval('test.num_range_rel_seq'));
220+
SELECTpathman.merge_range_partitions('test.num_range_rel_1', 'test.num_range_rel_' || currval('test.num_range_rel_seq'));
220221
NOTICE: Altering first partition...
221222
NOTICE: Copying data...
222223
NOTICE: Dropping second partition...
@@ -234,7 +235,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.num_range_rel WHERE id BETWEEN 100 AND 70
234235
Index Cond: ((id >= 100) AND (id <= 700))
235236
(3 rows)
236237

237-
SELECT merge_range_partitions('test.range_rel_1', 'test.range_rel_' || currval('test.range_rel_seq'));
238+
SELECTpathman.merge_range_partitions('test.range_rel_1', 'test.range_rel_' || currval('test.range_rel_seq'));
238239
NOTICE: Altering first partition...
239240
NOTICE: Copying data...
240241
NOTICE: Dropping second partition...
@@ -245,31 +246,31 @@ NOTICE: Done!
245246
(1 row)
246247

247248
/* Append and prepend partitions */
248-
SELECT append_partition('test.num_range_rel');
249+
SELECTpathman.append_partition('test.num_range_rel');
249250
NOTICE: Appending new partition...
250251
NOTICE: Done!
251252
append_partition
252253
------------------
253254

254255
(1 row)
255256

256-
SELECT prepend_partition('test.num_range_rel');
257+
SELECTpathman.prepend_partition('test.num_range_rel');
257258
NOTICE: Prepending new partition...
258259
NOTICE: Done!
259260
prepend_partition
260261
-------------------
261262

262263
(1 row)
263264

264-
SELECT append_partition('test.range_rel');
265+
SELECTpathman.append_partition('test.range_rel');
265266
NOTICE: Appending new partition...
266267
NOTICE: Done!
267268
append_partition
268269
------------------
269270

270271
(1 row)
271272

272-
SELECT prepend_partition('test.range_rel');
273+
SELECTpathman.prepend_partition('test.range_rel');
273274
NOTICE: Prepending new partition...
274275
NOTICE: Done!
275276
prepend_partition
@@ -280,20 +281,19 @@ NOTICE: Done!
280281
/*
281282
* Clean up
282283
*/
283-
SELECT drop_hash_partitions('test.hash_rel');
284+
SELECTpathman.drop_hash_partitions('test.hash_rel');
284285
drop_hash_partitions
285286
----------------------
286287

287288
(1 row)
288289

289290
DROP TABLE test.hash_rel CASCADE;
290291
NOTICE: drop cascades to 3 other objects
291-
SELECT drop_range_partitions('test.num_range_rel');
292+
SELECTpathman.drop_range_partitions('test.num_range_rel');
292293
drop_range_partitions
293294
-----------------------
294295

295296
(1 row)
296297

297298
DROP TABLE test.num_range_rel CASCADE;
298-
NOTICE: drop cascades to 6 other objects
299299
DROP EXTENSION pathman;

‎contrib/pathman/init.c‎

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include"utils/builtins.h"
1010
#include"utils/typcache.h"
1111
#include"utils/lsyscache.h"
12+
#include"utils/bytea.h"
1213

1314

1415
HTAB*relations=NULL;
@@ -19,7 +20,7 @@ boolinitialization_needed = true;
1920
staticboolvalidate_range_constraint(Expr*,PartRelationInfo*,Datum*,Datum*);
2021
staticboolvalidate_hash_constraint(Expr*expr,PartRelationInfo*prel,int*hash);
2122
staticintcmp_range_entries(constvoid*p1,constvoid*p2);
22-
23+
staticchar*get_extension_schema();
2324

2425
/*
2526
* Initialize hashtables
@@ -33,42 +34,67 @@ load_config(void)
3334
new_segment_created=init_dsm_segment(32);
3435

3536
LWLockAcquire(load_config_lock,LW_EXCLUSIVE);
36-
load_part_relations_hashtable(new_segment_created);
37+
load_relations_hashtable(new_segment_created);
3738
LWLockRelease(load_config_lock);
3839
}
3940

40-
staticbool
41-
check_extension()
41+
/*
42+
* Returns extension schema name or NULL. Caller is responsible for freeing
43+
* the memory.
44+
*/
45+
staticchar*
46+
get_extension_schema()
4247
{
43-
SPI_exec("SELECT * FROM pg_extension WHERE extname = 'pathman'",0);
44-
returnSPI_processed>0;
48+
intret;
49+
boolisnull;
50+
51+
ret=SPI_exec("SELECT extnamespace::regnamespace::text FROM pg_extension WHERE extname = 'pathman'",0);
52+
if (ret>0&&SPI_tuptable!=NULL)
53+
{
54+
TupleDesctupdesc=SPI_tuptable->tupdesc;
55+
SPITupleTable*tuptable=SPI_tuptable;
56+
HeapTupletuple=tuptable->vals[0];
57+
Datumdatum=SPI_getbinval(tuple,tupdesc,1,&isnull);
58+
59+
if (isnull)
60+
returnNULL;
61+
62+
returnTextDatumGetCString(datum);
63+
}
64+
returnNULL;
4565
}
4666

4767
void
48-
load_part_relations_hashtable(boolreinitialize)
68+
load_relations_hashtable(boolreinitialize)
4969
{
70+
intret,
71+
i,
72+
proc;
73+
boolisnull;
74+
List*part_oids=NIL;
75+
ListCell*lc;
76+
char*schema;
5077
PartRelationInfo*prel;
51-
intret;
52-
inti;
53-
intproc;
54-
boolisnull;
55-
List*part_oids=NIL;
56-
ListCell*lc;
78+
charsql[]="SELECT pg_class.relfilenode, pg_attribute.attnum, pathman_config.parttype, pg_attribute.atttypid "
79+
"FROM %s.pathman_config "
80+
"JOIN pg_class ON pg_class.relfilenode = pathman_config.relname::regclass::oid "
81+
"JOIN pg_attribute ON pg_attribute.attname = pathman_config.attname "
82+
"AND attrelid =pg_class.relfilenode";
83+
char*query;
5784

5885
SPI_connect();
86+
schema=get_extension_schema();
5987

60-
/* if extensionwasn'tcreated then just quit */
61-
if (!check_extension())
88+
/* if extensiondoesn'texist then just quit */
89+
if (!schema)
6290
{
6391
SPI_finish();
6492
return;
6593
}
6694

67-
ret=SPI_exec("SELECT pg_class.relfilenode, pg_attribute.attnum, pathman_config.parttype, pg_attribute.atttypid "
68-
"FROM pathman_config "
69-
"JOIN pg_class ON pg_class.relfilenode = pathman_config.relname::regclass::oid "
70-
"JOIN pg_attribute ON pg_attribute.attname = pathman_config.attname "
71-
"AND attrelid = pg_class.relfilenode",0);
95+
/* put schema name to the query */
96+
query=psprintf(sql,schema);
97+
ret=SPI_exec(query,0);
7298
proc=SPI_processed;
7399

74100
if (ret>0&&SPI_tuptable!=NULL)
@@ -94,6 +120,7 @@ load_part_relations_hashtable(bool reinitialize)
94120
// prinfo->children = NIL;
95121
}
96122
}
123+
pfree(query);
97124

98125
/* load children information */
99126
foreach(lc,part_oids)
@@ -133,7 +160,7 @@ load_part_relations_hashtable(bool reinitialize)
133160
}
134161

135162
void
136-
create_part_relations_hashtable()
163+
create_relations_hashtable()
137164
{
138165
HASHCTLctl;
139166

‎contrib/pathman/pathman.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pathman_shmem_startup(void)
192192

193193
/* allocate shared memory objects */
194194
alloc_dsm_table();
195-
create_part_relations_hashtable();
195+
create_relations_hashtable();
196196
create_range_restrictions_hashtable();
197197

198198
LWLockRelease(AddinShmemInitLock);
@@ -203,7 +203,7 @@ pathman_shmem_startup(void)
203203
}
204204

205205
/*
206-
*The hook function. All the magic goes here
206+
*Main hook. All the magic goes here
207207
*/
208208
void
209209
pathman_set_rel_pathlist_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte)

‎contrib/pathman/pathman.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ bool initialization_needed;
151151

152152
/* initialization functions */
153153
voidload_config(void);
154-
voidcreate_part_relations_hashtable(void);
154+
voidcreate_relations_hashtable(void);
155155
voidcreate_hash_restrictions_hashtable(void);
156156
voidcreate_range_restrictions_hashtable(void);
157-
voidload_part_relations_hashtable(boolreinitialize);
157+
voidload_relations_hashtable(boolreinitialize);
158158
voidload_check_constraints(Oidparent_oid);
159159
voidremove_relation_info(Oidrelid);
160160

‎contrib/pathman/pl_funcs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on_partitions_created(PG_FUNCTION_ARGS)
2121

2222
/* Reload config */
2323
/* TODO: reload just the specified relation */
24-
load_part_relations_hashtable(false);
24+
load_relations_hashtable(false);
2525

2626
LWLockRelease(load_config_lock);
2727

@@ -42,7 +42,7 @@ on_partitions_updated(PG_FUNCTION_ARGS)
4242
{
4343
LWLockAcquire(load_config_lock,LW_EXCLUSIVE);
4444
remove_relation_info(relid);
45-
load_part_relations_hashtable(false);
45+
load_relations_hashtable(false);
4646
LWLockRelease(load_config_lock);
4747
}
4848

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp