Saying I have this query:
EXPLAIN SELECT *
FROM (
SELECT "A" as a, i.n FROM (SELECT 1 AS n) AS i
UNION ALL SELECT "B" as a, i.n FROM (SELECT 1 AS n) AS i) AS t
WHERE a = "B";
MySQL says
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 PRIMARY <derived2> \N ref <auto_key0> <auto_key0> 6 const 1 100.00 \N
2 DERIVED <derived3> \N system \N \N \N \N 1 100.00 \N
3 DERIVED \N \N \N \N \N \N \N \N \N No tables used
4 UNION <derived5> \N system \N \N \N \N 1 100.00 \N
5 DERIVED \N \N \N \N \N \N \N \N \N No tables used
So MySQL generated an intermediate index <auto_key0>
but what is behind this index? What columns are used in it? And is there a way I can set this index manually, and force MySQL to use some columns.
EXPLAIN FORMAT=JSON SELECT ...
will return something like
key: <auto_key0>, used_key_parts: ['a'], key_length: 6, ref: ['const']
<auto_key0>
is the index generated by the Optimizer for a derived table.
(There is also "Optimizer trace"; but that probably does not have this particular info.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With