|
5 | 5 |
|
6 | 6 | ALTERTABLEpublic.aqo_data ADD COLUMN reliabilitydouble precision []; |
7 | 7 |
|
| 8 | +DROPFUNCTIONpublic.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 REPLACEFUNCTIONpublic.show_cardinality_errors() |
15 | | -RETURNS TABLE(numbigint, idbigint, error float) |
| 23 | +CREATE OR REPLACEFUNCTIONpublic.show_cardinality_errors(controlledboolean) |
| 24 | +RETURNS TABLE(numbigint, idbigint,fshashbigint,error float, nexecsbigint) |
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_hashAS query_id, |
| 35 | +aq.fspace_hashAS fs_hash, |
| 36 | + cardinality_error_with_aqo[array_length(cardinality_error_with_aqo,1)]AS cerror, |
| 37 | + executions_with_aqoAS execs |
| 38 | +FROMpublic.aqo_queries aqJOINpublic.aqo_query_stat aqs |
| 39 | +ONaq.query_hash=aqs.query_hash |
| 40 | +WHERE TRUE= ANY (SELECT unnest(cardinality_error_with_aqo)IS NOT NULL) |
| 41 | + )AS q1 |
| 42 | +ORDER BY nnASC; |
| 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_hashAS qhash, |
25 | | - cardinality_error_with_aqo[array_length(cardinality_error_with_aqo,1)]AS cerror |
26 | | -FROMpublic.aqo_queries aqJOINpublic.aqo_query_stat aqs |
27 | | -ONaq.query_hash=aqs.query_hash |
28 | | -WHERE TRUE= ANY (SELECT unnest(cardinality_error_with_aqo)IS NOT NULL) |
29 | | -)AS q1 |
30 | | -ORDER BY nnASC; |
| 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_hashAS query_id, |
| 51 | +aq.fspace_hashAS fs_hash, |
| 52 | + array_avg(cardinality_error_without_aqo)AS cerror, |
| 53 | + executions_without_aqoAS execs |
| 54 | +FROMpublic.aqo_queries aqJOINpublic.aqo_query_stat aqs |
| 55 | +ONaq.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 lastquery execution. Return querieshaving the largest error.'; |
| 63 | +COMMENT ON FUNCTION public.show_cardinality_errors(boolean) IS |
| 64 | +'Get cardinality error ofqueries thelasttime they were executed. Order queriesaccording to an error value.'; |