@@ -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{
149149Datum * elems ;
@@ -375,8 +375,8 @@ aqo_query_stat(PG_FUNCTION_ARGS)
375375MemoryContext per_query_ctx ;
376376MemoryContext oldcontext ;
377377Tuplestorestate * tupstore ;
378- Datum values [TOTAL_NCOLS + 1 ];
379- bool nulls [TOTAL_NCOLS + 1 ];
378+ Datum values [TOTAL_NCOLS ];
379+ bool nulls [TOTAL_NCOLS ];
380380HASH_SEQ_STATUS hash_seq ;
381381StatEntry * entry ;
382382
@@ -408,13 +408,11 @@ aqo_query_stat(PG_FUNCTION_ARGS)
408408
409409MemoryContextSwitchTo (oldcontext );
410410
411- memset (nulls ,0 ,TOTAL_NCOLS + 1 );
411+ memset (nulls ,0 ,TOTAL_NCOLS );
412412LWLockAcquire (& aqo_state -> stat_lock ,LW_SHARED );
413413hash_seq_init (& hash_seq ,stat_htab );
414414while ((entry = hash_seq_search (& hash_seq ))!= NULL )
415415{
416- memset (nulls ,0 ,TOTAL_NCOLS + 1 );
417-
418416values [QUERYID ]= Int64GetDatum (entry -> queryid );
419417values [NEXECS ]= Int64GetDatum (entry -> execs_without_aqo );
420418values [NEXECS_AQO ]= Int64GetDatum (entry -> execs_with_aqo );
@@ -1507,8 +1505,8 @@ fs_distance(double *a, double *b, int len)
15071505return 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{
15131511int i ;
15141512for (i = 0 ;i < old_rows ;i ++ )
@@ -1538,7 +1536,7 @@ build_knn_matrix(OkNNrdata *data, const OkNNrdata *temp_data, double *features)
15381536
15391537for (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 ,
15421540temp_data -> matrix [i ],
15431541data -> cols ))
15441542{
@@ -1904,8 +1902,8 @@ aqo_queries(PG_FUNCTION_ARGS)
19041902MemoryContext per_query_ctx ;
19051903MemoryContext oldcontext ;
19061904Tuplestorestate * 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 ];
19091907HASH_SEQ_STATUS hash_seq ;
19101908QueriesEntry * entry ;
19111909
@@ -1937,12 +1935,12 @@ aqo_queries(PG_FUNCTION_ARGS)
19371935
19381936MemoryContextSwitchTo (oldcontext );
19391937
1938+ memset (nulls ,0 ,AQ_TOTAL_NCOLS );
1939+
19401940LWLockAcquire (& aqo_state -> queries_lock ,LW_SHARED );
19411941hash_seq_init (& hash_seq ,queries_htab );
19421942while ((entry = hash_seq_search (& hash_seq ))!= NULL )
19431943{
1944- memset (nulls ,0 ,AQ_TOTAL_NCOLS + 1 );
1945-
19461944values [AQ_QUERYID ]= Int64GetDatum (entry -> queryid );
19471945values [AQ_FS ]= Int64GetDatum (entry -> fs );
19481946values [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 */
21492147bool
21502148update_query_timeout (uint64 queryid ,int64 smart_timeout )
@@ -2517,6 +2515,8 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
25172515LWLockAcquire (& aqo_state -> queries_lock ,LW_SHARED );
25182516LWLockAcquire (& aqo_state -> stat_lock ,LW_SHARED );
25192517
2518+ memset (nulls ,0 ,AQE_TOTAL_NCOLS * sizeof (nulls [0 ]));
2519+
25202520hash_seq_init (& hash_seq ,queries_htab );
25212521while ((qentry = hash_seq_search (& hash_seq ))!= NULL )
25222522{
@@ -2525,8 +2525,6 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
25252525int64 nexecs ;
25262526int nvals ;
25272527
2528- memset (nulls ,0 ,AQE_TOTAL_NCOLS * sizeof (nulls [0 ]));
2529-
25302528sentry = (StatEntry * )hash_search (stat_htab ,& qentry -> queryid ,
25312529HASH_FIND ,& found );
25322530if (!found )
@@ -2611,6 +2609,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
26112609LWLockAcquire (& aqo_state -> queries_lock ,LW_SHARED );
26122610LWLockAcquire (& aqo_state -> stat_lock ,LW_SHARED );
26132611
2612+ memset (nulls ,0 ,ET_TOTAL_NCOLS * sizeof (nulls [0 ]));
2613+
26142614hash_seq_init (& hash_seq ,queries_htab );
26152615while ((qentry = hash_seq_search (& hash_seq ))!= NULL )
26162616{
@@ -2620,8 +2620,6 @@ aqo_execution_time(PG_FUNCTION_ARGS)
26202620int nvals ;
26212621double tm = 0 ;
26222622
2623- memset (nulls ,0 ,ET_TOTAL_NCOLS * sizeof (nulls [0 ]));
2624-
26252623sentry = (StatEntry * )hash_search (stat_htab ,& qentry -> queryid ,
26262624HASH_FIND ,& found );
26272625if (!found )