Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2569512

Browse files
Daniil Anisimovdanolivo
authored andcommitted
Fix. Conventionally use of hooks.
Also, some arrangement for stable14 added by a.lepikhov
1 parent b16e852 commit 2569512

File tree

6 files changed

+17
-61
lines changed

6 files changed

+17
-61
lines changed

aqo.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -309,50 +309,11 @@ _PG_init(void)
309309
NULL,
310310
NULL);
311311

312-
<<<<<<< HEAD
313-
prev_shmem_startup_hook = shmem_startup_hook;
314-
shmem_startup_hook = aqo_init_shmem;
315-
prev_planner_hook = planner_hook;
316-
planner_hook = aqo_planner;
317-
prev_ExecutorStart_hook = ExecutorStart_hook;
318-
ExecutorStart_hook = aqo_ExecutorStart;
319-
prev_ExecutorRun = ExecutorRun_hook;
320-
ExecutorRun_hook = aqo_ExecutorRun;
321-
prev_ExecutorEnd_hook = ExecutorEnd_hook;
322-
ExecutorEnd_hook = aqo_ExecutorEnd;
323-
324-
/* Cardinality prediction hooks. */
325-
prev_set_baserel_rows_estimate_hook = set_baserel_rows_estimate_hook;
326-
set_foreign_rows_estimate_hook = aqo_set_baserel_rows_estimate;
327-
set_baserel_rows_estimate_hook = aqo_set_baserel_rows_estimate;
328-
prev_get_parameterized_baserel_size_hook = get_parameterized_baserel_size_hook;
329-
get_parameterized_baserel_size_hook = aqo_get_parameterized_baserel_size;
330-
prev_set_joinrel_size_estimates_hook = set_joinrel_size_estimates_hook;
331-
set_joinrel_size_estimates_hook = aqo_set_joinrel_size_estimates;
332-
prev_get_parameterized_joinrel_size_hook = get_parameterized_joinrel_size_hook;
333-
get_parameterized_joinrel_size_hook = aqo_get_parameterized_joinrel_size;
334-
prev_estimate_num_groups_hook = estimate_num_groups_hook;
335-
estimate_num_groups_hook = aqo_estimate_num_groups_hook;
336-
parampathinfo_postinit_hook = ppi_hook;
337-
338-
prev_create_plan_hook = create_plan_hook;
339-
create_plan_hook = aqo_create_plan_hook;
340-
341-
/* Service hooks. */
342-
prev_ExplainOnePlan_hook = ExplainOnePlan_hook;
343-
ExplainOnePlan_hook = print_into_explain;
344-
prev_ExplainOneNode_hook = ExplainOneNode_hook;
345-
ExplainOneNode_hook = print_node_explain;
346-
347-
prev_create_upper_paths_hook = create_upper_paths_hook;
348-
create_upper_paths_hook = aqo_store_upper_signature_hook;
349-
=======
350312
aqo_shmem_init();
351313
aqo_preprocessing_init();
352314
aqo_postprocessing_init();
353315
aqo_cardinality_hooks_init();
354316
aqo_path_utils_init();
355-
>>>>>>> daf05a0 (Bugfix. Do away with possible conflict of hooks, declared as 'extern' in)
356317

357318
init_deactivated_queries_storage();
358319

@@ -387,7 +348,6 @@ _PG_init(void)
387348
RegisterAQOPlanNodeMethods();
388349

389350
EmitWarningsOnPlaceholders("aqo");
390-
RequestAddinShmemSpace(aqo_memsize());
391351
}
392352

393353
/*

aqo_shared.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ int fs_max_items = 10000; /* Max number of different feature spaces in ML model
1818
int fss_max_items = 100000; /* Max number of different feature subspaces in ML model */
1919

2020
static shmem_startup_hook_type aqo_shmem_startup_next = NULL;
21-
static shmem_request_hook_type aqo_shmem_request_next = NULL;
2221

2322
static void on_shmem_shutdown(int code, Datum arg);
2423

@@ -29,7 +28,7 @@ aqo_init_shmem(void)
2928
HASHCTL info;
3029

3130
if (aqo_shmem_startup_next)
32-
aqo_shmem_startup_next();
31+
(*aqo_shmem_startup_next)();
3332

3433
aqo_state = NULL;
3534
stat_htab = NULL;
@@ -128,9 +127,6 @@ aqo_shmem_request(void)
128127
{
129128
Size size;
130129

131-
if (aqo_shmem_request_next)
132-
aqo_shmem_request_next();
133-
134130
size = MAXALIGN(sizeof(AQOSharedState));
135131
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(AQOSharedState)));
136132
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(StatEntry)));
@@ -146,6 +142,6 @@ aqo_shmem_init(void)
146142
{
147143
aqo_shmem_startup_next = shmem_startup_hook;
148144
shmem_startup_hook = aqo_init_shmem;
149-
aqo_shmem_request_next = shmem_request_hook;
150-
shmem_request_hook = aqo_shmem_request;
145+
146+
aqo_shmem_request();
151147
}

cardinality_hooks.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel)
108108

109109
default_estimator:
110110
rel->predicted_cardinality = -1.;
111-
aqo_set_baserel_rows_estimate_next(root, rel);
111+
(*aqo_set_baserel_rows_estimate_next)(root, rel);
112112
}
113113

114114
static void
@@ -219,7 +219,7 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
219219
return predicted;
220220

221221
default_estimator:
222-
return aqo_get_parameterized_baserel_size_next(root, rel, param_clauses);
222+
return (*aqo_get_parameterized_baserel_size_next)(root, rel, param_clauses);
223223
}
224224

225225
/*
@@ -294,7 +294,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
294294

295295
default_estimator:
296296
rel->predicted_cardinality = -1;
297-
aqo_set_joinrel_size_estimates_next(root, rel, outer_rel, inner_rel,
297+
(*aqo_set_joinrel_size_estimates_next)(root, rel, outer_rel, inner_rel,
298298
sjinfo, restrictlist);
299299
}
300300

@@ -367,7 +367,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
367367
return predicted;
368368

369369
default_estimator:
370-
return aqo_get_parameterized_joinrel_size_next(root, rel,
370+
return (*aqo_get_parameterized_joinrel_size_next)(root, rel,
371371
outer_path, inner_path,
372372
sjinfo, clauses);
373373
}
@@ -456,7 +456,7 @@ aqo_estimate_num_groups_hook(PlannerInfo *root, List *groupExprs,
456456

457457
default_estimator:
458458
if (aqo_estimate_num_groups_next)
459-
return aqo_estimate_num_groups_next(root, groupExprs, subpath,
459+
return (*aqo_estimate_num_groups_next)(root, groupExprs, subpath,
460460
grouped_rel, pgset, estinfo);
461461
else
462462
return estimate_num_groups(root, groupExprs, subpath->rows,

path_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ aqo_create_plan(PlannerInfo *root, Path *src, Plan **dest)
541541
AQOPlanNode *node;
542542

543543
if (aqo_create_plan_next)
544-
aqo_create_plan_next(root, src, dest);
544+
(*aqo_create_plan_next)(root, src, dest);
545545

546546
if (!query_context.use_aqo && !query_context.learn_aqo &&
547547
!query_context.collect_stat)

postprocessing.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ aqo_ExecutorStart(QueryDesc *queryDesc, int eflags)
600600
StoreToQueryEnv(queryDesc);
601601
}
602602

603-
aqo_ExecutorStart_next(queryDesc, eflags);
603+
(*aqo_ExecutorStart_next)(queryDesc, eflags);
604604

605605
if (use_aqo)
606606
StorePlanInternals(queryDesc);
@@ -725,7 +725,7 @@ aqo_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count,
725725

726726
PG_TRY();
727727
{
728-
aqo_ExecutorRun_next(queryDesc, direction, count, execute_once);
728+
(*aqo_ExecutorRun_next)(queryDesc, direction, count, execute_once);
729729
}
730730
PG_FINALLY();
731731
{
@@ -841,7 +841,7 @@ aqo_ExecutorEnd(QueryDesc *queryDesc)
841841
MemoryContextSwitchTo(oldctx);
842842
MemoryContextReset(AQOLearnMemCtx);
843843

844-
aqo_ExecutorEnd_next(queryDesc);
844+
(*aqo_ExecutorEnd_next)(queryDesc);
845845

846846
/*
847847
* standard_ExecutorEnd clears the queryDesc->planstate. After this point no
@@ -982,7 +982,7 @@ print_into_explain(PlannedStmt *plannedstmt, IntoClause *into,
982982
QueryEnvironment *queryEnv)
983983
{
984984
if (aqo_ExplainOnePlan_next)
985-
aqo_ExplainOnePlan_next(plannedstmt, into, es, queryString,
985+
(*aqo_ExplainOnePlan_next)(plannedstmt, into, es, queryString,
986986
params, planduration, queryEnv);
987987

988988
if (IsQueryDisabled() || !aqo_show_details)
@@ -1038,7 +1038,7 @@ print_node_explain(ExplainState *es, PlanState *ps, Plan *plan)
10381038

10391039
/* Extension, which took a hook early can be executed early too. */
10401040
if (aqo_ExplainOneNode_next)
1041-
aqo_ExplainOneNode_next(es, ps, plan);
1041+
(*aqo_ExplainOneNode_next)(es, ps, plan);
10421042

10431043
if (IsQueryDisabled() || !plan || es->format != EXPLAIN_FORMAT_TEXT)
10441044
return;

preprocessing.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ aqo_planner(Query *parse, const char *query_string, int cursorOptions,
128128
MemoryContextSwitchTo(oldctx);
129129
disable_aqo_for_query();
130130

131-
return aqo_planner_next(parse, query_string, cursorOptions, boundParams);
131+
return (*aqo_planner_next)(parse, query_string, cursorOptions, boundParams);
132132
}
133133

134134
selectivity_cache_clear();
@@ -149,7 +149,7 @@ aqo_planner(Query *parse, const char *query_string, int cursorOptions,
149149
MemoryContextSwitchTo(oldctx);
150150
disable_aqo_for_query();
151151

152-
return aqo_planner_next(parse, query_string, cursorOptions, boundParams);
152+
return (*aqo_planner_next)(parse, query_string, cursorOptions, boundParams);
153153
}
154154

155155
elog(DEBUG1, "AQO will be used for query '%s', class "UINT64_FORMAT,
@@ -322,7 +322,7 @@ aqo_planner(Query *parse, const char *query_string, int cursorOptions,
322322
/* Release the memory, allocated for AQO predictions */
323323
MemoryContextReset(AQOPredictMemCtx);
324324

325-
stmt = aqo_planner_next(parse, query_string, cursorOptions, boundParams);
325+
stmt = (*aqo_planner_next)(parse, query_string, cursorOptions, boundParams);
326326
return stmt;
327327
}
328328
}

0 commit comments

Comments
 (0)