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

Commit 3163936

Browse files
author
Oleg Ivanov
committed
Now aqo is disabled for queries in which catalog relations are used.
1 parent 330a60f commit 3163936

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

contrib/aqo/aqo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#include "access/hash.h"
117117
#include "access/htup_details.h"
118118
#include "access/xact.h"
119+
#include "catalog/catalog.h"
119120
#include "catalog/namespace.h"
120121
#include "catalog/index.h"
121122
#include "catalog/indexing.h"
@@ -125,6 +126,7 @@
125126
#include "executor/executor.h"
126127
#include "executor/execdesc.h"
127128
#include "nodes/makefuncs.h"
129+
#include "nodes/nodeFuncs.h"
128130
#include "optimizer/planmain.h"
129131
#include "optimizer/planner.h"
130132
#include "optimizer/cost.h"

contrib/aqo/preprocessing.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x"
5555

5656
static const char *query_text;
57+
static bool isQueryUsingSystemRelation(Query *query);
58+
static bool isQueryUsingSystemRelation_walker(Node *node, void *context);
5759

5860
/*
5961
* Saves query text into query_text variable.
@@ -108,7 +110,7 @@ aqo_planner(Query *parse,
108110
strlen(CREATE_EXTENSION_STARTSTRING_0)) == 0 ||
109111
strncmp(query_text, CREATE_EXTENSION_STARTSTRING_1,
110112
strlen(CREATE_EXTENSION_STARTSTRING_1)) == 0 ||
111-
aqo_mode == AQO_MODE_DISABLED)
113+
aqo_mode == AQO_MODE_DISABLED || isQueryUsingSystemRelation(parse))
112114
{
113115
disable_aqo_for_query();
114116
return call_default_planner(parse, cursorOptions, boundParams);
@@ -212,3 +214,50 @@ disable_aqo_for_query(void)
212214
auto_tuning = false;
213215
collect_stat = false;
214216
}
217+
218+
/*
219+
* Examine a fully-parsed query, and return TRUE iff any relation underlying
220+
* the query is a system relation.
221+
*/
222+
bool
223+
isQueryUsingSystemRelation(Query *query)
224+
{
225+
return isQueryUsingSystemRelation_walker((Node *) query, NULL);
226+
}
227+
228+
bool
229+
isQueryUsingSystemRelation_walker(Node *node, void *context)
230+
{
231+
if (node == NULL)
232+
return false;
233+
234+
if (IsA(node, Query))
235+
{
236+
Query *query = (Query *) node;
237+
ListCell *rtable;
238+
239+
foreach(rtable, query->rtable)
240+
{
241+
RangeTblEntry *rte = lfirst(rtable);
242+
243+
if (rte->rtekind == RTE_RELATION)
244+
{
245+
Relation rel = heap_open(rte->relid, AccessShareLock);
246+
bool is_catalog = IsCatalogRelation(rel);
247+
248+
heap_close(rel, AccessShareLock);
249+
if (is_catalog)
250+
return true;
251+
}
252+
}
253+
254+
return query_tree_walker(query,
255+
isQueryUsingSystemRelation_walker,
256+
context,
257+
0);
258+
}
259+
260+
return expression_tree_walker(node,
261+
isQueryUsingSystemRelation_walker,
262+
context);
263+
}

0 commit comments

Comments
 (0)