Details
-
Type:
Task
-
Status: Closed
-
Priority:
Major
-
Resolution: Fixed
-
Fix Version/s: 10.1.0
-
Component/s: None
-
Labels:
Description
(Documentation is at https://mariadb.com/kb/en/analyze-statement/)
== SQL syntax ==
The new syntax:
ANALYZE $explainable_stmt
ANALYZE $stmt will run the $stmt, and produce the output that EXPLAIN $stmt would produce, annotated with info about the query execution.
== Adjustments to EXPLAIN output ==
EXPLAIN FORMAT=JSON is easy to extend.
As for tabular EXPLAIN form, the following columns will be added:
- loops ( need this?)
- r_rows
- r_filtered
== Implementation at SQL layer ==
The parser will set LEX::analyze_stmt flag for ANALYZE statements.
There is LEX::describe which stores flags about EXPLAIN EXTENDED|PARTITIONS
but it is used to check whether the query is an EXPLAIN or not, and ANALYZE
command is not an EXPLAIN, because it actually runs the query.
Note: ANALYZE UPDATE statement actually makes the updates. With SBR, we will
have to write the statement into the binlog. The slave must be able to execute
it (I suspect current slave will choke on a statement that produces output).
== Counting ==
We will collect two kinds of counters:
1. Some are counted at SQL level, like filtered%, ICP_filtered, #rows, etc.
2. Some will be counted deeper inside the engine, like number of disk reads per table.
The problems with the latter are
- the counters are global or per-table. We need them to be per-table-instance
(to handle self-join-like queries correctly) - They may be difficult to get from the SQL layer.
== Getting the counter values ==
This is where the new SHOW EXPLAIN architecture plays against us.
The problem is: at the end of JOIN::optimize(), the plan is saved into an
Explain_select structure, and EXPLAIN output is produced from Explain_select.
Explain_select object has only "explain" information, it has no connection to
objects that participate in query execution (like JOIN_TABs, or handler*, etc).
An apparent solution is to have JOIN::cleanup() save execution data using a
call that is similar to save_explain_data()
Gliffy Diagrams
Attachments
Issue Links
- relates to
-
MDEV-7117 ANALYZE SELECT produces strange r_filtered value on a query with ORDER BY
-
- Open
-
-
MDEV-6393 ANALYZE SELECT crashes in Explain_query::print_explain with a non-existing column
-
- Closed
-
-
MDEV-6394 ANALYZE DELETE .. RETURNING fails with ERROR 2027 Malformed packet
-
- Closed
-
-
MDEV-6398 ANALYZE UPDATE does not populate r_rows
-
- Closed
-
-
MDEV-6400 "ANALYZE SELECT ... INTO @var" doesn't set @var
-
- Closed
-
-
MDEV-7023 Error 2027: Malformed packet and assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_INT24 || field_types[field_pos] == MYSQL_TYPE_LONG' failure in Protocol_text::store_long
-
- Closed
-
-
MDEV-7024 Assertion `! is_set()' failed in Diagnostics_area::set_eof_status on executing ANALYZE SELECT via PS
-
- Closed
-
-
MDEV-7025 ANALYZE SELECT/INSERT/UPDATE/DELETE from a view does not check access permissions on the underlying table
-
- Closed
-
-
MDEV-7027 ANALYZE SELECT/INSERT/UPDATE/DELETE from a view does not check SHOW permission on the view
-
- Closed
-
-
MDEV-6395 ANALYZE UPDATE/DELETE with impossible where does not produce any output
-
- Closed
-
-
MDEV-6396 ANALYZE INSERT/REPLACE is accepted, but does not produce a plan
-
- Closed
-
-
MDEV-6397 ANALYZE SELECT/UPDATE/DELETE increments Com_select/update/delete, but not Com_analyze
-
- Closed
-
-
MDEV-6422
More QA for ANALYZE stmt and JSON
-
- In Progress
-
-
MDEV-407 Print EXPLAIN [ANALYZE] in the slow query log
-
- Closed
-
-
MDEV-6382 ANALYZE $stmt and security
-
- Closed
-
-
MDEV-6388 ANALYZE $stmt output in the slow query log
-
- Closed
-
-
MDEV-7115 ANALYZE SELECT FROM empty table produces a plan which looks different from EXPLAIN
-
- Open
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
test=# explain select count
from one_k where ones < 10;
QUERY PLAN
-------------------------------------------------------------
Aggregate (cost=17.53..17.54 rows=1 width=0)
-> Seq Scan on one_k (cost=0.00..17.50 rows=11 width=0)
Filter: (ones < 10)
(3 rows)
test=# explain analyze select count
from one_k where ones < 10;
QUERY PLAN
--------------------------------------------------------------------------------------------------------
Aggregate (cost=17.53..17.54 rows=1 width=0) (actual time=1.449..1.451 rows=1 loops=1)
-> Seq Scan on one_k (cost=0.00..17.50 rows=11 width=0) (actual time=0.037..1.406 rows=10 loops=1)
Filter: (ones < 10)
Total runtime: 1.560 ms
(4 rows)