Skip to content

Commit 44f8cb6

Browse files
Daniil AnisimovAlena0704
Daniil Anisimov
authored andcommitted
Add small bugfixes and refactoring.
Reviewed by: @Alena0704
1 parent 6c85f0a commit 44f8cb6

File tree

6 files changed

+34
-38
lines changed

6 files changed

+34
-38
lines changed

aqo.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static const struct config_enum_entry format_options[] = {
6161
};
6262

6363
/* Parameters of autotuning */
64-
int aqo_stat_size = STAT_SAMPLE_SIZE;
6564
int auto_tuning_window_size = 5;
6665
double auto_tuning_exploration = 0.1;
6766
int auto_tuning_max_iterations = 50;

aqo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ extern double predicted_ppi_rows;
211211
extern double fss_ppi_hash;
212212

213213
/* Parameters of autotuning */
214-
extern int aqo_stat_size;
215214
extern int auto_tuning_window_size;
216215
extern double auto_tuning_exploration;
217216
extern int auto_tuning_max_iterations;

hash.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ get_clause_hash(Expr *clause, int nargs, int *args_hash, int *eclass_hash)
326326
/*
327327
* Computes hash for given string.
328328
*/
329-
int
329+
static int
330330
get_str_hash(const char *str)
331331
{
332332
return DatumGetInt32(hash_any((const unsigned char *) str,
@@ -363,7 +363,7 @@ get_int_array_hash(int *arr, int len)
363363
* Sorts given array in-place to compute hash.
364364
* The hash is order-insensitive.
365365
*/
366-
int
366+
static int
367367
get_unsorted_unsafe_int_array_hash(int *arr, int len)
368368
{
369369
qsort(arr, len, sizeof(*arr), int_cmp);
@@ -378,7 +378,7 @@ get_unsorted_unsafe_int_array_hash(int *arr, int len)
378378
* using 'hash_any'.
379379
* Frees allocated memory before returning hash.
380380
*/
381-
int
381+
static int
382382
get_unordered_int_list_hash(List *lst)
383383
{
384384
int i = 0;
@@ -430,7 +430,7 @@ replace_patterns(const char *str, const char *start_pattern,
430430
* Computes hash for given feature subspace.
431431
* Hash is supposed to be clause-order-insensitive.
432432
*/
433-
int
433+
static int
434434
get_fss_hash(int clauses_hash, int eclasses_hash, int relidslist_hash)
435435
{
436436
int hashes[3];
@@ -499,7 +499,7 @@ remove_locations(const char *str)
499499
* Returns index of given value in given sorted integer array
500500
* or -1 if not found.
501501
*/
502-
int
502+
static int
503503
get_id_in_sorted_int_array(int val, int n, int *arr)
504504
{
505505
int *i;
@@ -518,7 +518,7 @@ get_id_in_sorted_int_array(int val, int n, int *arr)
518518
* Returns class of equivalence for given argument hash or 0 if such hash
519519
* does not belong to any equivalence class.
520520
*/
521-
int
521+
static int
522522
get_arg_eclass(int arg_hash, int nargs, int *args_hash, int *eclass_hash)
523523
{
524524
int di = get_id_in_sorted_int_array(arg_hash, nargs, args_hash);
@@ -533,7 +533,7 @@ get_arg_eclass(int arg_hash, int nargs, int *args_hash, int *eclass_hash)
533533
* Builds list of non-constant arguments of equivalence clauses
534534
* of given clauselist.
535535
*/
536-
void
536+
static void
537537
get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
538538
{
539539
RestrictInfo *rinfo;
@@ -579,7 +579,7 @@ get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
579579
/*
580580
* Returns class of an object in disjoint set.
581581
*/
582-
int
582+
static int
583583
disjoint_set_get_parent(int *p, int v)
584584
{
585585
if (p[v] == -1)
@@ -591,7 +591,7 @@ disjoint_set_get_parent(int *p, int v)
591591
/*
592592
* Merges two equivalence classes in disjoint set.
593593
*/
594-
void
594+
static void
595595
disjoint_set_merge_eclasses(int *p, int v1, int v2)
596596
{
597597
int p1,
@@ -611,7 +611,7 @@ disjoint_set_merge_eclasses(int *p, int v1, int v2)
611611
/*
612612
* Constructs disjoint set on arguments.
613613
*/
614-
int *
614+
static int *
615615
perform_eclasses_join(List *clauselist, int nargs, int *args_hash)
616616
{
617617
RestrictInfo *rinfo;
@@ -688,7 +688,7 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
688688
/*
689689
* Checks whether the given char is brace, i. e. '{' or '}'.
690690
*/
691-
bool
691+
static bool
692692
is_brace(char ch)
693693
{
694694
return ch == '{' || ch == '}';
@@ -697,7 +697,7 @@ is_brace(char ch)
697697
/*
698698
* Returns whether arguments list contain constants.
699699
*/
700-
bool
700+
static bool
701701
has_consts(List *lst)
702702
{
703703
ListCell *l;
@@ -711,7 +711,7 @@ has_consts(List *lst)
711711
/*
712712
* Returns pointer on the args list in clause or NULL.
713713
*/
714-
List **
714+
static List **
715715
get_clause_args_ptr(Expr *clause)
716716
{
717717
switch (clause->type)
@@ -737,7 +737,7 @@ get_clause_args_ptr(Expr *clause)
737737
/*
738738
* Returns whether the clause is an equivalence clause.
739739
*/
740-
bool
740+
static bool
741741
clause_is_eq_clause(Expr *clause)
742742
{
743743
/* TODO: fix this horrible mess */

postprocessing.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ learn_sample(aqo_obj_stat *ctx, RelSortOut *rels,
173173
* For given node specified by clauselist, relidslist and join_type restores
174174
* the same selectivities of clauses as were used at query optimization stage.
175175
*/
176-
List *
176+
static List *
177177
restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
178178
bool was_parametrized)
179179
{
@@ -336,7 +336,7 @@ should_learn(PlanState *ps, AQOPlanNode *node, aqo_obj_stat *ctx,
336336
"predicted rows: %.0lf, updated prediction: %.0lf",
337337
query_context.query_hash, node->fss, predicted, nrows);
338338

339-
*rfactor = 0.9 * (RELIABILITY_MAX - RELIABILITY_MIN);
339+
*rfactor = RELIABILITY_MIN + 0.9 * (RELIABILITY_MAX - RELIABILITY_MIN);
340340
return true;
341341
}
342342
}

preprocessing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
/* List of feature spaces, that are processing in this backend. */
7070
List *cur_classes = NIL;
7171

72-
int aqo_join_threshold = 0;
72+
int aqo_join_threshold = 3;
7373

7474
static planner_hook_type aqo_planner_next = NULL;
7575

storage.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static bool _aqo_stat_remove(uint64 queryid);
100100
static bool _aqo_queries_remove(uint64 queryid);
101101
static bool _aqo_qtexts_remove(uint64 queryid);
102102
static bool _aqo_data_remove(data_key *key);
103-
static bool neirest_neighbor(double **matrix, int old_rows, double *neighbor, int cols);
103+
static bool nearest_neighbor(double **matrix, int old_rows, double *neighbor, int cols);
104104
static double fs_distance(double *a, double *b, int len);
105105

106106
PG_FUNCTION_INFO_V1(aqo_query_stat);
@@ -143,7 +143,7 @@ update_fss_ext(uint64 fs, int fss, OkNNrdata *data, List *reloids)
143143
/*
144144
* Forms ArrayType object for storage from simple C-array matrix.
145145
*/
146-
ArrayType *
146+
static ArrayType *
147147
form_matrix(double *matrix, int nrows, int ncols)
148148
{
149149
Datum *elems;
@@ -375,8 +375,8 @@ aqo_query_stat(PG_FUNCTION_ARGS)
375375
MemoryContext per_query_ctx;
376376
MemoryContext oldcontext;
377377
Tuplestorestate *tupstore;
378-
Datum values[TOTAL_NCOLS + 1];
379-
bool nulls[TOTAL_NCOLS + 1];
378+
Datum values[TOTAL_NCOLS];
379+
bool nulls[TOTAL_NCOLS];
380380
HASH_SEQ_STATUS hash_seq;
381381
StatEntry *entry;
382382

@@ -408,13 +408,11 @@ aqo_query_stat(PG_FUNCTION_ARGS)
408408

409409
MemoryContextSwitchTo(oldcontext);
410410

411-
memset(nulls, 0, TOTAL_NCOLS + 1);
411+
memset(nulls, 0, TOTAL_NCOLS);
412412
LWLockAcquire(&aqo_state->stat_lock, LW_SHARED);
413413
hash_seq_init(&hash_seq, stat_htab);
414414
while ((entry = hash_seq_search(&hash_seq)) != NULL)
415415
{
416-
memset(nulls, 0, TOTAL_NCOLS + 1);
417-
418416
values[QUERYID] = Int64GetDatum(entry->queryid);
419417
values[NEXECS] = Int64GetDatum(entry->execs_without_aqo);
420418
values[NEXECS_AQO] = Int64GetDatum(entry->execs_with_aqo);
@@ -1507,8 +1505,8 @@ fs_distance(double *a, double *b, int len)
15071505
return res;
15081506
}
15091507

1510-
bool
1511-
neirest_neighbor(double **matrix, int old_rows, double *neibour, int cols)
1508+
static bool
1509+
nearest_neighbor(double **matrix, int old_rows, double *neibour, int cols)
15121510
{
15131511
int i;
15141512
for (i=0; i<old_rows; i++)
@@ -1538,7 +1536,7 @@ build_knn_matrix(OkNNrdata *data, const OkNNrdata *temp_data, double *features)
15381536

15391537
for (i = 0; i < temp_data->rows; i++)
15401538
{
1541-
if (k < aqo_K && !neirest_neighbor(data->matrix, old_rows,
1539+
if (k < aqo_K && !nearest_neighbor(data->matrix, old_rows,
15421540
temp_data->matrix[i],
15431541
data->cols))
15441542
{
@@ -1904,8 +1902,8 @@ aqo_queries(PG_FUNCTION_ARGS)
19041902
MemoryContext per_query_ctx;
19051903
MemoryContext oldcontext;
19061904
Tuplestorestate *tupstore;
1907-
Datum values[AQ_TOTAL_NCOLS + 1];
1908-
bool nulls[AQ_TOTAL_NCOLS + 1];
1905+
Datum values[AQ_TOTAL_NCOLS];
1906+
bool nulls[AQ_TOTAL_NCOLS];
19091907
HASH_SEQ_STATUS hash_seq;
19101908
QueriesEntry *entry;
19111909

@@ -1937,12 +1935,12 @@ aqo_queries(PG_FUNCTION_ARGS)
19371935

19381936
MemoryContextSwitchTo(oldcontext);
19391937

1938+
memset(nulls, 0, AQ_TOTAL_NCOLS);
1939+
19401940
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
19411941
hash_seq_init(&hash_seq, queries_htab);
19421942
while ((entry = hash_seq_search(&hash_seq)) != NULL)
19431943
{
1944-
memset(nulls, 0, AQ_TOTAL_NCOLS + 1);
1945-
19461944
values[AQ_QUERYID] = Int64GetDatum(entry->queryid);
19471945
values[AQ_FS] = Int64GetDatum(entry->fs);
19481946
values[AQ_LEARN_AQO] = BoolGetDatum(entry->learn_aqo);
@@ -2144,7 +2142,7 @@ aqo_queries_find(uint64 queryid, QueryContextData *ctx)
21442142

21452143
/*
21462144
* Function for update and save value of smart statement timeout
2147-
* for query in aqu_queries table
2145+
* for query in aqo_queries table
21482146
*/
21492147
bool
21502148
update_query_timeout(uint64 queryid, int64 smart_timeout)
@@ -2517,6 +2515,8 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
25172515
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
25182516
LWLockAcquire(&aqo_state->stat_lock, LW_SHARED);
25192517

2518+
memset(nulls, 0, AQE_TOTAL_NCOLS * sizeof(nulls[0]));
2519+
25202520
hash_seq_init(&hash_seq, queries_htab);
25212521
while ((qentry = hash_seq_search(&hash_seq)) != NULL)
25222522
{
@@ -2525,8 +2525,6 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
25252525
int64 nexecs;
25262526
int nvals;
25272527

2528-
memset(nulls, 0, AQE_TOTAL_NCOLS * sizeof(nulls[0]));
2529-
25302528
sentry = (StatEntry *) hash_search(stat_htab, &qentry->queryid,
25312529
HASH_FIND, &found);
25322530
if (!found)
@@ -2611,6 +2609,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
26112609
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
26122610
LWLockAcquire(&aqo_state->stat_lock, LW_SHARED);
26132611

2612+
memset(nulls, 0, ET_TOTAL_NCOLS * sizeof(nulls[0]));
2613+
26142614
hash_seq_init(&hash_seq, queries_htab);
26152615
while ((qentry = hash_seq_search(&hash_seq)) != NULL)
26162616
{
@@ -2620,8 +2620,6 @@ aqo_execution_time(PG_FUNCTION_ARGS)
26202620
int nvals;
26212621
double tm = 0;
26222622

2623-
memset(nulls, 0, ET_TOTAL_NCOLS * sizeof(nulls[0]));
2624-
26252623
sentry = (StatEntry *) hash_search(stat_htab, &qentry->queryid,
26262624
HASH_FIND, &found);
26272625
if (!found)

0 commit comments

Comments
 (0)