User tests: Successful: Unsuccessful:
left joined table b is not used in query at all, it just generates multiple same rows, which are solved by distinct. Removing both gives the same result and removes 'using temporary table' and 'Range checked for each record' from query explain, which could cause high performance issues on some servers.
Plus add quoting on table name.
Enable Debug mode, open list of articles, see generated Explain for query
SELECT DISTINCT a.id AS value, a.path, a.title AS text, a.level, a.published, a.lft
FROM sdx54_tags AS a
LEFT JOIN `sdx54_tags` AS b ON a.lft > b.lft AND a.rgt < b.rgt
WHERE `a`.`lft` > 0 AND a.published IN (0, 1) ORDER BY a.lft ASC
Tags in filetr field for Tags are displayed, sorted by it ordering
Explain of query shows
Using where; Using temporary; Using filesort
Range checked for each record (index map: 0x10); Distinct
Tags in filetr field for Tags are displayed, sorted by it ordering
Query is simplified to
SELECT a.id AS value, a.path, a.title AS text, a.level, a.published, a.lft
FROM `sdx54_tags` AS a
WHERE `a`.`lft` > 0 AND a.published IN (0, 1) ORDER BY a.lft ASC
Explain shows
Using where; Using filesort
No
This issue remains in 4.0 and 4.1, If accepted I could prepare PR there also.
In my case this becomes issue after moving from MySQL 5 to MySQL 8 on some server. the original query took aprox. 8s, new one is aprox 5ms.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Vow, I didn't search so far in history.
Ok, as far as I understand, #4114 replaced 'group by' by distinct, but neither of it is IMO needed, as it is used just to remove duplicate records, loaded just because there is left join, which is not needed, as there is no usage of table b neither in select list fields, nor where clause nor order by clause.
I have tested this item
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
Labels |
Added:
?
|
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-02-20 09:29:10 |
Closed_By | ⇒ | zero-24 | |
Labels |
Added:
?
|
Merging here thanks
There is a longer history for this select clause - #4114