@@ -38,6 +38,7 @@ find_query(int query_hash,
38
38
Oid query_index_rel_oid ;
39
39
IndexScanDesc query_index_scan ;
40
40
ScanKeyData key ;
41
+ LOCKMODE index_lock = AccessShareLock ;
41
42
42
43
bool find_ok = false;
43
44
@@ -51,7 +52,7 @@ find_query(int query_hash,
51
52
aqo_queries_table_rv = makeRangeVar ("public" , "aqo_queries" , -1 );
52
53
aqo_queries_heap = heap_openrv (aqo_queries_table_rv , heap_lock );
53
54
54
- query_index_rel = index_open (query_index_rel_oid , heap_lock );
55
+ query_index_rel = index_open (query_index_rel_oid , index_lock );
55
56
query_index_scan = index_beginscan (
56
57
aqo_queries_heap ,
57
58
query_index_rel ,
@@ -76,7 +77,7 @@ find_query(int query_hash,
76
77
search_values , search_nulls );
77
78
78
79
index_endscan (query_index_scan );
79
- index_close (query_index_rel , heap_lock );
80
+ index_close (query_index_rel , index_lock );
80
81
heap_close (aqo_queries_heap , heap_lock );
81
82
82
83
return find_ok ;
@@ -94,6 +95,7 @@ add_query(int query_hash, bool learn_aqo, bool use_aqo,
94
95
Relation aqo_queries_heap ;
95
96
HeapTuple tuple ;
96
97
LOCKMODE heap_lock = RowExclusiveLock ;
98
+ LOCKMODE index_lock = RowExclusiveLock ;
97
99
98
100
Datum values [5 ];
99
101
bool nulls [5 ] = {false, false, false, false, false};
@@ -113,7 +115,7 @@ add_query(int query_hash, bool learn_aqo, bool use_aqo,
113
115
disable_aqo_for_query ();
114
116
return false;
115
117
}
116
- query_index_rel = index_open (query_index_rel_oid , heap_lock );
118
+ query_index_rel = index_open (query_index_rel_oid , index_lock );
117
119
118
120
aqo_queries_table_rv = makeRangeVar ("public" , "aqo_queries" , -1 );
119
121
aqo_queries_heap = heap_openrv (aqo_queries_table_rv , heap_lock );
@@ -136,7 +138,7 @@ add_query(int query_hash, bool learn_aqo, bool use_aqo,
136
138
}
137
139
PG_END_TRY ();
138
140
139
- index_close (query_index_rel , heap_lock );
141
+ index_close (query_index_rel , index_lock );
140
142
heap_close (aqo_queries_heap , heap_lock );
141
143
142
144
CommandCounterIncrement ();
@@ -158,6 +160,7 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
158
160
Oid query_index_rel_oid ;
159
161
IndexScanDesc query_index_scan ;
160
162
ScanKeyData key ;
163
+ LOCKMODE index_lock = RowExclusiveLock ;
161
164
162
165
Datum values [5 ];
163
166
bool nulls [5 ] = {false, false, false, false, false};
@@ -173,7 +176,7 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
173
176
aqo_queries_table_rv = makeRangeVar ("public" , "aqo_queries" , -1 );
174
177
aqo_queries_heap = heap_openrv (aqo_queries_table_rv , heap_lock );
175
178
176
- query_index_rel = index_open (query_index_rel_oid , heap_lock );
179
+ query_index_rel = index_open (query_index_rel_oid , index_lock );
177
180
query_index_scan = index_beginscan (
178
181
aqo_queries_heap ,
179
182
query_index_rel ,
@@ -217,7 +220,7 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
217
220
}
218
221
219
222
index_endscan (query_index_scan );
220
- index_close (query_index_rel , heap_lock );
223
+ index_close (query_index_rel , index_lock );
221
224
heap_close (aqo_queries_heap , heap_lock );
222
225
223
226
CommandCounterIncrement ();
@@ -236,6 +239,7 @@ add_query_text(int query_hash, const char *query_text)
236
239
Relation aqo_query_texts_heap ;
237
240
HeapTuple tuple ;
238
241
LOCKMODE heap_lock = RowExclusiveLock ;
242
+ LOCKMODE index_lock = RowExclusiveLock ;
239
243
240
244
Datum values [2 ];
241
245
bool nulls [2 ] = {false, false};
@@ -252,7 +256,7 @@ add_query_text(int query_hash, const char *query_text)
252
256
disable_aqo_for_query ();
253
257
return false;
254
258
}
255
- query_index_rel = index_open (query_index_rel_oid , heap_lock );
259
+ query_index_rel = index_open (query_index_rel_oid , index_lock );
256
260
257
261
aqo_query_texts_table_rv = makeRangeVar ("public" ,
258
262
"aqo_query_texts" ,
@@ -280,7 +284,7 @@ add_query_text(int query_hash, const char *query_text)
280
284
PG_END_TRY ();
281
285
282
286
283
- index_close (query_index_rel , heap_lock );
287
+ index_close (query_index_rel , index_lock );
284
288
heap_close (aqo_query_texts_heap , heap_lock );
285
289
286
290
CommandCounterIncrement ();
@@ -315,6 +319,7 @@ load_fss(int fss_hash, int ncols,
315
319
Oid data_index_rel_oid ;
316
320
IndexScanDesc data_index_scan ;
317
321
ScanKeyData * key ;
322
+ LOCKMODE index_lock = AccessShareLock ;
318
323
319
324
Datum values [5 ];
320
325
bool nulls [5 ];
@@ -331,7 +336,7 @@ load_fss(int fss_hash, int ncols,
331
336
aqo_data_table_rv = makeRangeVar ("public" , "aqo_data" , -1 );
332
337
aqo_data_heap = heap_openrv (aqo_data_table_rv , heap_lock );
333
338
334
- data_index_rel = index_open (data_index_rel_oid , heap_lock );
339
+ data_index_rel = index_open (data_index_rel_oid , index_lock );
335
340
data_index_scan = index_beginscan (
336
341
aqo_data_heap ,
337
342
data_index_rel ,
@@ -380,7 +385,7 @@ load_fss(int fss_hash, int ncols,
380
385
381
386
index_endscan (data_index_scan );
382
387
383
- index_close (data_index_rel , heap_lock );
388
+ index_close (data_index_rel , index_lock );
384
389
heap_close (aqo_data_heap , heap_lock );
385
390
386
391
pfree (key );
@@ -534,6 +539,7 @@ get_aqo_stat(int query_hash)
534
539
Oid stat_index_rel_oid ;
535
540
IndexScanDesc stat_index_scan ;
536
541
ScanKeyData key ;
542
+ LOCKMODE index_lock = AccessShareLock ;
537
543
538
544
Datum values [9 ];
539
545
bool nulls [9 ];
@@ -550,7 +556,7 @@ get_aqo_stat(int query_hash)
550
556
aqo_stat_table_rv = makeRangeVar ("public" , "aqo_query_stat" , -1 );
551
557
aqo_stat_heap = heap_openrv (aqo_stat_table_rv , heap_lock );
552
558
553
- stat_index_rel = index_open (stat_index_rel_oid , heap_lock );
559
+ stat_index_rel = index_open (stat_index_rel_oid , index_lock );
554
560
stat_index_scan = index_beginscan (
555
561
aqo_stat_heap ,
556
562
stat_index_rel ,
@@ -586,7 +592,7 @@ get_aqo_stat(int query_hash)
586
592
587
593
index_endscan (stat_index_scan );
588
594
589
- index_close (stat_index_rel , heap_lock );
595
+ index_close (stat_index_rel , index_lock );
590
596
heap_close (aqo_stat_heap , heap_lock );
591
597
592
598
return stat ;
@@ -707,7 +713,7 @@ update_aqo_stat(int query_hash, QueryStat * stat)
707
713
708
714
index_endscan (stat_index_scan );
709
715
710
- index_close (stat_index_rel , heap_lock );
716
+ index_close (stat_index_rel , index_lock );
711
717
heap_close (aqo_stat_heap , heap_lock );
712
718
713
719
CommandCounterIncrement ();
@@ -839,6 +845,10 @@ my_simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
839
845
return false;
840
846
break ;
841
847
848
+ case HeapTupleBeingUpdated :
849
+ return false;
850
+ break ;
851
+
842
852
default :
843
853
elog (ERROR , "unrecognized heap_update status: %u" , result );
844
854
break ;
0 commit comments