Skip to content

Commit 6c85f0a

Browse files
Daniil AnisimovAlena0704
Daniil Anisimov
authored andcommitted
Add the routine for safe update.
Reviewed by: @Alena0704
1 parent d2f713a commit 6c85f0a

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

‎storage.c

+30-13
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ HTAB *data_htab = NULL;
7474
dsa_area *data_dsa = NULL;
7575
HTAB *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;
7983
static const uint32 PGAQO_PG_MAJOR_VERSION = PG_VERSION_NUM / 100;
8084

8185
/*
@@ -374,7 +378,7 @@ aqo_query_stat(PG_FUNCTION_ARGS)
374378
Datum values[TOTAL_NCOLS + 1];
375379
bool nulls[TOTAL_NCOLS + 1];
376380
HASH_SEQ_STATUS hash_seq;
377-
StatEntry *entry;
381+
StatEntry *entry;
378382

379383
/* check to see if caller supports us returning a tuplestore */
380384
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
@@ -393,7 +397,9 @@ aqo_query_stat(PG_FUNCTION_ARGS)
393397
/* Build a tuple descriptor for our result type */
394398
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
395399
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");
397403

398404
tupstore = tuplestore_begin_heap(true, false, work_mem);
399405
rsinfo->returnMode = SFRM_Materialize;
@@ -1160,7 +1166,9 @@ aqo_query_texts(PG_FUNCTION_ARGS)
11601166
/* Build a tuple descriptor for our result type */
11611167
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
11621168
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");
11641172

11651173
tupstore = tuplestore_begin_heap(true, false, work_mem);
11661174
rsinfo->returnMode = SFRM_Materialize;
@@ -1756,7 +1764,9 @@ aqo_data(PG_FUNCTION_ARGS)
17561764
/* Build a tuple descriptor for our result type */
17571765
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
17581766
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");
17601770

17611771
tupstore = tuplestore_begin_heap(true, false, work_mem);
17621772
rsinfo->returnMode = SFRM_Materialize;
@@ -1916,7 +1926,9 @@ aqo_queries(PG_FUNCTION_ARGS)
19161926
/* Build a tuple descriptor for our result type */
19171927
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
19181928
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");
19201932

19211933
tupstore = tuplestore_begin_heap(true, false, work_mem);
19221934
rsinfo->returnMode = SFRM_Materialize;
@@ -2379,7 +2391,8 @@ aqo_cleanup(PG_FUNCTION_ARGS)
23792391
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
23802392
elog(ERROR, "return type must be a row type");
23812393

2382-
Assert(tupDesc->natts == 2);
2394+
if (tupDesc->natts != 2)
2395+
elog(ERROR, "[AQO] Incorrect number of output arguments");
23832396

23842397
/*
23852398
* Make forced cleanup: if at least one fss isn't actual, remove parent FS
@@ -2490,7 +2503,9 @@ aqo_cardinality_error(PG_FUNCTION_ARGS)
24902503
/* Build a tuple descriptor for our result type */
24912504
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
24922505
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");
24942509

24952510
tupstore = tuplestore_begin_heap(true, false, work_mem);
24962511
rsinfo->returnMode = SFRM_Materialize;
@@ -2558,8 +2573,8 @@ aqo_execution_time(PG_FUNCTION_ARGS)
25582573
MemoryContext per_query_ctx;
25592574
MemoryContext oldcontext;
25602575
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];
25632578
HASH_SEQ_STATUS hash_seq;
25642579
QueriesEntry *qentry;
25652580
StatEntry *sentry;
@@ -2582,7 +2597,9 @@ aqo_execution_time(PG_FUNCTION_ARGS)
25822597
/* Build a tuple descriptor for our result type */
25832598
if (get_call_result_type(fcinfo, NULL, &tupDesc) != TYPEFUNC_COMPOSITE)
25842599
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");
25862603

25872604
tupstore = tuplestore_begin_heap(true, false, work_mem);
25882605
rsinfo->returnMode = SFRM_Materialize;
@@ -2715,7 +2732,7 @@ aqo_query_stat_update(PG_FUNCTION_ARGS)
27152732
PG_ARGISNULL(EST_ERROR))
27162733
PG_RETURN_BOOL(false);
27172734

2718-
queryid = PG_GETARG_INT64(AQ_QUERYID);
2735+
queryid = PG_GETARG_INT64(QUERYID);
27192736
stat_arg.execs_with_aqo = PG_GETARG_INT64(NEXECS_AQO);
27202737
stat_arg.execs_without_aqo = PG_GETARG_INT64(NEXECS);
27212738
if (queryid == 0 || stat_arg.execs_with_aqo < 0 ||

0 commit comments

Comments
 (0)