Well this is certainly interesting.
I've got the following query that uses this relations table when displaying category pages.
$sql = '
SELECT wp.item_id, wp.label, wp.path
FROM ' . RELATIONS_TABLE . ' rel
LEFT JOIN ' . ITEMS_TABLE . " wp
ON rel.item_id = wp.item_id
WHERE rel.{$t->category_sql}
ORDER BY rel.insert_order ASC
LIMIT {$t->start_id}, {$config->options->display->category->per_page}";
- $sql = '
- SELECT wp.item_id, wp.label, wp.path
- FROM ' . RELATIONS_TABLE . ' rel
- LEFT JOIN ' . ITEMS_TABLE . " wp
- ON rel.item_id = wp.item_id
- WHERE rel.{$t->category_sql}
- ORDER BY rel.insert_order ASC
- LIMIT {$t->start_id}, {$config->options->display->category->per_page}";
Because a category can be assigned as a parent category, I'm fetching the category_id of any category with the current category set as its' parent before this query and that gives me either a "category_id = N" or "category_id IN(N,N)" for "$t->category_sql" depending on how many categories there are. This allows me to have parent categories that both have their own items, and will include the items of their immediate children in their category pages.
The intersting part is that when using EXPLAIN with this query, I see the extra values "Using WHERE; Using Filesort". From what I understand "using filesort" is bad news. There used to be a DISTINCT clause on that query, but that was causing "using temporary" which is bad news as well.
However, when I drop that ORDER BY clause from the query, my extra turns into "Using Index", which means it doesn't even have to look at the data rows, and it still returns the same order. I'm guessing because of that insert_id PRIMARY KEY.
The query also notes both the UNIQUE KEY and the single category_id INDEX as possible keys, it's deciding to use the single column key by the looks of it, though the key_len being 2 in the output for that table has me confused.

Strong with this one, the sudo is.