Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion aqo.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void _PG_init(void);
/* Strategy of determining feature space for new queries. */
int aqo_mode = AQO_MODE_CONTROLLED;
bool force_collect_stat;
bool aqo_predict_with_few_neighbors;

/*
* Show special info in EXPLAIN mode.
Expand Down Expand Up @@ -71,7 +72,7 @@ int auto_tuning_infinite_loop = 8;
/* Machine learning parameters */

/* The number of nearest neighbors which will be chosen for ML-operations */
int aqo_k = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Должно быть задано значение по-умолчанию, которое совпадает с умолчальным в точке объявления GUC'a - иначе тесты мастера не пройдет.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, значение по умолчанию берется равным 3.

int aqo_k;
double log_selectivity_lower_bound = -30;

/*
Expand Down Expand Up @@ -287,6 +288,29 @@ _PG_init(void)
NULL
);

DefineCustomIntVariable("aqo.k_neighbors_threshold",
"Set the threshold of number of neighbors for predicting.",
NULL,
&aqo_k,
3,
1, INT_MAX / 1000,
PGC_USERSET,
0,
NULL,
NULL,
NULL);

DefineCustomBoolVariable("aqo.predict_with_few_neighbors",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот параметр нужен только для тестирования или зачем? Стоит откомментировать его , иначе непонятна необходимость.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Параметр нужен для того, чтобы не считались предсказания, если найдено меньшее количество соседей, чем задано в параметре min_neighbors_for_predicting. Без этой настройки, aqo сразу делает предсказание при одном найденном соседе, что может быть в некоторых случаях неверно.
Тут дается дополнительная возможность дождаться, когда aqo обучиться и запросов в базе знаний станет достаточно для получения средней оценки, например, на основе трех соседей.

"Make prediction with less neighbors than we should have.",
NULL,
&aqo_predict_with_few_neighbors,
true,
PGC_USERSET,
0,
NULL,
NULL,
NULL);

prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = aqo_init_shmem;
prev_planner_hook = planner_hook;
Expand Down
1 change: 1 addition & 0 deletions aqo.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ extern double auto_tuning_convergence_error;
/* Machine learning parameters */

extern int aqo_k;
extern bool aqo_predict_with_few_neighbors;
extern double log_selectivity_lower_bound;

/* Parameters for current query */
Expand Down
2 changes: 1 addition & 1 deletion cardinality_estimation.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ predict_for_relation(List *clauses, List *selectivities, List *relsigns,
*/

/* Try to search in surrounding feature spaces for the same node */
if (!load_aqo_data(query_context.fspace_hash, *fss, data, NULL, use_wide_search))
if (!load_aqo_data(query_context.fspace_hash, *fss, data, NULL, use_wide_search, features))
result = -1;
else
{
Expand Down
Loading