Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5226c27

Browse files
author
Oleg Ivanov
committed
Hotfix which solves PGPRO-432 (actually it is not a real fix, but it decreases the probability of such deadlock by several orders, so we can hope that it will not occur)
1 parent c387c67 commit 5226c27

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

contrib/aqo/preprocessing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ aqo_planner(Query *parse,
143143
use_aqo = true;
144144
auto_tuning = false;
145145
fspace_hash = 0;
146-
collect_stat = true;
146+
collect_stat = false;
147147
break;
148148
case AQO_MODE_MANUAL:
149149
adding_query = false;

contrib/aqo/storage.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ find_query(int query_hash,
3838
Oid query_index_rel_oid;
3939
IndexScanDesc query_index_scan;
4040
ScanKeyData key;
41+
LOCKMODE index_lock = AccessShareLock;
4142

4243
bool find_ok = false;
4344

@@ -51,7 +52,7 @@ find_query(int query_hash,
5152
aqo_queries_table_rv = makeRangeVar("public", "aqo_queries", -1);
5253
aqo_queries_heap = heap_openrv(aqo_queries_table_rv, heap_lock);
5354

54-
query_index_rel = index_open(query_index_rel_oid, heap_lock);
55+
query_index_rel = index_open(query_index_rel_oid, index_lock);
5556
query_index_scan = index_beginscan(
5657
aqo_queries_heap,
5758
query_index_rel,
@@ -76,7 +77,7 @@ find_query(int query_hash,
7677
search_values, search_nulls);
7778

7879
index_endscan(query_index_scan);
79-
index_close(query_index_rel, heap_lock);
80+
index_close(query_index_rel, index_lock);
8081
heap_close(aqo_queries_heap, heap_lock);
8182

8283
return find_ok;
@@ -94,6 +95,7 @@ add_query(int query_hash, bool learn_aqo, bool use_aqo,
9495
Relation aqo_queries_heap;
9596
HeapTuple tuple;
9697
LOCKMODE heap_lock = RowExclusiveLock;
98+
LOCKMODE index_lock = RowExclusiveLock;
9799

98100
Datum values[5];
99101
bool nulls[5] = {false, false, false, false, false};
@@ -113,7 +115,7 @@ add_query(int query_hash, bool learn_aqo, bool use_aqo,
113115
disable_aqo_for_query();
114116
return false;
115117
}
116-
query_index_rel = index_open(query_index_rel_oid, heap_lock);
118+
query_index_rel = index_open(query_index_rel_oid, index_lock);
117119

118120
aqo_queries_table_rv = makeRangeVar("public", "aqo_queries", -1);
119121
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,
136138
}
137139
PG_END_TRY();
138140

139-
index_close(query_index_rel, heap_lock);
141+
index_close(query_index_rel, index_lock);
140142
heap_close(aqo_queries_heap, heap_lock);
141143

142144
CommandCounterIncrement();
@@ -158,6 +160,7 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
158160
Oid query_index_rel_oid;
159161
IndexScanDesc query_index_scan;
160162
ScanKeyData key;
163+
LOCKMODE index_lock = RowExclusiveLock;
161164

162165
Datum values[5];
163166
bool nulls[5] = {false, false, false, false, false};
@@ -173,7 +176,7 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
173176
aqo_queries_table_rv = makeRangeVar("public", "aqo_queries", -1);
174177
aqo_queries_heap = heap_openrv(aqo_queries_table_rv, heap_lock);
175178

176-
query_index_rel = index_open(query_index_rel_oid, heap_lock);
179+
query_index_rel = index_open(query_index_rel_oid, index_lock);
177180
query_index_scan = index_beginscan(
178181
aqo_queries_heap,
179182
query_index_rel,
@@ -217,7 +220,7 @@ update_query(int query_hash, bool learn_aqo, bool use_aqo,
217220
}
218221

219222
index_endscan(query_index_scan);
220-
index_close(query_index_rel, heap_lock);
223+
index_close(query_index_rel, index_lock);
221224
heap_close(aqo_queries_heap, heap_lock);
222225

223226
CommandCounterIncrement();
@@ -236,6 +239,7 @@ add_query_text(int query_hash, const char *query_text)
236239
Relation aqo_query_texts_heap;
237240
HeapTuple tuple;
238241
LOCKMODE heap_lock = RowExclusiveLock;
242+
LOCKMODE index_lock = RowExclusiveLock;
239243

240244
Datum values[2];
241245
bool nulls[2] = {false, false};
@@ -252,7 +256,7 @@ add_query_text(int query_hash, const char *query_text)
252256
disable_aqo_for_query();
253257
return false;
254258
}
255-
query_index_rel = index_open(query_index_rel_oid, heap_lock);
259+
query_index_rel = index_open(query_index_rel_oid, index_lock);
256260

257261
aqo_query_texts_table_rv = makeRangeVar("public",
258262
"aqo_query_texts",
@@ -280,7 +284,7 @@ add_query_text(int query_hash, const char *query_text)
280284
PG_END_TRY();
281285

282286

283-
index_close(query_index_rel, heap_lock);
287+
index_close(query_index_rel, index_lock);
284288
heap_close(aqo_query_texts_heap, heap_lock);
285289

286290
CommandCounterIncrement();
@@ -315,6 +319,7 @@ load_fss(int fss_hash, int ncols,
315319
Oid data_index_rel_oid;
316320
IndexScanDesc data_index_scan;
317321
ScanKeyData *key;
322+
LOCKMODE index_lock = AccessShareLock;
318323

319324
Datum values[5];
320325
bool nulls[5];
@@ -331,7 +336,7 @@ load_fss(int fss_hash, int ncols,
331336
aqo_data_table_rv = makeRangeVar("public", "aqo_data", -1);
332337
aqo_data_heap = heap_openrv(aqo_data_table_rv, heap_lock);
333338

334-
data_index_rel = index_open(data_index_rel_oid, heap_lock);
339+
data_index_rel = index_open(data_index_rel_oid, index_lock);
335340
data_index_scan = index_beginscan(
336341
aqo_data_heap,
337342
data_index_rel,
@@ -380,7 +385,7 @@ load_fss(int fss_hash, int ncols,
380385

381386
index_endscan(data_index_scan);
382387

383-
index_close(data_index_rel, heap_lock);
388+
index_close(data_index_rel, index_lock);
384389
heap_close(aqo_data_heap, heap_lock);
385390

386391
pfree(key);
@@ -534,6 +539,7 @@ get_aqo_stat(int query_hash)
534539
Oid stat_index_rel_oid;
535540
IndexScanDesc stat_index_scan;
536541
ScanKeyData key;
542+
LOCKMODE index_lock = AccessShareLock;
537543

538544
Datum values[9];
539545
bool nulls[9];
@@ -550,7 +556,7 @@ get_aqo_stat(int query_hash)
550556
aqo_stat_table_rv = makeRangeVar("public", "aqo_query_stat", -1);
551557
aqo_stat_heap = heap_openrv(aqo_stat_table_rv, heap_lock);
552558

553-
stat_index_rel = index_open(stat_index_rel_oid, heap_lock);
559+
stat_index_rel = index_open(stat_index_rel_oid, index_lock);
554560
stat_index_scan = index_beginscan(
555561
aqo_stat_heap,
556562
stat_index_rel,
@@ -586,7 +592,7 @@ get_aqo_stat(int query_hash)
586592

587593
index_endscan(stat_index_scan);
588594

589-
index_close(stat_index_rel, heap_lock);
595+
index_close(stat_index_rel, index_lock);
590596
heap_close(aqo_stat_heap, heap_lock);
591597

592598
return stat;
@@ -707,7 +713,7 @@ update_aqo_stat(int query_hash, QueryStat * stat)
707713

708714
index_endscan(stat_index_scan);
709715

710-
index_close(stat_index_rel, heap_lock);
716+
index_close(stat_index_rel, index_lock);
711717
heap_close(aqo_stat_heap, heap_lock);
712718

713719
CommandCounterIncrement();
@@ -839,6 +845,10 @@ my_simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
839845
return false;
840846
break;
841847

848+
case HeapTupleBeingUpdated:
849+
return false;
850+
break;
851+
842852
default:
843853
elog(ERROR, "unrecognized heap_update status: %u", result);
844854
break;

0 commit comments

Comments
 (0)