@@ -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,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 MemoryContext per_query_ctx ;
19051903 MemoryContext oldcontext ;
19061904 Tuplestorestate * 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 ];
19091907 HASH_SEQ_STATUS hash_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 in aqu_queries table
2145+ * for query in aqo_queries table
21482146 */
21492147bool
21502148update_query_timeout (uint64 queryid , int64 smart_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 int64 nexecs ;
25262526 int nvals ;
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 int nvals ;
26212621 double tm = 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