@@ -74,8 +74,12 @@ HTAB *data_htab = NULL;
7474dsa_area * data_dsa = NULL ;
7575HTAB * deactivated_queries = NULL ;
7676
77- /* Used to check data file consistency */
78- static const uint32 PGAQO_FILE_HEADER = 123467589 ;
77+ /*
78+ * Used to check data file consistency
79+ * When changing data structures, PGAQO_FILE_HEADER should also be changed.
80+ * In this case, all AQO file storages will be reset.
81+ */
82+ static const uint32 PGAQO_FILE_HEADER = 0x20230330 ;
7983static const uint32 PGAQO_PG_MAJOR_VERSION = PG_VERSION_NUM /100 ;
8084
8185/*
@@ -374,7 +378,7 @@ aqo_query_stat(PG_FUNCTION_ARGS)
374378Datum values [TOTAL_NCOLS + 1 ];
375379bool nulls [TOTAL_NCOLS + 1 ];
376380HASH_SEQ_STATUS hash_seq ;
377- StatEntry * entry ;
381+ StatEntry * entry ;
378382
379383/* check to see if caller supports us returning a tuplestore */
380384if (rsinfo == NULL || !IsA (rsinfo ,ReturnSetInfo ))
@@ -393,7 +397,9 @@ aqo_query_stat(PG_FUNCTION_ARGS)
393397/* Build a tuple descriptor for our result type */
394398if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
395399elog (ERROR ,"return type must be a row type" );
396- Assert (tupDesc -> natts == TOTAL_NCOLS );
400+
401+ if (tupDesc -> natts != TOTAL_NCOLS )
402+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
397403
398404tupstore = tuplestore_begin_heap (true, false,work_mem );
399405rsinfo -> returnMode = SFRM_Materialize ;
@@ -1160,7 +1166,9 @@ aqo_query_texts(PG_FUNCTION_ARGS)
11601166/* Build a tuple descriptor for our result type */
11611167if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
11621168elog (ERROR ,"return type must be a row type" );
1163- Assert (tupDesc -> natts == QT_TOTAL_NCOLS );
1169+
1170+ if (tupDesc -> natts != QT_TOTAL_NCOLS )
1171+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
11641172
11651173tupstore = tuplestore_begin_heap (true, false,work_mem );
11661174rsinfo -> returnMode = SFRM_Materialize ;
@@ -1754,7 +1762,9 @@ aqo_data(PG_FUNCTION_ARGS)
17541762/* Build a tuple descriptor for our result type */
17551763if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
17561764elog (ERROR ,"return type must be a row type" );
1757- Assert (tupDesc -> natts == AD_TOTAL_NCOLS );
1765+
1766+ if (tupDesc -> natts != AD_TOTAL_NCOLS )
1767+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
17581768
17591769tupstore = tuplestore_begin_heap (true, false,work_mem );
17601770rsinfo -> returnMode = SFRM_Materialize ;
@@ -1914,7 +1924,9 @@ aqo_queries(PG_FUNCTION_ARGS)
19141924/* Build a tuple descriptor for our result type */
19151925if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
19161926elog (ERROR ,"return type must be a row type" );
1917- Assert (tupDesc -> natts == AQ_TOTAL_NCOLS );
1927+
1928+ if (tupDesc -> natts != AQ_TOTAL_NCOLS )
1929+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
19181930
19191931tupstore = tuplestore_begin_heap (true, false,work_mem );
19201932rsinfo -> returnMode = SFRM_Materialize ;
@@ -2377,7 +2389,8 @@ aqo_cleanup(PG_FUNCTION_ARGS)
23772389if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
23782390elog (ERROR ,"return type must be a row type" );
23792391
2380- Assert (tupDesc -> natts == 2 );
2392+ if (tupDesc -> natts != 2 )
2393+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
23812394
23822395/*
23832396 * Make forced cleanup: if at least one fss isn't actual, remove parent FS
@@ -2488,7 +2501,9 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
24882501/* Build a tuple descriptor for our result type */
24892502if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
24902503elog (ERROR ,"return type must be a row type" );
2491- Assert (tupDesc -> natts == AQE_TOTAL_NCOLS );
2504+
2505+ if (tupDesc -> natts != AQE_TOTAL_NCOLS )
2506+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
24922507
24932508tupstore = tuplestore_begin_heap (true, false,work_mem );
24942509rsinfo -> returnMode = SFRM_Materialize ;
@@ -2556,8 +2571,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
25562571MemoryContext per_query_ctx ;
25572572MemoryContext oldcontext ;
25582573Tuplestorestate * tupstore ;
2559- Datum values [AQE_TOTAL_NCOLS ];
2560- bool nulls [AQE_TOTAL_NCOLS ];
2574+ Datum values [ET_TOTAL_NCOLS ];
2575+ bool nulls [ET_TOTAL_NCOLS ];
25612576HASH_SEQ_STATUS hash_seq ;
25622577QueriesEntry * qentry ;
25632578StatEntry * sentry ;
@@ -2580,7 +2595,9 @@ aqo_execution_time(PG_FUNCTION_ARGS)
25802595/* Build a tuple descriptor for our result type */
25812596if (get_call_result_type (fcinfo ,NULL ,& tupDesc )!= TYPEFUNC_COMPOSITE )
25822597elog (ERROR ,"return type must be a row type" );
2583- Assert (tupDesc -> natts == ET_TOTAL_NCOLS );
2598+
2599+ if (tupDesc -> natts != ET_TOTAL_NCOLS )
2600+ elog (ERROR ,"[AQO] Incorrect number of output arguments" );
25842601
25852602tupstore = tuplestore_begin_heap (true, false,work_mem );
25862603rsinfo -> returnMode = SFRM_Materialize ;
@@ -2713,7 +2730,7 @@ aqo_query_stat_update(PG_FUNCTION_ARGS)
27132730PG_ARGISNULL (EST_ERROR ))
27142731PG_RETURN_BOOL (false);
27152732
2716- queryid = PG_GETARG_INT64 (AQ_QUERYID );
2733+ queryid = PG_GETARG_INT64 (QUERYID );
27172734stat_arg .execs_with_aqo = PG_GETARG_INT64 (NEXECS_AQO );
27182735stat_arg .execs_without_aqo = PG_GETARG_INT64 (NEXECS );
27192736if (queryid == 0 || stat_arg .execs_with_aqo < 0 ||