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

Commit44f8cb6

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

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-
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
@@ -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+
staticint
330330
get_str_hash(constchar*str)
331331
{
332332
returnDatumGetInt32(hash_any((constunsignedchar*)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+
staticint
367367
get_unsorted_unsafe_int_array_hash(int*arr,intlen)
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+
staticint
382382
get_unordered_int_list_hash(List*lst)
383383
{
384384
inti=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+
staticint
434434
get_fss_hash(intclauses_hash,inteclasses_hash,intrelidslist_hash)
435435
{
436436
inthashes[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+
staticint
503503
get_id_in_sorted_int_array(intval,intn,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+
staticint
522522
get_arg_eclass(intarg_hash,intnargs,int*args_hash,int*eclass_hash)
523523
{
524524
intdi=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+
staticvoid
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+
staticint
583583
disjoint_set_get_parent(int*p,intv)
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+
staticvoid
595595
disjoint_set_merge_eclasses(int*p,intv1,intv2)
596596
{
597597
intp1,
@@ -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+
staticint*
615615
perform_eclasses_join(List*clauselist,intnargs,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+
staticbool
692692
is_brace(charch)
693693
{
694694
returnch=='{'||ch=='}';
@@ -697,7 +697,7 @@ is_brace(char ch)
697697
/*
698698
* Returns whether arguments list contain constants.
699699
*/
700-
bool
700+
staticbool
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+
staticList**
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+
staticbool
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+
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: 17 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,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
MemoryContextper_query_ctx;
19051903
MemoryContextoldcontext;
19061904
Tuplestorestate*tupstore;
1907-
Datumvalues[AQ_TOTAL_NCOLS+1];
1908-
boolnulls[AQ_TOTAL_NCOLS+1];
1905+
Datumvalues[AQ_TOTAL_NCOLS];
1906+
boolnulls[AQ_TOTAL_NCOLS];
19091907
HASH_SEQ_STATUShash_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 inaqu_queries table
2145+
* for query inaqo_queries table
21482146
*/
21492147
bool
21502148
update_query_timeout(uint64queryid,int64smart_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
int64nexecs;
25262526
intnvals;
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
intnvals;
26212621
doubletm=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)

[8]ページ先頭

©2009-2025 Movatter.jp