[MDEV-27146] extend EXPLAIN output to include "attached_condition" Created: 2021-11-30 Updated: 2022-05-02 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | Nuno | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Using MariaDB 10.5.12 on CentOS 7 If I run:
This query uses the index on the "ip" column (simple index). However, if I run (simplest example query I could get):
The subquery on the "ips" table doesn't have "ip" as "possible_keys", it uses the "time" index (which isn't even used in the query!), and does a table scan (and this is a huge table). If I hardcode an IP, like:
It uses the "ip" key as intended. What is preventing the subquery from using the index as supposed, in the `ip`=srl.ip example? ------- UPDATE: ANALYZE FORMAT=JSON
I guess `attached_condition` tells me what it is! One is `utf8_general_ci`, the other is `utf8mb4_unicode_ci`, so MariaDB converts one of them, to match the collation. I didn't know about `ANALYZE` ! Great stuff! Maybe a suggestion would be to add `attached_condition` in EXPLAIN EXTENDED or so (as it seems that EXPLAIN by itself already predicts this does happen), and it would greatly help! |
| Comments |
| Comment by Rick James [ 2022-04-14 ] |
|
@nuno - Please provide `SHOW CREATE TABLE` for the two tables so we can see the datatypes and indexes. |
| Comment by Nuno [ 2022-04-14 ] |
|
Thanks, but as per the description above, I "figured it out" by using the ANALYZE. It's because of the different collations. Ironically, I had the exact same problem earlier today, where a query wasn't performing at all, when I was "sure" the JOINs and Indexes were all fine!! But the EXPLAIN was showing "Temp table & Filesort"... Then I checked ANALYZE, and found the same collation issue (and fixed it). Again, it would have saved me time if EXPLAIN EXTENDED told me straight away that there is a collation conversion involved. |
| Comment by Nuno [ 2022-04-20 ] |
|
And I've just realized that "EXPLAIN FORMAT=JSON" also includes "attached_condition" in it. Yeah... it would be very helpful if the output of EXPLAIN (on table format) included "attached_condition" by default |