You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Show a query execution time made with AQO support for the planner
90
-
-- cardinality estimations. Here we return result of last execution.
91
-
RETURN QUERY
92
-
SELECT
93
-
row_number() OVER (ORDER BY (exectime, queryid, fs_hash) DESC) AS nn,
94
-
queryid, fs_hash, exectime, execs
95
-
FROM (
96
-
SELECT
97
-
aq.queryidAS queryid,
98
-
aq.fsAS fs_hash,
99
-
execution_time_with_aqo[array_length(execution_time_with_aqo, 1)] AS exectime,
100
-
executions_with_aqo AS execs
101
-
FROM aqo_queries aq JOIN aqo_query_stat aqs
102
-
ONaq.queryid=aqs.queryid
103
-
WHERE TRUE = ANY (SELECT unnest(execution_time_with_aqo) IS NOT NULL)
104
-
) AS q1
105
-
ORDER BY nn ASC;
106
-
107
-
ELSE
108
-
-- Show a query execution time made without any AQO advise.
109
-
-- Return an average value across all executions.
110
-
RETURN QUERY
111
-
SELECT
112
-
row_number() OVER (ORDER BY (exectime, queryid, fs_hash) DESC) AS nn,
113
-
queryid, fs_hash, exectime, execs
114
-
FROM (
115
-
SELECT
116
-
aq.queryidAS queryid,
117
-
aq.fsAS fs_hash,
118
-
(SELECTAVG(t) FROM unnest(execution_time_without_aqo) t) AS exectime,
119
-
executions_without_aqo AS execs
120
-
FROM aqo_queries aq JOIN aqo_query_stat aqs
121
-
ONaq.queryid=aqs.queryid
122
-
WHERE TRUE = ANY (SELECT unnest(execution_time_without_aqo) IS NOT NULL)
123
-
) AS q1
124
-
ORDER BY (nn) ASC;
125
-
END IF;
126
-
END;
127
-
$$ LANGUAGE plpgsql;
123
+
AS'MODULE_PATHNAME', 'aqo_execution_time'
124
+
LANGUAGE C STRICT VOLATILE;
128
125
COMMENT ON FUNCTION aqo_execution_time(boolean) IS
129
126
'Get execution time of queries. If controlled = true (AQO could advise cardinality estimations), show time of last execution attempt. Another case (AQO not used), return an average value of execution time across all known executions.';
130
127
@@ -152,76 +149,6 @@ LANGUAGE C STRICT VOLATILE;
152
149
COMMENT ON FUNCTION aqo_cleanup() IS
153
150
'Remove unneeded rows from the AQO ML storage';
154
151
155
-
--
156
-
-- Get cardinality error of queries the last time they were executed.
157
-
-- IN:
158
-
-- controlled - show queries executed under a control of AQO (true);
159
-
-- executed without an AQO control, but AQO has a stat on the query (false).
160
-
--
161
-
-- OUT:
162
-
-- num - sequental number. Smaller number corresponds to higher error.
163
-
-- id - ID of a query.
164
-
-- fshash - feature space. Usually equal to zero or ID.
165
-
-- error - AQO error that calculated on plan nodes of the query.
166
-
-- nexecs - number of executions of queries associated with this ID.
167
-
--
168
-
CREATE OR REPLACEFUNCTIONaqo_cardinality_error(controlled boolean)
0 commit comments