@@ -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 ;
@@ -1754,7 +1762,9 @@ aqo_data(PG_FUNCTION_ARGS)
1754
1762
/* Build a tuple descriptor for our result type */
1755
1763
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
1756
1764
elog (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" );
1758
1768
1759
1769
tupstore = tuplestore_begin_heap (true, false, work_mem );
1760
1770
rsinfo -> returnMode = SFRM_Materialize ;
@@ -1914,7 +1924,9 @@ aqo_queries(PG_FUNCTION_ARGS)
1914
1924
/* Build a tuple descriptor for our result type */
1915
1925
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
1916
1926
elog (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" );
1918
1930
1919
1931
tupstore = tuplestore_begin_heap (true, false, work_mem );
1920
1932
rsinfo -> returnMode = SFRM_Materialize ;
@@ -2377,7 +2389,8 @@ aqo_cleanup(PG_FUNCTION_ARGS)
2377
2389
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
2378
2390
elog (ERROR , "return type must be a row type" );
2379
2391
2380
- Assert (tupDesc -> natts == 2 );
2392
+ if (tupDesc -> natts != 2 )
2393
+ elog (ERROR , "[AQO] Incorrect number of output arguments" );
2381
2394
2382
2395
/*
2383
2396
* Make forced cleanup: if at least one fss isn't actual, remove parent FS
@@ -2488,7 +2501,9 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
2488
2501
/* Build a tuple descriptor for our result type */
2489
2502
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
2490
2503
elog (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" );
2492
2507
2493
2508
tupstore = tuplestore_begin_heap (true, false, work_mem );
2494
2509
rsinfo -> returnMode = SFRM_Materialize ;
@@ -2556,8 +2571,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
2556
2571
MemoryContext per_query_ctx ;
2557
2572
MemoryContext oldcontext ;
2558
2573
Tuplestorestate * 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 ];
2561
2576
HASH_SEQ_STATUS hash_seq ;
2562
2577
QueriesEntry * qentry ;
2563
2578
StatEntry * sentry ;
@@ -2580,7 +2595,9 @@ aqo_execution_time(PG_FUNCTION_ARGS)
2580
2595
/* Build a tuple descriptor for our result type */
2581
2596
if (get_call_result_type (fcinfo , NULL , & tupDesc ) != TYPEFUNC_COMPOSITE )
2582
2597
elog (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" );
2584
2601
2585
2602
tupstore = tuplestore_begin_heap (true, false, work_mem );
2586
2603
rsinfo -> returnMode = SFRM_Materialize ;
@@ -2713,7 +2730,7 @@ aqo_query_stat_update(PG_FUNCTION_ARGS)
2713
2730
PG_ARGISNULL (EST_ERROR ))
2714
2731
PG_RETURN_BOOL (false);
2715
2732
2716
- queryid = PG_GETARG_INT64 (AQ_QUERYID );
2733
+ queryid = PG_GETARG_INT64 (QUERYID );
2717
2734
stat_arg .execs_with_aqo = PG_GETARG_INT64 (NEXECS_AQO );
2718
2735
stat_arg .execs_without_aqo = PG_GETARG_INT64 (NEXECS );
2719
2736
if (queryid == 0 || stat_arg .execs_with_aqo < 0 ||
0 commit comments