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

Commit25e225d

Browse files
committed
Bugfix. Do away with possible conflict of hooks, declared as 'extern' in different libraries.
To avoid such a problem in future, refactor AQO interfaces: declare allhooks as static, reduce number of exporting functions and introduceconcept of *_init() function for a module that needs some actions in thePG_init() routine.Reviewed by:@Anisimov-ds
1 parentec03b4a commit25e225d

File tree

14 files changed

+263
-377
lines changed

14 files changed

+263
-377
lines changed

‎aqo.c‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
#include"aqo.h"
2121
#include"aqo_shared.h"
22-
#include"cardinality_hooks.h"
2322
#include"path_utils.h"
24-
#include"preprocessing.h"
2523
#include"storage.h"
2624

2725

@@ -98,19 +96,6 @@ MemoryContext AQOLearnMemCtx = NULL;
9896
/* Additional plan info */
9997
intnjoins;
10098

101-
/* Saved hook values */
102-
post_parse_analyze_hook_typeprev_post_parse_analyze_hook;
103-
planner_hook_typeprev_planner_hook;
104-
ExecutorStart_hook_typeprev_ExecutorStart_hook;
105-
ExecutorRun_hook_typeprev_ExecutorRun;
106-
ExecutorEnd_hook_typeprev_ExecutorEnd_hook;
107-
set_baserel_rows_estimate_hook_typeprev_set_foreign_rows_estimate_hook;
108-
set_baserel_rows_estimate_hook_typeprev_set_baserel_rows_estimate_hook;
109-
get_parameterized_baserel_size_hook_typeprev_get_parameterized_baserel_size_hook;
110-
set_joinrel_size_estimates_hook_typeprev_set_joinrel_size_estimates_hook;
111-
get_parameterized_joinrel_size_hook_typeprev_get_parameterized_joinrel_size_hook;
112-
ExplainOnePlan_hook_typeprev_ExplainOnePlan_hook;
113-
ExplainOneNode_hook_typeprev_ExplainOneNode_hook;
11499

115100
/*****************************************************************************
116101
*
@@ -330,6 +315,7 @@ _PG_init(void)
330315
NULL,
331316
NULL);
332317

318+
<<<<<<<HEAD
333319
prev_shmem_startup_hook=shmem_startup_hook;
334320
shmem_startup_hook=aqo_init_shmem;
335321
prev_planner_hook=planner_hook;
@@ -366,6 +352,13 @@ _PG_init(void)
366352

367353
prev_create_upper_paths_hook=create_upper_paths_hook;
368354
create_upper_paths_hook=aqo_store_upper_signature_hook;
355+
=======
356+
aqo_shmem_init();
357+
aqo_preprocessing_init();
358+
aqo_postprocessing_init();
359+
aqo_cardinality_hooks_init();
360+
aqo_path_utils_init();
361+
>>>>>>>daf05a0 (Bugfix.Doawaywithpossibleconflictofhooks,declaredas'extern'in)
369362

370363
init_deactivated_queries_storage();
371364

‎aqo.h‎

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,16 @@
132132
#include"nodes/nodeFuncs.h"
133133
#include"optimizer/pathnode.h"
134134
#include"optimizer/planner.h"
135-
#include"optimizer/cost.h"
136135
#include"parser/analyze.h"
137136
#include"parser/parsetree.h"
138137
#include"utils/builtins.h"
139138
#include"utils/guc.h"
140139
#include"utils/hsearch.h"
141140
#include"utils/memutils.h"
142141
#include"utils/rel.h"
143-
#include"utils/fmgroids.h"
144142
#include"utils/snapmgr.h"
145143

146144
#include"machine_learning.h"
147-
//#include "storage.h"
148145

149146
/* Check PostgreSQL version (9.6.0 contains important changes in planner) */
150147
#ifPG_VERSION_NUM<90600
@@ -237,58 +234,15 @@ extern MemoryContext AQOCacheMemCtx;
237234
externMemoryContextAQOPredictMemCtx;
238235
externMemoryContextAQOLearnMemCtx;
239236

240-
/* Saved hook values in case of unload */
241-
externpost_parse_analyze_hook_typeprev_post_parse_analyze_hook;
242-
externplanner_hook_typeprev_planner_hook;
243-
externExecutorStart_hook_typeprev_ExecutorStart_hook;
244-
externExecutorRun_hook_typeprev_ExecutorRun;
245-
externExecutorEnd_hook_typeprev_ExecutorEnd_hook;
246-
externset_baserel_rows_estimate_hook_type
247-
prev_set_foreign_rows_estimate_hook;
248-
externset_baserel_rows_estimate_hook_type
249-
prev_set_baserel_rows_estimate_hook;
250-
externget_parameterized_baserel_size_hook_type
251-
prev_get_parameterized_baserel_size_hook;
252-
externset_joinrel_size_estimates_hook_type
253-
prev_set_joinrel_size_estimates_hook;
254-
externget_parameterized_joinrel_size_hook_type
255-
prev_get_parameterized_joinrel_size_hook;
256-
externExplainOnePlan_hook_typeprev_ExplainOnePlan_hook;
257-
externExplainOneNode_hook_typeprev_ExplainOneNode_hook;
258-
259-
externvoidppi_hook(ParamPathInfo*ppi);
260237
externintaqo_statement_timeout;
261238

