|
5 | 5 |
|
6 | 6 | ALTER TABLE public.aqo_data ADD COLUMN reliability double precision []; |
7 | 7 |
|
| 8 | +DROP FUNCTION public.top_error_queries(int); |
| 9 | + |
| 10 | +-- |
| 11 | +-- Get cardinality error of queries the last time they were executed. |
| 12 | +-- IN: |
| 13 | +-- controlled - show queries executed under a control of AQO (true); |
| 14 | +-- executed without an AQO control, but AQO has a stat on the query (false). |
8 | 15 | -- |
9 | | --- Get IDs of queries having the largest cardinality error when last executed. |
| 16 | +-- OUT: |
10 | 17 | -- num - sequental number. Smaller number corresponds to higher error. |
11 | | --- qhash - ID of a query. |
12 | | --- error - AQO error calculated over plan nodes of the query. |
| 18 | +-- id - ID of a query. |
| 19 | +-- fshash - feature space. Usually equal to zero or ID. |
| 20 | +-- error - AQO error that calculated on plan nodes of the query. |
| 21 | +-- nexecs - number of executions of queries associated with this ID. |
13 | 22 | -- |
14 | | -CREATE OR REPLACE FUNCTION public.show_cardinality_errors() |
15 | | -RETURNS TABLE(num bigint, id bigint, error float) |
| 23 | +CREATE OR REPLACE FUNCTION public.show_cardinality_errors(controlled boolean) |
| 24 | +RETURNS TABLE(num bigint, id bigint, fshash bigint, error float, nexecs bigint) |
16 | 25 | AS $$ |
17 | 26 | BEGIN |
| 27 | +IF (controlled) THEN |
| 28 | + RETURN QUERY |
| 29 | + SELECT |
| 30 | + row_number() OVER (ORDER BY (cerror, query_id, fs_hash) DESC) AS nn, |
| 31 | + query_id, fs_hash, cerror, execs |
| 32 | + FROM ( |
| 33 | + SELECT |
| 34 | + aq.query_hash AS query_id, |
| 35 | + aq.fspace_hash AS fs_hash, |
| 36 | + cardinality_error_with_aqo[array_length(cardinality_error_with_aqo, 1)] AS cerror, |
| 37 | + executions_with_aqo AS execs |
| 38 | + FROM public.aqo_queries aq JOIN public.aqo_query_stat aqs |
| 39 | + ON aq.query_hash = aqs.query_hash |
| 40 | + WHERE TRUE = ANY (SELECT unnest(cardinality_error_with_aqo) IS NOT NULL) |
| 41 | + ) AS q1 |
| 42 | + ORDER BY nn ASC; |
| 43 | +ELSE |
18 | 44 | RETURN QUERY |
19 | | - SELECT |
20 | | - row_number() OVER (ORDER BY (cerror, qhash) DESC) AS nn, |
21 | | - qhash, cerror |
22 | | - FROM ( |
23 | | - SELECT |
24 | | - aq.query_hash AS qhash, |
25 | | - cardinality_error_with_aqo[array_length(cardinality_error_with_aqo, 1)] AS cerror |
26 | | - FROM public.aqo_queries aq JOIN public.aqo_query_stat aqs |
27 | | - ON aq.query_hash = aqs.query_hash |
28 | | - WHERE TRUE = ANY (SELECT unnest(cardinality_error_with_aqo) IS NOT NULL) |
29 | | - ) AS q1 |
30 | | - ORDER BY nn ASC; |
| 45 | + SELECT |
| 46 | + row_number() OVER (ORDER BY (cerror, query_id, fs_hash) DESC) AS nn, |
| 47 | + query_id, fs_hash, cerror, execs |
| 48 | + FROM ( |
| 49 | + SELECT |
| 50 | + aq.query_hash AS query_id, |
| 51 | + aq.fspace_hash AS fs_hash, |
| 52 | + array_avg(cardinality_error_without_aqo) AS cerror, |
| 53 | + executions_without_aqo AS execs |
| 54 | + FROM public.aqo_queries aq JOIN public.aqo_query_stat aqs |
| 55 | + ON aq.query_hash = aqs.query_hash |
| 56 | + WHERE TRUE = ANY (SELECT unnest(cardinality_error_without_aqo) IS NOT NULL) |
| 57 | + ) AS q1 |
| 58 | + ORDER BY (nn) ASC; |
| 59 | +END IF; |
31 | 60 | END; |
32 | 61 | $$ LANGUAGE plpgsql; |
33 | 62 |
|
34 | | -COMMENT ON FUNCTION public.show_cardinality_errors() IS |
35 | | -'Get cardinality error of last query execution. Return queries having the largest error.'; |
| 63 | +COMMENT ON FUNCTION public.show_cardinality_errors(boolean) IS |
| 64 | +'Get cardinality error of queries the last time they were executed. Order queries according to an error value.'; |
0 commit comments