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

Commit0344edd

Browse files
committed
pathman: two patches by Julien Rouhaud (shmem allocation and post_parse_analyze_hook) and one by Alexander Korotkov (version check)
1 parentb23f756 commit0344edd

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

‎contrib/pg_pathman/dsm_array.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ typedef BlockHeader* BlockHeaderPtr;
4343
#defineset_length(header,length) \
4444
((length) | ((*header) & FREE_BIT))
4545

46+
/*
47+
* Amount of memory that need to be requested in shared memory to store dsm
48+
* config
49+
*/
50+
Size
51+
get_dsm_shared_size()
52+
{
53+
return (Size)MAXALIGN(sizeof(DsmConfig));
54+
}
55+
4656
/*
4757
* Initialize dsm config for arrays
4858
*/

‎contrib/pg_pathman/init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ static bool validate_range_constraint(Expr *, PartRelationInfo *, Datum *, Datum
3434
staticboolvalidate_hash_constraint(Expr*expr,PartRelationInfo*prel,int*hash);
3535
staticintcmp_range_entries(constvoid*p1,constvoid*p2);
3636

37+
Size
38+
pathman_memsize()
39+
{
40+
Sizesize;
41+
42+
size=get_dsm_shared_size()+MAXALIGN(sizeof(PathmanState));
43+
returnsize;
44+
}
45+
3746
void
3847
init_shmem_config()
3948
{

‎contrib/pg_pathman/pathman.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include"storage/dsm.h"
1919
#include"storage/lwlock.h"
2020

21+
/* Check PostgreSQL version */
22+
#ifPG_VERSION_NUM<90500
23+
#error "You are trying to build pg_pathman with PostgreSQL version lower than 9.5. Please, check you environment."
24+
#endif
2125

2226
#defineALL NIL
2327
#defineINITIAL_BLOCKS_COUNT 8192
@@ -152,6 +156,7 @@ int irange_list_length(List *rangeset);
152156
boolirange_list_find(List*rangeset,intindex,bool*lossy);
153157

154158
/* Dynamic shared memory functions */
159+
Sizeget_dsm_shared_size(void);
155160
voidinit_dsm_config(void);
156161
boolinit_dsm_segment(size_tblocks_count,size_tblock_size);
157162
voidinit_dsm_table(size_tblock_size,size_tstart,size_tend);
@@ -167,6 +172,7 @@ HTAB *range_restrictions;
167172
boolinitialization_needed;
168173

169174
/* initialization functions */
175+
Sizepathman_memsize(void);
170176
voidinit_shmem_config(void);
171177
voidload_config(void);
172178
voidcreate_relations_hashtable(void);

‎contrib/pg_pathman/pg_pathman.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include"optimizer/planner.h"
2323
#include"optimizer/restrictinfo.h"
2424
#include"optimizer/cost.h"
25+
#include"parser/analyze.h"
2526
#include"parser/parsetree.h"
2627
#include"utils/hsearch.h"
2728
#include"utils/tqual.h"
@@ -56,6 +57,7 @@ typedef struct
5657
/* Original hooks */
5758
staticset_rel_pathlist_hook_typeset_rel_pathlist_hook_original=NULL;
5859
staticshmem_startup_hook_typeshmem_startup_hook_original=NULL;
60+
staticpost_parse_analyze_hook_typepost_parse_analyze_hook_original=NULL;
5961
staticplanner_hook_typeplanner_hook_original=NULL;
6062

6163
/* pg module functions */
@@ -65,6 +67,7 @@ void _PG_fini(void);
6567
/* Hook functions */
6668
staticvoidpathman_shmem_startup(void);
6769
staticvoidpathman_set_rel_pathlist_hook(PlannerInfo*root,RelOptInfo*rel,Indexrti,RangeTblEntry*rte);
70+
voidpathman_post_parse_analysis_hook(ParseState*pstate,Query*query);
6871
staticPlannedStmt*pathman_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams);
6972

7073
/* Utility functions */
@@ -127,10 +130,16 @@ _PG_init(void)
127130
}
128131
#endif
129132

133+
/* Request additional shared resources */
134+
RequestAddinShmemSpace(pathman_memsize());
135+
RequestAddinLWLocks(3);
136+
130137
set_rel_pathlist_hook_original=set_rel_pathlist_hook;
131138
set_rel_pathlist_hook=pathman_set_rel_pathlist_hook;
132139
shmem_startup_hook_original=shmem_startup_hook;
133140
shmem_startup_hook=pathman_shmem_startup;
141+
post_parse_analyze_hook_original=post_parse_analyze_hook;
142+
post_parse_analyze_hook=pathman_post_parse_analysis_hook;
134143
planner_hook_original=planner_hook;
135144
planner_hook=pathman_planner_hook;
136145
}
@@ -140,6 +149,7 @@ _PG_fini(void)
140149
{
141150
set_rel_pathlist_hook=set_rel_pathlist_hook_original;
142151
shmem_startup_hook=shmem_startup_hook_original;
152+
post_parse_analyze_hook=post_parse_analyze_hook_original;
143153
planner_hook=planner_hook_original;
144154
}
145155

@@ -182,6 +192,20 @@ get_cmp_func(Oid type1, Oid type2)
182192
returncmp_func;
183193
}
184194

195+
/*
196+
* Post parse analysis hook. It makes sure the config is loaded before executing
197+
* any statement, including utility commands
198+
*/
199+
void
200+
pathman_post_parse_analysis_hook(ParseState*pstate,Query*query)
201+
{
202+
if (initialization_needed)
203+
load_config();
204+
205+
if (post_parse_analyze_hook_original)
206+
post_parse_analyze_hook_original(pstate,query);
207+
}
208+
185209
/*
186210
* Planner hook. It disables inheritance for tables that have been partitioned
187211
* by pathman to prevent standart PostgreSQL partitioning mechanism from
@@ -193,11 +217,6 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
193217
PlannedStmt*result;
194218
ListCell*lc;
195219

196-
if (initialization_needed)
197-
{
198-
load_config();
199-
}
200-
201220
inheritance_disabled= false;
202221
switch(parse->commandType)
203222
{
@@ -325,9 +344,6 @@ handle_modification_query(Query *parse)
325344
staticvoid
326345
pathman_shmem_startup(void)
327346
{
328-
/* Initialize locks */
329-
RequestAddinLWLocks(3);
330-
331347
/* Allocate shared memory objects */
332348
LWLockAcquire(AddinShmemInitLock,LW_EXCLUSIVE);
333349
init_dsm_config();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp