? ? Pending

User tests: Successful: Unsuccessful:

avatar n3t
n3t
24 Jan 2022

Summary of Changes

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.

Testing Instructions

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

Actual result BEFORE applying this Pull Request

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

before

Expected result AFTER applying this Pull Request

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

after

Documentation Changes Required

No

Additional info

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.

avatar n3t n3t - open - 24 Jan 2022
avatar n3t n3t - change - 24 Jan 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 24 Jan 2022
Category Libraries
avatar chmst
chmst - comment - 24 Jan 2022

There is a longer history for this select clause - #4114

avatar n3t
n3t - comment - 24 Jan 2022

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.

Just tested with PostgreSQL 14.1, and works fine
postgres

avatar alikon alikon - test_item - 12 Feb 2022 - Tested successfully
avatar alikon
alikon - comment - 12 Feb 2022

I have tested this item successfully on 16d58d5


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36813.

avatar PhocaCz PhocaCz - test_item - 17 Feb 2022 - Tested successfully
avatar PhocaCz
PhocaCz - comment - 17 Feb 2022

I have tested this item successfully on 16d58d5


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36813.

avatar Quy Quy - change - 17 Feb 2022
Status Pending Ready to Commit
Labels Added: ?
avatar Quy
Quy - comment - 17 Feb 2022

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/36813.

avatar zero-24 zero-24 - change - 20 Feb 2022
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: ?
avatar zero-24 zero-24 - close - 20 Feb 2022
avatar zero-24 zero-24 - merge - 20 Feb 2022
avatar zero-24
zero-24 - comment - 20 Feb 2022

Merging here thanks

Add a Comment

Login with GitHub to post a comment