262-
/* Hash functions */
263-
voidget_eclasses(List*clauselist,int*nargs,int**args_hash,
264-
int**eclass_hash);
265-
intget_clause_hash(Expr*clause,intnargs,int*args_hash,int*eclass_hash);
266-
267-
268-
/* Storage interaction */
269-
externboolload_fss_ext(uint64fs,intfss,OkNNrdata*data,List**reloids);
270-
externboolupdate_fss_ext(uint64fs,intfss,OkNNrdata*data,List*reloids);
271-
272-
/* Query preprocessing hooks */
273-
externvoidprint_into_explain(PlannedStmt*plannedstmt,IntoClause*into,
274-
ExplainState*es,constchar*queryString,
275-
ParamListInfoparams,
276-
constinstr_time*planduration,
277-
QueryEnvironment*queryEnv);
278-
externvoidprint_node_explain(ExplainState*es,PlanState*ps,Plan*plan);
279-
280239
/* Cardinality estimation */
281240
externdoublepredict_for_relation(List*restrict_clauses,List*selectivities,
282241
List*relsigns,int*fss);
283242

284-
/* Query execution statistics collecting hooks */
285-
voidaqo_ExecutorStart(QueryDesc*queryDesc,inteflags);
286-
voidaqo_ExecutorRun(QueryDesc*queryDesc,ScanDirectiondirection,
287-
uint64count,boolexecute_once);
288-
voidaqo_ExecutorEnd(QueryDesc*queryDesc);
289-
290243
/* Automatic query tuning */
291244
externvoidautomatical_query_tuning(uint64query_hash,structStatEntry*stat);
245+
externdoubleget_mean(double*elems,intnelems);
292246

293247
/* Utilities */
294248
externintint_cmp(constvoid*a,constvoid*b);
@@ -306,8 +260,10 @@ extern void selectivity_cache_clear(void);
306260

307261
externboolIsQueryDisabled(void);
308262

309-
externboolupdate_query_timeout(uint64queryid,int64smart_timeout);
310-
externdoubleget_mean(double*elems,intnelems);
311-
312263
externList*cur_classes;
264+
265+
externvoidaqo_cardinality_hooks_init(void);
266+
externvoidaqo_preprocessing_init(void);
267+
externvoidaqo_postprocessing_init(void);
268+
313269
#endif

‎aqo_shared.c‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,30 @@
66

77
#include"lib/dshash.h"
88
#include"miscadmin.h"
9+
#include"storage/ipc.h"
910
#include"storage/shmem.h"
1011

1112
#include"aqo_shared.h"
1213
#include"storage.h"
1314

1415

15-
shmem_startup_hook_typeprev_shmem_startup_hook=NULL;
1616
AQOSharedState*aqo_state=NULL;
1717
intfs_max_items=10000;/* Max number of different feature spaces in ML model */
1818
intfss_max_items=100000;/* Max number of different feature subspaces in ML model */
1919

20+
staticshmem_startup_hook_typeaqo_shmem_startup_next=NULL;
21+
staticshmem_request_hook_typeaqo_shmem_request_next=NULL;
22+
2023
staticvoidon_shmem_shutdown(intcode,Datumarg);
2124

22-
void
25+
staticvoid
2326
aqo_init_shmem(void)
2427
{
2528
boolfound;
2629
HASHCTLinfo;
2730

28-
if (prev_shmem_startup_hook)
29-
prev_shmem_startup_hook();
31+
if (aqo_shmem_startup_next)
32+
aqo_shmem_startup_next();
3033

3134
aqo_state=NULL;
3235
stat_htab=NULL;
@@ -116,10 +119,17 @@ on_shmem_shutdown(int code, Datum arg)
116119
return;
117120
}
118121

119-
Size
120-
aqo_memsize(void)
122+
123+
/*
124+
* Requests any additional shared memory required for aqo.
125+
*/
126+
staticvoid
127+
aqo_shmem_request(void)
121128
{
122-
Sizesize;
129+
Sizesize;
130+
131+
if (aqo_shmem_request_next)
132+
aqo_shmem_request_next();
123133

124134
size=MAXALIGN(sizeof(AQOSharedState));
125135
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(AQOSharedState)));
@@ -128,5 +138,14 @@ aqo_memsize(void)
128138
size=add_size(size,hash_estimate_size(fss_max_items,sizeof(DataEntry)));
129139
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(QueriesEntry)));
130140

131-
returnsize;
141+
RequestAddinShmemSpace(size);
142+
}
143+
144+
void
145+
aqo_shmem_init(void)
146+
{
147+
aqo_shmem_startup_next=shmem_startup_hook;
148+
shmem_startup_hook=aqo_init_shmem;
149+
aqo_shmem_request_next=shmem_request_hook;
150+
shmem_request_hook=aqo_shmem_request;
132151
}

‎aqo_shared.h‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#ifndefAQO_SHARED_H
22
#defineAQO_SHARED_H
33

4-
#include"lib/dshash.h"
5-
#include"storage/dsm.h"
6-
#include"storage/ipc.h"
74
#include"storage/lwlock.h"
85
#include"utils/dsa.h"
96

@@ -31,13 +28,11 @@ typedef struct AQOSharedState
3128
}AQOSharedState;
3229

3330

34-
externshmem_startup_hook_typeprev_shmem_startup_hook;
3531
externAQOSharedState*aqo_state;
3632

3733
externintfs_max_items;/* Max number of feature spaces that AQO can operate */
3834
externintfss_max_items;
3935

40-
externSizeaqo_memsize(void);
41-
externvoidaqo_init_shmem(void);
36+
externvoidaqo_shmem_init(void);
4237

4338
#endif/* AQO_SHARED_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp