Skip to content

Commit 8810877

Browse files
committed
Change AQO code caused by planner's interface improvements (6aba63ef3e60).
Also, some code readability improvements were made.
1 parent 35ef80b commit 8810877

File tree

2 files changed

+60
-42
lines changed

2 files changed

+60
-42
lines changed

aqo.h

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ extern double log_selectivity_lower_bound;
243243
/* Parameters for current query */
244244
extern QueryContextData query_context;
245245
extern int njoins;
246-
extern char *query_text;
246+
extern char *query_text;
247247

248248
/* Memory context for long-live data */
249249
extern MemoryContext AQOMemoryContext;
@@ -253,63 +253,64 @@ extern post_parse_analyze_hook_type prev_post_parse_analyze_hook;
253253
extern planner_hook_type prev_planner_hook;
254254
extern ExecutorStart_hook_type prev_ExecutorStart_hook;
255255
extern ExecutorEnd_hook_type prev_ExecutorEnd_hook;
256-
extern set_baserel_rows_estimate_hook_type
257-
prev_set_baserel_rows_estimate_hook;
258-
extern get_parameterized_baserel_size_hook_type
259-
prev_get_parameterized_baserel_size_hook;
260-
extern set_joinrel_size_estimates_hook_type
261-
prev_set_joinrel_size_estimates_hook;
262-
extern get_parameterized_joinrel_size_hook_type
263-
prev_get_parameterized_joinrel_size_hook;
264-
extern copy_generic_path_info_hook_type
265-
prev_copy_generic_path_info_hook;
256+
extern set_baserel_rows_estimate_hook_type
257+
prev_set_baserel_rows_estimate_hook;
258+
extern get_parameterized_baserel_size_hook_type
259+
prev_get_parameterized_baserel_size_hook;
260+
extern set_joinrel_size_estimates_hook_type
261+
prev_set_joinrel_size_estimates_hook;
262+
extern get_parameterized_joinrel_size_hook_type
263+
prev_get_parameterized_joinrel_size_hook;
264+
extern copy_generic_path_info_hook_type prev_copy_generic_path_info_hook;
266265
extern ExplainOnePlan_hook_type prev_ExplainOnePlan_hook;
267266

268267
extern void ppi_hook(ParamPathInfo *ppi);
269268

270269
/* Hash functions */
271-
int get_query_hash(Query *parse, const char *query_text);
270+
int get_query_hash(Query *parse, const char *query_text);
272271
extern int get_fss_for_object(List *clauselist, List *selectivities,
273-
List *relidslist, int *nfeatures, double **features);
274-
void get_eclasses(List *clauselist, int *nargs,
275-
int **args_hash, int **eclass_hash);
276-
int get_clause_hash(Expr *clause, int nargs,
277-
int *args_hash, int *eclass_hash);
272+
List *relidslist, int *nfeatures,
273+
double **features);
274+
void get_eclasses(List *clauselist, int *nargs, int **args_hash,
275+
int **eclass_hash);
276+
int get_clause_hash(Expr *clause, int nargs, int *args_hash, int *eclass_hash);
278277

279278

280279
/* Storage interaction */
281280
bool find_query(int query_hash,
282-
Datum *search_values,
283-
bool *search_nulls);
281+
Datum *search_values,
282+
bool *search_nulls);
284283
bool add_query(int query_hash, bool learn_aqo, bool use_aqo,
285-
int fspace_hash, bool auto_tuning);
284+
int fspace_hash, bool auto_tuning);
286285
bool update_query(int query_hash, bool learn_aqo, bool use_aqo,
287-
int fspace_hash, bool auto_tuning);
288-
bool add_query_text(int query_hash, const char *query_text);
286+
int fspace_hash, bool auto_tuning);
287+
bool add_query_text(int query_hash, const char *query_text);
289288
bool load_fss(int fss_hash, int ncols,
290289
double **matrix, double *targets, int *rows);
291290
extern bool update_fss(int fss_hash, int nrows, int ncols,
292291
double **matrix, double *targets);
293-
QueryStat *get_aqo_stat(int query_hash);
294-
void update_aqo_stat(int query_hash, QueryStat * stat);
295-
void init_deactivated_queries_storage(void);
296-
void fini_deactivated_queries_storage(void);
297-
bool query_is_deactivated(int query_hash);
298-
void add_deactivated_query(int query_hash);
292+
QueryStat *get_aqo_stat(int query_hash);
293+
void update_aqo_stat(int query_hash, QueryStat * stat);
294+
void init_deactivated_queries_storage(void);
295+
void fini_deactivated_queries_storage(void);
296+
bool query_is_deactivated(int query_hash);
297+
void add_deactivated_query(int query_hash);
299298

300299
/* Query preprocessing hooks */
301-
void get_query_text(ParseState *pstate, Query *query);
300+
void get_query_text(ParseState *pstate, Query *query);
302301
PlannedStmt *call_default_planner(Query *parse,
303-
int cursorOptions,
304-
ParamListInfo boundParams);
302+
const char *query_string,
303+
int cursorOptions,
304+
ParamListInfo boundParams);
305305
PlannedStmt *aqo_planner(Query *parse,
306-
int cursorOptions,
307-
ParamListInfo boundParams);
306+
const char *query_string,
307+
int cursorOptions,
308+
ParamListInfo boundParams);
308309
void print_into_explain(PlannedStmt *plannedstmt, IntoClause *into,
309-
ExplainState *es, const char *queryString,
310-
ParamListInfo params, const instr_time *planduration,
311-
QueryEnvironment *queryEnv);
312-
void disable_aqo_for_query(void);
310+
ExplainState *es, const char *queryString,
311+
ParamListInfo params, const instr_time *planduration,
312+
QueryEnvironment *queryEnv);
313+
void disable_aqo_for_query(void);
313314

314315
/* Cardinality estimation hooks */
315316
extern void aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel);

preprocessing.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,20 @@ get_query_text(ParseState *pstate, Query *query)
9191
*/
9292
PlannedStmt *
9393
call_default_planner(Query *parse,
94+
const char *query_string,
9495
int cursorOptions,
9596
ParamListInfo boundParams)
9697
{
9798
if (prev_planner_hook)
98-
return prev_planner_hook(parse, cursorOptions, boundParams);
99+
return prev_planner_hook(parse,
100+
query_string,
101+
cursorOptions,
102+
boundParams);
99103
else
100-
return standard_planner(parse, cursorOptions, boundParams);
104+
return standard_planner(parse,
105+
query_string,
106+
cursorOptions,
107+
boundParams);
101108
}
102109

103110
/*
@@ -110,6 +117,7 @@ call_default_planner(Query *parse,
110117
*/
111118
PlannedStmt *
112119
aqo_planner(Query *parse,
120+
const char *query_string,
113121
int cursorOptions,
114122
ParamListInfo boundParams)
115123
{
@@ -134,7 +142,10 @@ aqo_planner(Query *parse,
134142
RecoveryInProgress())
135143
{
136144
disable_aqo_for_query();
137-
return call_default_planner(parse, cursorOptions, boundParams);
145+
return call_default_planner(parse,
146+
query_string,
147+
cursorOptions,
148+
boundParams);
138149
}
139150

140151
INSTR_TIME_SET_CURRENT(query_context.query_starttime);
@@ -144,7 +155,10 @@ aqo_planner(Query *parse,
144155
if (query_is_deactivated(query_context.query_hash))
145156
{
146157
disable_aqo_for_query();
147-
return call_default_planner(parse, cursorOptions, boundParams);
158+
return call_default_planner(parse,
159+
query_string,
160+
cursorOptions,
161+
boundParams);
148162
}
149163

150164
query_is_stored = find_query(query_context.query_hash, &query_params[0],
@@ -274,7 +288,10 @@ aqo_planner(Query *parse,
274288
query_context.fspace_hash = query_context.query_hash;
275289
}
276290

277-
return call_default_planner(parse, cursorOptions, boundParams);
291+
return call_default_planner(parse,
292+
query_string,
293+
cursorOptions,
294+
boundParams);
278295
}
279296

280297
/*

0 commit comments

Comments
 (0)