Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite658efe

Browse files
Daniil AnisimovAlena0704
Daniil Anisimov
authored andcommitted
Add small bugfixes and refactoring.
Reviewed by:@Alena0704
1 parentbaa4043 commite658efe

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-
intaqo_stat_size=STAT_SAMPLE_SIZE;
6564
intauto_tuning_window_size=5;
6665
doubleauto_tuning_exploration=0.1;
6766
intauto_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
externdoublefss_ppi_hash;
212212

213213
/* Parameters of autotuning */
214-
externintaqo_stat_size;
215214
externintauto_tuning_window_size;
216215
externdoubleauto_tuning_exploration;
217216
externintauto_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+
staticint
348348
get_str_hash(constchar*str)
349349
{
350350
returnDatumGetInt32(hash_any((constunsignedchar*)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+
staticint
385385
get_unsorted_unsafe_int_array_hash(int*arr,intlen)
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+
staticint
400400
get_unordered_int_list_hash(List*lst)
401401
{
402402
inti=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+
staticint
452452
get_fss_hash(intclauses_hash,inteclasses_hash,intrelidslist_hash)
453453
{
454454
inthashes[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+
staticint
521521
get_id_in_sorted_int_array(intval,intn,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+
staticint
540540
get_arg_eclass(intarg_hash,intnargs,int*args_hash,int*eclass_hash)
541541
{
542542
intdi=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+
staticvoid
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+
staticint
601601
disjoint_set_get_parent(int*p,intv)
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+
staticvoid
613613
disjoint_set_merge_eclasses(int*p,intv1,intv2)
614614
{
615615
intp1,
@@ -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+
staticint*
633633
perform_eclasses_join(List*clauselist,intnargs,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+
staticbool
710710
is_brace(charch)
711711
{
712712
returnch=='{'||ch=='}';
@@ -715,7 +715,7 @@ is_brace(char ch)
715715
/*
716716
* Returns whether arguments list contain constants.
717717
*/
718-
bool
718+
staticbool
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+
staticList**
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+
staticbool
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+
staticList*
177177
restore_selectivities(List*clauselist,List*relidslist,JoinTypejoin_type,
178178
boolwas_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-
intaqo_join_threshold=0;
72+
intaqo_join_threshold=3;
7373

7474
staticplanner_hook_typeaqo_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
staticbool_aqo_queries_remove(uint64queryid);
101101
staticbool_aqo_qtexts_remove(uint64queryid);
102102
staticbool_aqo_data_remove(data_key*key);
103-
staticboolneirest_neighbor(double**matrix,intold_rows,double*neighbor,intcols);
103+
staticboolnearest_neighbor(double**matrix,intold_rows,double*neighbor,intcols);
104104
staticdoublefs_distance(double*a,double*b,intlen);
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+
staticArrayType*
147147
form_matrix(double*matrix,intnrows,intncols)
148148
{
149149
Datum*elems;
@@ -375,8 +375,8 @@ aqo_query_stat(PG_FUNCTION_ARGS)
375375
MemoryContextper_query_ctx;
376376
MemoryContextoldcontext;
377377
Tuplestorestate*tupstore;
378-
Datumvalues[TOTAL_NCOLS+1];
379-
boolnulls[TOTAL_NCOLS+1];
378+
Datumvalues[TOTAL_NCOLS];
379+
boolnulls[TOTAL_NCOLS];
380380
HASH_SEQ_STATUShash_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
returnres;
15081506
}
15091507

1510-
bool
1511-
neirest_neighbor(double**matrix,intold_rows,double*neibour,intcols)
1508+
staticbool
1509+
nearest_neighbor(double**matrix,intold_rows,double*neibour,intcols)
15121510
{
15131511
inti;
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
MemoryContextper_query_ctx;
19031903
MemoryContextoldcontext;
19041904
Tuplestorestate*tupstore;
1905-
Datumvalues[AQ_TOTAL_NCOLS+1];
1906-
boolnulls[AQ_TOTAL_NCOLS+1];
1905+
Datumvalues[AQ_TOTAL_NCOLS];
1906+
boolnulls[AQ_TOTAL_NCOLS];
19071907
HASH_SEQ_STATUShash_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 inaqu_queries table
2145+
* for query inaqo_queries table
21462146
*/
21472147
bool
21482148
update_query_timeout(uint64queryid,int64smart_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
int64nexecs;
25242526
intnvals;
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
intnvals;
26192621
doubletm=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)

[8]ページ先頭

©2009-2025 Movatter.jp