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

Commit3207d62

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-dsP.S.: being cherry-picked from stable14 the commit changed drastically becauseof huge differences between the PG cores...
1 parent94bc12d commit3207d62

15 files changed

+259
-418
lines changed

‎aqo--1.6.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,19 @@ LANGUAGE C STRICT VOLATILE;
7575
COMMENT ON FUNCTION aqo_execution_time(boolean) IS
7676
'Get execution time of queries. If controlled = true (AQO could advise cardinality estimations), show time of last execution attempt. Another case (AQO not used), return an average value of execution time across all known executions.';
7777

78+
-- Show how much shared memory AQO are using at the moment
7879
CREATEFUNCTIONaqo_memory_usage(
7980
OUT nametext,
8081
OUT allocated_sizeint,
8182
OUT used_sizeint
8283
)
8384
RETURNS SETOF record
8485
AS $$
85-
SELECT name, total_bytes, used_bytesFROM pg_backend_memory_contexts
86-
WHERE nameLIKE'AQO%'
87-
UNION
8886
SELECT name, allocated_size, sizeFROM pg_shmem_allocations
8987
WHERE nameLIKE'AQO%';
9088
$$ LANGUAGE SQL;
9189
COMMENT ON FUNCTION aqo_memory_usage() IS
92-
'Showallocated sizes and used sizes of aqo`s memory contexts and hash tables';
90+
'Showhow much shared memory AQO are using at the moment';
9391

9492
--
9593
-- Update or insert an aqo_data

‎aqo.c

Lines changed: 5 additions & 52 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
*
@@ -324,42 +309,11 @@ _PG_init(void)
324309
NULL,
325310
NULL);
326311

327-
prev_shmem_startup_hook=shmem_startup_hook;
328-
shmem_startup_hook=aqo_init_shmem;
329-
prev_planner_hook=planner_hook;
330-
planner_hook=aqo_planner;
331-
prev_ExecutorStart_hook=ExecutorStart_hook;
332-
ExecutorStart_hook=aqo_ExecutorStart;
333-
prev_ExecutorRun=ExecutorRun_hook;
334-
ExecutorRun_hook=aqo_ExecutorRun;
335-
prev_ExecutorEnd_hook=ExecutorEnd_hook;
336-
ExecutorEnd_hook=aqo_ExecutorEnd;
337-
338-
/* Cardinality prediction hooks. */
339-
prev_set_baserel_rows_estimate_hook=set_baserel_rows_estimate_hook;
340-
set_foreign_rows_estimate_hook=aqo_set_baserel_rows_estimate;
341-
set_baserel_rows_estimate_hook=aqo_set_baserel_rows_estimate;
342-
prev_get_parameterized_baserel_size_hook=get_parameterized_baserel_size_hook;
343-
get_parameterized_baserel_size_hook=aqo_get_parameterized_baserel_size;
344-
prev_set_joinrel_size_estimates_hook=set_joinrel_size_estimates_hook;
345-
set_joinrel_size_estimates_hook=aqo_set_joinrel_size_estimates;
346-
prev_get_parameterized_joinrel_size_hook=get_parameterized_joinrel_size_hook;
347-
get_parameterized_joinrel_size_hook=aqo_get_parameterized_joinrel_size;
348-
prev_estimate_num_groups_hook=estimate_num_groups_hook;
349-
estimate_num_groups_hook=aqo_estimate_num_groups_hook;
350-
parampathinfo_postinit_hook=ppi_hook;
351-
352-
prev_create_plan_hook=create_plan_hook;
353-
create_plan_hook=aqo_create_plan_hook;
354-
355-
/* Service hooks. */
356-
prev_ExplainOnePlan_hook=ExplainOnePlan_hook;
357-
ExplainOnePlan_hook=print_into_explain;
358-
prev_ExplainOneNode_hook=ExplainOneNode_hook;
359-
ExplainOneNode_hook=print_node_explain;
360-
361-
prev_create_upper_paths_hook=create_upper_paths_hook;
362-
create_upper_paths_hook=aqo_store_upper_signature_hook;
312+
aqo_shmem_init();
313+
aqo_preprocessing_init();
314+
aqo_postprocessing_init();
315+
aqo_cardinality_hooks_init();
316+
aqo_path_utils_init();
363317

364318
init_deactivated_queries_storage();
365319

@@ -394,7 +348,6 @@ _PG_init(void)
394348
RegisterAQOPlanNodeMethods();
395349

396350
EmitWarningsOnPlaceholders("aqo");
397-
RequestAddinShmemSpace(aqo_memsize());
398351
}
399352

400353
/*

‎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: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@
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+
2022
staticvoidon_shmem_shutdown(intcode,Datumarg);
2123

22-
void
24+
staticvoid
2325
aqo_init_shmem(void)
2426
{
2527
boolfound;
2628
HASHCTLinfo;
2729

28-
if (prev_shmem_startup_hook)
29-
prev_shmem_startup_hook();
30+
if (aqo_shmem_startup_next)
31+
aqo_shmem_startup_next();
3032

3133
aqo_state=NULL;
3234
stat_htab=NULL;
@@ -116,10 +118,14 @@ on_shmem_shutdown(int code, Datum arg)
116118
return;
117119
}
118120

119-
Size
120-
aqo_memsize(void)
121+
122+
/*
123+
* Requests any additional shared memory required for aqo.
124+
*/
125+
staticvoid
126+
aqo_shmem_request(void)
121127
{
122-
Sizesize;
128+
Sizesize;
123129

124130
size=MAXALIGN(sizeof(AQOSharedState));
125131
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(AQOSharedState)));
@@ -128,5 +134,14 @@ aqo_memsize(void)
128134
size=add_size(size,hash_estimate_size(fss_max_items,sizeof(DataEntry)));
129135
size=add_size(size,hash_estimate_size(fs_max_items,sizeof(QueriesEntry)));
130136

131-
returnsize;
137+
RequestAddinShmemSpace(size);
138+
}
139+
140+
void
141+
aqo_shmem_init(void)
142+
{
143+
aqo_shmem_startup_next=shmem_startup_hook;
144+
shmem_startup_hook=aqo_init_shmem;
145+
146+
aqo_shmem_request();
132147
}

‎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