Skip to content

Commit e658efe

Browse files
Daniil AnisimovAlena0704
authored andcommitted
Add small bugfixes and refactoring.
Reviewed by: @Alena0704
1 parent baa4043 commit e658efe

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-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
@@ -344,7 +344,7 @@ get_clause_hash(Expr *clause, int nargs, int *args_hash, int *eclass_hash)
344344
/*
345345
* Computes hash for given string.
346346
*/
347-
int
347+
static int
348348
get_str_hash(const char *str)
349349
{
350350
return DatumGetInt32(hash_any((const unsigned char *) str,
@@ -381,7 +381,7 @@ get_int_array_hash(int *arr, int len)
381381
* Sorts given array in-place to compute hash.
382382
* The hash is order-insensitive.
383383
*/
384-
int
384+
static int
385385
get_unsorted_unsafe_int_array_hash(int *arr, int len)
386386
{
387387
qsort(arr, len, sizeof(*arr), int_cmp);
@@ -396,7 +396,7 @@ get_unsorted_unsafe_int_array_hash(int *arr, int len)
396396
* using 'hash_any'.
397397
* Frees allocated memory before returning hash.
398398
*/
399-
int
399+
static int
400400
get_unordered_int_list_hash(List *lst)
401401
{
402402
int i = 0;
@@ -448,7 +448,7 @@ replace_patterns(const char *str, const char *start_pattern,
448448
* Computes hash for given feature subspace.
449449
* Hash is supposed to be clause-order-insensitive.
450450
*/
451-
int
451+
static int
452452
get_fss_hash(int clauses_hash, int eclasses_hash, int relidslist_hash)
453453
{
454454
int hashes[3];
@@ -517,7 +517,7 @@ remove_locations(const char *str)
517517
* Returns index of given value in given sorted integer array
518518
* or -1 if not found.
519519
*/
520-
int
520+
static int
521521
get_id_in_sorted_int_array(int val, int n, int *arr)
522522
{
523523
int *i;
@@ -536,7 +536,7 @@ get_id_in_sorted_int_array(int val, int n, int *arr)
536536
* Returns class of equivalence for given argument hash or 0 if such hash
537537
* does not belong to any equivalence class.
538538
*/
539-
int
539+
static int
540540
get_arg_eclass(int arg_hash, int nargs, int *args_hash, int *eclass_hash)
541541
{
542542
int di = get_id_in_sorted_int_array(arg_hash, nargs, args_hash);
@@ -551,7 +551,7 @@ get_arg_eclass(int arg_hash, int nargs, int *args_hash, int *eclass_hash)
551551
* Builds list of non-constant arguments of equivalence clauses
552552
* of given clauselist.
553553
*/
554-
void
554+
static void
555555
get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
556556
{
557557
RestrictInfo *rinfo;
@@ -597,7 +597,7 @@ get_clauselist_args(List *clauselist, int *nargs, int **args_hash)
597597
/*
598598
* Returns class of an object in disjoint set.
599599
*/
600-
int
600+
static int
601601
disjoint_set_get_parent(int *p, int v)
602602
{
603603
if (p[v] == -1)
@@ -609,7 +609,7 @@ disjoint_set_get_parent(int *p, int v)
609609
/*
610610
* Merges two equivalence classes in disjoint set.
611611
*/
612-
void
612+
static void
613613
disjoint_set_merge_eclasses(int *p, int v1, int v2)
614614
{
615615
int p1,
@@ -629,7 +629,7 @@ disjoint_set_merge_eclasses(int *p, int v1, int v2)
629629
/*
630630
* Constructs disjoint set on arguments.
631631
*/
632-
int *
632+
static int *
633633
perform_eclasses_join(List *clauselist, int nargs, int *args_hash)
634634
{
635635
RestrictInfo *rinfo;
@@ -706,7 +706,7 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
706706
/*
707707
* Checks whether the given char is brace, i. e. '{' or '}'.
708708
*/
709-
bool
709+
static bool
710710
is_brace(char ch)
711711
{
712712
return ch == '{' || ch == '}';
@@ -715,7 +715,7 @@ is_brace(char ch)
715715
/*
716716
* Returns whether arguments list contain constants.
717717
*/
718-
bool
718+
static bool
719719
has_consts(List *lst)
720720
{
721721
ListCell *l;
@@ -729,7 +729,7 @@ has_consts(List *lst)
729729
/*
730730
* Returns pointer on the args list in clause or NULL.
731731
*/
732-
List **
732+
static List **
733733
get_clause_args_ptr(Expr *clause)
734734
{
735735
switch (clause->type)
@@ -755,7 +755,7 @@ get_clause_args_ptr(Expr *clause)
755755
/*
756756
* Returns whether the clause is an equivalence clause.
757757
*/
758-
bool
758+
static bool
759759
clause_is_eq_clause(Expr *clause)
760760
{
761761
/* 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: 19 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,9 @@ 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, data->matrix[i], data->cols))
1539+
if (k < aqo_K && !nearest_neighbor(data->matrix, old_rows,
1540+
temp_data->matrix[i],
1541+
data->cols))
15421542
{
15431543
memcpy(data->matrix[k], temp_data->matrix[i], data->cols * sizeof(double));
15441544
data->rfactors[k] = temp_data->rfactors[i];
@@ -1902,8 +1902,8 @@ aqo_queries(PG_FUNCTION_ARGS)
19021902
MemoryContext per_query_ctx;
19031903
MemoryContext oldcontext;
19041904
Tuplestorestate *tupstore;
1905-
Datum values[AQ_TOTAL_NCOLS + 1];
1906-
bool nulls[AQ_TOTAL_NCOLS + 1];
1905+
Datum values[AQ_TOTAL_NCOLS];
1906+
bool nulls[AQ_TOTAL_NCOLS];
19071907
HASH_SEQ_STATUS hash_seq;
19081908
QueriesEntry *entry;
19091909

@@ -1935,12 +1935,12 @@ aqo_queries(PG_FUNCTION_ARGS)
19351935

19361936
MemoryContextSwitchTo(oldcontext);
19371937

1938+
memset(nulls, 0, AQ_TOTAL_NCOLS);
1939+
19381940
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
19391941
hash_seq_init(&hash_seq, queries_htab);
19401942
while ((entry = hash_seq_search(&hash_seq)) != NULL)
19411943
{
1942-
memset(nulls, 0, AQ_TOTAL_NCOLS + 1);
1943-
19441944
values[AQ_QUERYID] = Int64GetDatum(entry->queryid);
19451945
values[AQ_FS] = Int64GetDatum(entry->fs);
19461946
values[AQ_LEARN_AQO] = BoolGetDatum(entry->learn_aqo);
@@ -2142,7 +2142,7 @@ aqo_queries_find(uint64 queryid, QueryContextData *ctx)
21422142

21432143
/*
21442144
* Function for update and save value of smart statement timeout
2145-
* for query in aqu_queries table
2145+
* for query in aqo_queries table
21462146
*/
21472147
bool
21482148
update_query_timeout(uint64 queryid, int64 smart_timeout)
@@ -2515,6 +2515,8 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
25152515
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
25162516
LWLockAcquire(&aqo_state->stat_lock, LW_SHARED);
25172517

2518+
memset(nulls, 0, AQE_TOTAL_NCOLS * sizeof(nulls[0]));
2519+
25182520
hash_seq_init(&hash_seq, queries_htab);
25192521
while ((qentry = hash_seq_search(&hash_seq)) != NULL)
25202522
{
@@ -2523,8 +2525,6 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
25232525
int64 nexecs;
25242526
int nvals;
25252527

2526-
memset(nulls, 0, AQE_TOTAL_NCOLS * sizeof(nulls[0]));
2527-
25282528
sentry = (StatEntry *) hash_search(stat_htab, &qentry->queryid,
25292529
HASH_FIND, &found);
25302530
if (!found)
@@ -2609,6 +2609,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
26092609
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
26102610
LWLockAcquire(&aqo_state->stat_lock, LW_SHARED);
26112611

2612+
memset(nulls, 0, ET_TOTAL_NCOLS * sizeof(nulls[0]));
2613+
26122614
hash_seq_init(&hash_seq, queries_htab);
26132615
while ((qentry = hash_seq_search(&hash_seq)) != NULL)
26142616
{
@@ -2618,8 +2620,6 @@ aqo_execution_time(PG_FUNCTION_ARGS)
26182620
int nvals;
26192621
double tm = 0;
26202622

2621-
memset(nulls, 0, ET_TOTAL_NCOLS * sizeof(nulls[0]));
2622-
26232623
sentry = (StatEntry *) hash_search(stat_htab, &qentry->queryid,
26242624
HASH_FIND, &found);
26252625
if (!found)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy