Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce7188c

Browse files
committed
Add list of currently used feature spaces in the backend.
It is needed to exclude problems with recursive execution induced by cache invalidation. Change parallel schedule for regression tests.
1 parent e72f1a6 commit ce7188c

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

aqo.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ aqo_free_callback(ResourceReleasePhase phase,
125125
pfree(query_text);
126126
query_text = NULL;
127127
}
128+
129+
if (isTopLevel)
130+
{
131+
list_free(cur_classes);
132+
cur_classes = NIL;
133+
}
128134
}
129135

130136
void

aqo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,5 @@ void selectivity_cache_clear(void);
385385
extern Oid get_aqo_schema(void);
386386
extern void init_lock_tag(LOCKTAG *tag, uint32 key1, uint32 key2);
387387

388+
extern List *cur_classes;
388389
#endif

parallel_schedule

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# ----------
2-
# src/test/regress/parallel_schedule
32
#
43
# By convention, we put no more than twenty tests in any one parallel group;
54
# this limits the number of connections needed to run the tests.
@@ -8,12 +7,12 @@
87
# run tablespace by itself, and first, because it forces a checkpoint;
98
# we'd prefer not to have checkpoints later in the tests because that
109
# interferes with crash-recovery testing.
11-
# test: tablespace
10+
test: tablespace
1211

1312
# ----------
1413
# The first group of parallel tests
1514
# ----------
16-
15+
ignore: txid
1716
test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric txid uuid enum money rangetypes pg_lsn regproc
1817

1918
# ----------
@@ -70,6 +69,7 @@ test: sanity_check
7069
# Note: the ignore: line does not run random, just mark it as ignorable
7170
# ----------
7271
ignore: random
72+
ignore: update
7373
test: select_into select_distinct select_distinct_on select_implicit select_having case aggregates transactions random portals arrays btree_index hash_index update delete namespace prepared_xacts
7474
test: subselect union join
7575

@@ -97,6 +97,7 @@ test: publication subscription
9797
# ----------
9898
# Another group of parallel tests
9999
# ----------
100+
ignore: combocid
100101
test: select_views portals_p2 foreign_key cluster dependency guc bitmapops combocid tsearch tsdicts foreign_data window xmlmap functional_deps advisory_lock indirect_toast equivclass
101102

102103
# ----------
@@ -109,8 +110,7 @@ test: json jsonb json_encoding jsonpath jsonpath_encoding jsonb_jsonpath
109110
# NB: temp.sql does a reconnect which transiently uses 2 connections,
110111
# so keep this parallel group to at most 19 tests
111112
# ----------
112-
test: plancache limit plpgsql copy2 temp domain rangefuncs prepare conversion truncate alter_table sequence polymorphism rowtypes returning largeobject xml
113-
test: with
113+
test: plancache limit plpgsql copy2 temp domain rangefuncs prepare conversion truncate alter_table sequence polymorphism rowtypes returning largeobject xml with
114114

115115
# ----------
116116
# Another group of parallel tests

postprocessing.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,11 @@ aqo_ExecutorEnd(QueryDesc *queryDesc)
557557
pfree_query_stat(stat);
558558
}
559559

560+
/* Allow concurrent queries to update this feature space. */
560561
LockRelease(&tag, ExclusiveLock, false);
562+
563+
cur_classes = list_delete_int(cur_classes, query_context.query_hash);
564+
561565
RemoveFromQueryEnv(queryDesc);
562566

563567
end:

preprocessing.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
#include "access/table.h"
6262
#include "commands/extension.h"
6363

64+
/* List of feature spaces, that are processing in this backend. */
65+
List *cur_classes = NIL;
66+
6467
static bool isQueryUsingSystemRelation(Query *query);
6568
static bool isQueryUsingSystemRelation_walker(Node *node, void *context);
6669

@@ -116,6 +119,7 @@ aqo_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
116119
Datum query_params[5];
117120
bool query_nulls[5] = {false, false, false, false, false};
118121
LOCKTAG tag;
122+
MemoryContext oldCxt;
119123

120124
selectivity_cache_clear();
121125

@@ -139,16 +143,25 @@ aqo_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
139143
return call_default_planner(parse, cursorOptions, boundParams);
140144
}
141145

142-
INSTR_TIME_SET_CURRENT(query_context.query_starttime);
143-
144146
query_context.query_hash = get_query_hash(parse, query_text);
145147

146-
if (query_is_deactivated(query_context.query_hash))
148+
if (query_is_deactivated(query_context.query_hash) ||
149+
list_member_int(cur_classes, query_context.query_hash))
147150
{
151+
/* Disable AQO for deactivated query or for query belonged to a
152+
* feature space, that is processing yet (disallow invalidation
153+
* recursion, as an example).
154+
*/
148155
disable_aqo_for_query();
149156
return call_default_planner(parse, cursorOptions, boundParams);
150157
}
151158

159+
oldCxt = MemoryContextSwitchTo(AQOMemoryContext);
160+
cur_classes = lappend_int(cur_classes, query_context.query_hash);
161+
MemoryContextSwitchTo(oldCxt);
162+
163+
INSTR_TIME_SET_CURRENT(query_context.query_starttime);
164+
152165
/*
153166
* find-add query and query text must be atomic operation to prevent
154167
* concurrent insertions.

0 commit comments

Comments
 (0)