Skip to content

Commit ae2caf2

Browse files
Alena Rybakinadanolivo
Alena Rybakina
authored andcommitted
Cherry-pick from stable15 of two bonded commits:
1. Load neighbours with the fss hash except duplicated neighours. Rewrite test for look-a-like functional. Current tests contain correlation columns and queries have more nodes and description features. Add aqo_k as custom parameter to define few number of features for prediction. Its default value is 3. Queries can contain a larger number of features than 3 especially generic queries. Also add predict_a_few_neibours parameter for switch avalable to predict a few neibors than 3. It is done for not to change the previous logic of the code 2. Add disabled nestloop and mergejoin parameters to stabilize look-a-like test, besides add two additional cases where look-a-like should not be applied.
1 parent de7d405 commit ae2caf2

File tree

8 files changed

+663
-196
lines changed

8 files changed

+663
-196
lines changed

Diff for: aqo.c

+25-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void _PG_init(void);
3838
/* Strategy of determining feature space for new queries. */
3939
int aqo_mode = AQO_MODE_CONTROLLED;
4040
bool force_collect_stat;
41+
bool aqo_predict_with_few_neighbors;
4142

4243
/*
4344
* Show special info in EXPLAIN mode.
@@ -75,7 +76,7 @@ int auto_tuning_infinite_loop = 8;
7576
/* Machine learning parameters */
7677

7778
/* The number of nearest neighbors which will be chosen for ML-operations */
78-
int aqo_k = 3;
79+
int aqo_k;
7980
double log_selectivity_lower_bound = -30;
8081

8182
bool cleanup_bgworker = false;
@@ -415,6 +416,29 @@ _PG_init(void)
415416
NULL
416417
);
417418

419+
DefineCustomIntVariable("aqo.k_neighbors_threshold",
420+
"Set the threshold of number of neighbors for predicting.",
421+
NULL,
422+
&aqo_k,
423+
3,
424+
1, INT_MAX / 1000,
425+
PGC_USERSET,
426+
0,
427+
NULL,
428+
NULL,
429+
NULL);
430+
431+
DefineCustomBoolVariable("aqo.predict_with_few_neighbors",
432+
"Make prediction with less neighbors than we should have.",
433+
NULL,
434+
&aqo_predict_with_few_neighbors,
435+
true,
436+
PGC_USERSET,
437+
0,
438+
NULL,
439+
NULL,
440+
NULL);
441+
418442
prev_shmem_startup_hook = shmem_startup_hook;
419443
shmem_startup_hook = aqo_init_shmem;
420444
prev_planner_hook = planner_hook;

Diff for: aqo.h

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ extern double auto_tuning_convergence_error;
217217
/* Machine learning parameters */
218218

219219
extern int aqo_k;
220+
extern bool aqo_predict_with_few_neighbors;
220221
extern double log_selectivity_lower_bound;
221222

222223
/* Parameters for current query */

Diff for: cardinality_estimation.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ predict_for_relation(List *clauses, List *selectivities, List *relsigns,
9393
*/
9494

9595
/* Try to search in surrounding feature spaces for the same node */
96-
if (!load_aqo_data(query_context.fspace_hash, *fss, data, NULL, use_wide_search))
96+
if (!load_aqo_data(query_context.fspace_hash, *fss, data, NULL, use_wide_search, features))
9797
result = -1;
9898
else
9999
{

0 commit comments

Comments
 (0)