@@ -74,8 +74,12 @@ HTAB *data_htab = NULL;
74
74
dsa_area * data_dsa = NULL ;
75
75
HTAB * deactivated_queries = NULL ;
76
76
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 ;
79
83
static const uint32 PGAQO_PG_MAJOR_VERSION = PG_VERSION_NUM / 100 ;
80
84
81
85
/*
@@ -374,7 +378,7 @@ aqo_query_stat(PG_FUNCTION_ARGS)
374
378
Datum values [TOTAL_NCOLS + 1 ];
375
379
bool nulls [TOTAL_NCOLS + 1 ];
376
380
HASH_SEQ_STATUS hash_seq ;
377
- StatEntry * entry ;
381
+ StatEntry * entry ;
378
382
379
383
/* check to see if caller supports us returning a tuplestore */
380
384
if (rsinfo == NULL || !IsA (rsinfo , ReturnSetInfo ))
@@ -393,7 +397,9 @@ aqo_query_stat(PG_FUNCTION_ARGS)
393
397
/* Build a tuple descriptor for our result type */
394
398
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
395
399
elog (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" );
397
403
398
404
tupstore = tuplestore_begin_heap (true, false, work_mem );
399
405
rsinfo -> returnMode = SFRM_Materialize ;
@@ -1160,7 +1166,9 @@ aqo_query_texts(PG_FUNCTION_ARGS)
1160
1166
/* Build a tuple descriptor for our result type */
1161
1167
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
1162
1168
elog (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" );
1164
1172
1165
1173
tupstore = tuplestore_begin_heap (true, false, work_mem );
1166
1174
rsinfo -> returnMode = SFRM_Materialize ;
@@ -1756,7 +1764,9 @@ aqo_data(PG_FUNCTION_ARGS)
1756
1764
/* Build a tuple descriptor for our result type */
1757
1765
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
1758
1766
elog (ERROR , "return type must be a row type" );
1759
- Assert (tupDesc -> natts == AD_TOTAL_NCOLS );
1767
+
1768
+ if (tupDesc -> natts != AD_TOTAL_NCOLS )
1769
+ elog (ERROR , "[AQO] Incorrect number of output arguments" );
1760
1770
1761
1771
tupstore = tuplestore_begin_heap (true, false, work_mem );
1762
1772
rsinfo -> returnMode = SFRM_Materialize ;
@@ -1916,7 +1926,9 @@ aqo_queries(PG_FUNCTION_ARGS)
1916
1926
/* Build a tuple descriptor for our result type */
1917
1927
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
1918
1928
elog (ERROR , "return type must be a row type" );
1919
- Assert (tupDesc -> natts == AQ_TOTAL_NCOLS );
1929
+
1930
+ if (tupDesc -> natts != AQ_TOTAL_NCOLS )
1931
+ elog (ERROR , "[AQO] Incorrect number of output arguments" );
1920
1932
1921
1933
tupstore = tuplestore_begin_heap (true, false, work_mem );
1922
1934
rsinfo -> returnMode = SFRM_Materialize ;
@@ -2379,7 +2391,8 @@ aqo_cleanup(PG_FUNCTION_ARGS)
2379
2391
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
2380
2392
elog (ERROR , "return type must be a row type" );
2381
2393
2382
- Assert (tupDesc -> natts == 2 );
2394
+ if (tupDesc -> natts != 2 )
2395
+ elog (ERROR , "[AQO] Incorrect number of output arguments" );
2383
2396
2384
2397
/*
2385
2398
* Make forced cleanup: if at least one fss isn't actual, remove parent FS
@@ -2490,7 +2503,9 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
2490
2503
/* Build a tuple descriptor for our result type */
2491
2504
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
2492
2505
elog (ERROR , "return type must be a row type" );
2493
- Assert (tupDesc -> natts == AQE_TOTAL_NCOLS );
2506
+
2507
+ if (tupDesc -> natts != AQE_TOTAL_NCOLS )
2508
+ elog (ERROR , "[AQO] Incorrect number of output arguments" );
2494
2509
2495
2510
tupstore = tuplestore_begin_heap (true, false, work_mem );
2496
2511
rsinfo -> returnMode = SFRM_Materialize ;
@@ -2558,8 +2573,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
2558
2573
MemoryContext per_query_ctx ;
2559
2574
MemoryContext oldcontext ;
2560
2575
Tuplestorestate * tupstore ;
2561
- Datum values [AQE_TOTAL_NCOLS ];
2562
- bool nulls [AQE_TOTAL_NCOLS ];
2576
+ Datum values [ET_TOTAL_NCOLS ];
2577
+ bool nulls [ET_TOTAL_NCOLS ];
2563
2578
HASH_SEQ_STATUS hash_seq ;
2564
2579
QueriesEntry * qentry ;
2565
2580
StatEntry * sentry ;
@@ -2582,7 +2597,9 @@ aqo_execution_time(PG_FUNCTION_ARGS)
2582
2597
/* Build a tuple descriptor for our result type */
2583
2598
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
2584
2599
elog (ERROR , "return type must be a row type" );
2585
- Assert (tupDesc -> natts == ET_TOTAL_NCOLS );
2600
+
2601
+ if (tupDesc -> natts != ET_TOTAL_NCOLS )
2602
+ elog (ERROR , "[AQO] Incorrect number of output arguments" );
2586
2603
2587
2604
tupstore = tuplestore_begin_heap (true, false, work_mem );
2588
2605
rsinfo -> returnMode = SFRM_Materialize ;
@@ -2715,7 +2732,7 @@ aqo_query_stat_update(PG_FUNCTION_ARGS)
2715
2732
PG_ARGISNULL (EST_ERROR ))
2716
2733
PG_RETURN_BOOL (false);
2717
2734
2718
- queryid = PG_GETARG_INT64 (AQ_QUERYID );
2735
+ queryid = PG_GETARG_INT64 (QUERYID );
2719
2736
stat_arg .execs_with_aqo = PG_GETARG_INT64 (NEXECS_AQO );
2720
2737
stat_arg .execs_without_aqo = PG_GETARG_INT64 (NEXECS );
2721
2738
if (queryid == 0 || stat_arg .execs_with_aqo < 0 ||
0 commit comments