@@ -100,7 +100,7 @@ static bool _aqo_stat_remove(uint64 queryid);
100100static bool _aqo_queries_remove (uint64 queryid );
101101static bool _aqo_qtexts_remove (uint64 queryid );
102102static 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 );
104104static double fs_distance (double * a , double * b , int len );
105105
106106PG_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 *
147147form_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 */
21472147bool
21482148update_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