@@ -93,6 +93,30 @@ call_default_planner(Query *parse,
93
93
boundParams );
94
94
}
95
95
96
+ /*
97
+ * Check, that a 'CREATE EXTENSION aqo' command has been executed.
98
+ * This function allows us to execute the get_extension_oid routine only once
99
+ * at each backend.
100
+ * If any AQO-related table is missed we will set aqo_enabled to false (see
101
+ * a storage implementation module).
102
+ */
103
+ static bool
104
+ aqoIsEnabled (void )
105
+ {
106
+ if (creating_extension )
107
+ /* Nothing to tell in this mode. */
108
+ return false;
109
+
110
+ if (aqo_enabled )
111
+ /* Fast path. Dropping should be detected by absence of any table. */
112
+ return true;
113
+
114
+ if (get_extension_oid ("aqo" , true) != InvalidOid )
115
+ aqo_enabled = true;
116
+
117
+ return aqo_enabled ;
118
+ }
119
+
96
120
/*
97
121
* Before query optimization we determine machine learning settings
98
122
* for the query.
@@ -120,18 +144,23 @@ aqo_planner(Query *parse,
120
144
* the heap during planning. Transactions is synchronized between parallel
121
145
* sections. See GetCurrentCommandId() comments also.
122
146
*/
123
- if ((parse -> commandType != CMD_SELECT && parse -> commandType != CMD_INSERT &&
147
+ if (!aqoIsEnabled () ||
148
+ (parse -> commandType != CMD_SELECT && parse -> commandType != CMD_INSERT &&
124
149
parse -> commandType != CMD_UPDATE && parse -> commandType != CMD_DELETE ) ||
125
- strstr (application_name , "postgres_fdw" ) != NULL || /* Prevent distributed deadlocks */
126
- strstr (application_name , "pgfdw:" ) != NULL || /* caused by fdw */
127
- get_extension_oid ("aqo" , true) == InvalidOid ||
128
150
creating_extension ||
129
151
IsInParallelMode () || IsParallelWorker () ||
130
152
(aqo_mode == AQO_MODE_DISABLED && !force_collect_stat ) ||
153
+ strstr (application_name , "postgres_fdw" ) != NULL || /* Prevent distributed deadlocks */
154
+ strstr (application_name , "pgfdw:" ) != NULL || /* caused by fdw */
131
155
isQueryUsingSystemRelation (parse ) ||
132
156
RecoveryInProgress ())
E52F
tr>133
157
{
158
+ /*
159
+ * We should disable AQO for this query to remember this decision along
160
+ * all execution stages.
161
+ */
134
162
disable_aqo_for_query ();
163
+
135
164
return call_default_planner (parse ,
136
165
query_string ,
137
166
cursorOptions ,
0 commit comments