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