@@ -94,44 +94,53 @@ open_aqo_relation(char *heaprelnspname, char *heaprelname,
94
94
*
95
95
* Use dirty snapshot to see all (include in-progess) data. We want to prevent
96
96
* wait in the XactLockTableWait routine.
97
+ * If query is found in the knowledge base, fill the query context struct.
97
98
*/
98
99
bool
99
- find_query (uint64 qhash , Datum * search_values , bool * search_nulls )
100
+ find_query (uint64 qhash , QueryContextData * ctx )
100
101
{
101
- Relation hrel ;
102
- Relation irel ;
103
- HeapTuple tuple ;
102
+ Relation hrel ;
103
+ Relation irel ;
104
+ HeapTuple tuple ;
104
105
TupleTableSlot * slot ;
105
- bool shouldFree ;
106
- IndexScanDesc scan ;
107
- ScanKeyData key ;
108
- SnapshotData snap ;
109
- bool find_ok = false;
106
+ bool shouldFree = true;
107
+ IndexScanDesc scan ;
108
+ ScanKeyData key ;
109
+ SnapshotData snap ;
110
+ bool find_ok = false;
111
+ Datum values [5 ];
112
+ bool nulls [5 ] = {false, false, false, false, false};
110
113
111
114
if (!open_aqo_relation ("public" , "aqo_queries" , "aqo_queries_query_hash_idx" ,
112
115
AccessShareLock , & hrel , & irel ))
113
116
return false;
114
117
115
118
InitDirtySnapshot (snap );
116
119
scan = index_beginscan (hrel , irel , & snap , 1 , 0 );
117
- ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT4EQ , Int64GetDatum (qhash ));
120
+ ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (qhash ));
118
121
119
122
index_rescan (scan , & key , 1 , NULL , 0 );
120
123
slot = MakeSingleTupleTableSlot (hrel -> rd_att , & TTSOpsBufferHeapTuple );
121
124
find_ok = index_getnext_slot (scan , ForwardScanDirection , slot );
122
125
123
- if (find_ok && search_values != NULL )
126
+ if (find_ok )
124
127
{
125
128
tuple = ExecFetchSlotHeapTuple (slot , true, & shouldFree );
126
129
Assert (shouldFree != true);
127
- heap_deform_tuple (tuple , hrel -> rd_att , search_values , search_nulls );
130
+ heap_deform_tuple (tuple , hrel -> rd_att , values , nulls );
131
+
132
+ /* Fill query context data */
133
+ ctx -> learn_aqo = DatumGetBool (values [1 ]);
134
+ ctx -> use_aqo = DatumGetBool (values [2 ]);
135
+ ctx -> fspace_hash = DatumGetInt64 (values [3 ]);
136
+ ctx -> auto_tuning = DatumGetBool (values [4 ]);
137
+ ctx -> collect_stat = query_context .auto_tuning ;
128
138
}
129
139
130
140
ExecDropSingleTupleTableSlot (slot );
131
141
index_endscan (scan );
132
142
index_close (irel , AccessShareLock );
133
143
table_close (hrel , AccessShareLock );
134
-
135
144
return find_ok ;
136
145
}
137
146
@@ -177,7 +186,7 @@ update_query(uint64 qhash, uint64 fhash,
177
186
*/
178
187
InitDirtySnapshot (snap );
179
188
scan = index_beginscan (hrel , irel , & snap , 1 , 0 );
180
- ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (qhash ));
189
+ ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (qhash ));
181
190
182
191
index_rescan (scan , & key , 1 , NULL , 0 );
183
192
slot = MakeSingleTupleTableSlot (hrel -> rd_att , & TTSOpsBufferHeapTuple );
@@ -222,7 +231,8 @@ update_query(uint64 qhash, uint64 fhash,
222
231
* Ooops, somebody concurrently updated the tuple. It is possible
223
232
* only in the case of changes made by third-party code.
224
233
*/
225
- elog (ERROR , "AQO feature space data for signature (%ld, %ld) concurrently"
234
+ elog (ERROR , "AQO feature space data for signature (" UINT64_FORMAT \
235
+ ", " UINT64_FORMAT ") concurrently"
226
236
" updated by a stranger backend." ,
227
237
qhash , fhash );
228
238
result = false;
@@ -284,7 +294,7 @@ add_query_text(uint64 qhash, const char *query_string)
284
294
*/
285
295
InitDirtySnapshot (snap );
286
296
scan = index_beginscan (hrel , irel , & snap , 1 , 0 );
287
- ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (qhash ));
297
+ ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (qhash ));
288
298
289
299
index_rescan (scan , & key , 1 , NULL , 0 );
290
300
slot = MakeSingleTupleTableSlot (hrel -> rd_att , & TTSOpsBufferHeapTuple );
@@ -391,7 +401,7 @@ load_fss(uint64 fhash, int fss_hash,
391
401
return false;
392
402
393
403
scan = index_beginscan (hrel , irel , SnapshotSelf , 2 , 0 );
394
- ScanKeyInit (& key [0 ], 1 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (fhash ));
404
+ ScanKeyInit (& key [0 ], 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (fhash ));
395
405
ScanKeyInit (& key [1 ], 2 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (fss_hash ));
396
406
index_rescan (scan , key , 2 , NULL , 0 );
397
407
@@ -423,9 +433,10 @@ load_fss(uint64 fhash, int fss_hash,
423
433
* relids = deform_oids_vector (values [5 ]);
424
434
}
425
435
else
426
- elog (ERROR , "unexpected number of features for hash (%ld, %d):\
427
- expected %d features, obtained %d" ,
428
- fhash , fss_hash , ncols , DatumGetInt32 (values [2 ]));
436
+ elog (ERROR , "unexpected number of features for hash (" \
437
+ UINT64_FORMAT ", %d):\
438
+ expected %d features, obtained %d" ,
439
+ fhash , fss_hash , ncols , DatumGetInt32 (values [2 ]));
429
440
}
430
441
else
431
442
success = false;
@@ -484,7 +495,7 @@ update_fss(uint64 fhash, int fsshash, int nrows, int ncols,
484
495
InitDirtySnapshot (snap );
485
496
scan = index_beginscan (hrel , irel , & snap , 2 , 0 );
486
497
487
- ScanKeyInit (& key [0 ], 1 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (fhash ));
498
+ ScanKeyInit (& key [0 ], 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (fhash ));
488
499
ScanKeyInit (& key [1 ], 2 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (fsshash ));
489
500
490
501
index_rescan (scan , key , 2 , NULL , 0 );
@@ -494,7 +505,7 @@ update_fss(uint64 fhash, int fsshash, int nrows, int ncols,
494
505
495
506
if (!find_ok )
496
507
{
497
- values [0 ] = Int32GetDatum (fhash );
508
+ values [0 ] = Int64GetDatum (fhash );
498
509
values [1 ] = Int32GetDatum (fsshash );
499
510
values [2 ] = Int32GetDatum (ncols );
500
511
@@ -549,8 +560,8 @@ update_fss(uint64 fhash, int fsshash, int nrows, int ncols,
549
560
* Ooops, somebody concurrently updated the tuple. It is possible
550
561
* only in the case of changes made by third-party code.
551
562
*/
552
- elog (ERROR , "AQO data piece (%ld %d) concurrently updated "
553
- " by a stranger backend." ,
563
+ elog (ERROR , "AQO data piece (" UINT64_FORMAT " %d) concurrently"
564
+ " updated by a stranger backend." ,
554
565
fhash , fsshash );
555
566
result = false;
556
567
}
@@ -596,7 +607,7 @@ get_aqo_stat(uint64 qhash)
596
607
return false;
597
608
598
609
scan = index_beginscan (hrel , irel , SnapshotSelf , 1 , 0 );
599
- ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT4EQ , Int32GetDatum (qhash ));
610
+ ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (qhash ));
600
611
index_rescan (scan , & key , 1 , NULL , 0 );
601
612
slot = MakeSingleTupleTableSlot (hrel -> rd_att , & TTSOpsBufferHeapTuple );
602
613
@@ -667,7 +678,7 @@ update_aqo_stat(uint64 qhash, QueryStat *stat)
667
678
668
679
InitDirtySnapshot (snap );
669
680
scan = index_beginscan (hrel , irel , & snap , 1 , 0 );
670
- ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT4EQ , Int64GetDatum (qhash ));
681
+ ScanKeyInit (& key , 1 , BTEqualStrategyNumber , F_INT8EQ , Int64GetDatum (qhash ));
671
682
index_rescan (scan , & key , 1 , NULL , 0 );
672
683
slot = MakeSingleTupleTableSlot (hrel -> rd_att , & TTSOpsBufferHeapTuple );
673
684
@@ -713,8 +724,8 @@ update_aqo_stat(uint64 qhash, QueryStat *stat)
713
724
* Ooops, somebody concurrently updated the tuple. It is possible
714
725
* only in the case of changes made by third-party code.
715
726
*/
716
- elog (ERROR , "AQO statistic data for query signature %ld concurrently"
717
- " updated by a stranger backend." ,
727
+ elog (ERROR , "AQO statistic data for query signature " UINT64_FORMAT
728
+ " concurrently updated by a stranger backend." ,
718
729
qhash );
719
730
}
720
731
}
@@ -914,8 +925,8 @@ init_deactivated_queries_storage(void)
914
925
915
926
/* Create the hashtable proper */
916
927
MemSet (& hash_ctl , 0 , sizeof (hash_ctl ));
917
- hash_ctl .keysize = sizeof (int );
918
- hash_ctl .entrysize = sizeof (int );
928
+ hash_ctl .keysize = sizeof (uint64 );
929
+ hash_ctl .entrysize = sizeof (uint64 );
919
930
deactivated_queries = hash_create ("aqo_deactivated_queries" ,
920
931
128 , /* start small and extend */
921
932
& hash_ctl ,
0 commit comments