You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This adds a query that takes 150 ms to 500 ms, sometimes up to 1.8 seconds depending on server load.
SELECT`elements`.`id`, `elements`.`canonicalId`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateLastMerged`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id`AS`siteSettingsId`, `elements_sites`.`siteId`, `elements_sites`.`title`, `elements_sites`.`slug`, `elements_sites`.`uri`, `elements_sites`.`content`, `elements_sites`.`enabled`AS`enabledForSite`, `entries`.`sectionId`, `entries`.`fieldId`, `entries`.`primaryOwnerId`, `entries`.`typeId`, `entries`.`postDate`, `entries`.`expiryDate`FROM (SELECT`elements`.`id`AS`elementsId`, `elements_sites`.`id`AS`siteSettingsId`FROM`elements``elements`INNER JOIN`entries``entries`ON`entries`.`id`=`elements`.`id`INNER JOIN`elements_sites``elements_sites`ON`elements_sites`.`elementId`=`elements`.`id`WHERE (`entries`.`sectionId`=2) AND (((`elements`.`enabled`=TRUE) AND (`elements_sites`.`enabled`=TRUE)) AND (`entries`.`postDate`<='2025-01-08 13:01:59') AND ((`entries`.`expiryDate` IS NULL) OR (`entries`.`expiryDate`>'2025-01-08 13:01:59'))) AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY`entries`.`postDate`DESC, `elements`.`id`DESCLIMIT3) `subquery`INNER JOIN`elements``elements`ON`elements`.`id`=`subquery`.`elementsId`INNER JOIN`elements_sites``elements_sites`ON`elements_sites`.`id`=`subquery`.`siteSettingsId`INNER JOIN`entries``entries`ON`entries`.`id`=`subquery`.`elementsId`ORDER BY`entries`.`postDate`DESC, `elements`.`id`DESC
SELECT`elements`.`id`, `elements`.`canonicalId`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateLastMerged`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id`AS`siteSettingsId`, `elements_sites`.`siteId`, `elements_sites`.`title`, `elements_sites`.`slug`, `elements_sites`.`uri`, `elements_sites`.`content`, `elements_sites`.`enabled`AS`enabledForSite`, `entries`.`sectionId`, `entries`.`fieldId`, `entries`.`primaryOwnerId`, `entries`.`typeId`, `entries`.`postDate`, `entries`.`expiryDate`, `structureelements`.`root`, `structureelements`.`lft`, `structureelements`.`rgt`, `structureelements`.`level`FROM (SELECT`elements`.`id`AS`elementsId`, `elements_sites`.`id`AS`siteSettingsId`FROM`elements``elements`INNER JOIN`entries``entries`ON`entries`.`id`=`elements`.`id`INNER JOIN`elements_sites``elements_sites`ON`elements_sites`.`elementId`=`elements`.`id`LEFT JOIN`structureelements``structureelements`ON (`structureelements`.`elementId`=`elements`.`id`) AND (`structureelements`.`structureId`=14)
WHERE (`entries`.`sectionId`=21) AND (((`elements`.`enabled`=TRUE) AND (`elements_sites`.`enabled`=TRUE)) AND (`entries`.`postDate`<='2025-01-08 14:42:59') AND ((`entries`.`expiryDate` IS NULL) OR (`entries`.`expiryDate`>'2025-01-08 14:42:59'))) AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY`structureelements`.`lft`, `entries`.`postDate`DESC, `elements`.`id`DESCLIMIT3) `subquery`INNER JOIN`elements``elements`ON`elements`.`id`=`subquery`.`elementsId`INNER JOIN`elements_sites``elements_sites`ON`elements_sites`.`id`=`subquery`.`siteSettingsId`INNER JOIN`entries``entries`ON`entries`.`id`=`subquery`.`elementsId`LEFT JOIN`structureelements``structureelements`ON (`structureelements`.`elementId`=`subquery`.`elementsId`) AND (`structureelements`.`structureId`=14)
ORDER BY`structureelements`.`lft`, `entries`.`postDate`DESC, `elements`.`id`DESC
I've manually tried to execute the query to find out what exactly is causing indexes not being used, and this was specifically because of the ORDER BY on line 7 (not the ORDER BY on the last line).
Changing the ORDER BY from
ORDER BY `entries`.`postDate` DESC, `elements`.`id` DESC
To
ORDER BY `entries`.`postDate` DESC, `entries`.`id` DESC
What happened?
Description
Hi I'm currently having the same issues, the "Using where; Using temporary; Using filesort" is causing significant load.
Steps to reproduce
To isolate the issue I've created a simple
test.twig
with onlyThis adds a query that takes 150 ms to 500 ms, sometimes up to 1.8 seconds depending on server load.
Same thing happens with structures except this is a bit more complicated:
Expected behavior
I've manually tried to execute the query to find out what exactly is causing indexes not being used, and this was specifically because of the ORDER BY on line 7 (not the ORDER BY on the last line).
Changing the
ORDER BY
fromTo
Would speeding up the query to 2-3 ms. Looks like the secondary ORDER BY was added in Craft 4.8.2 (https://github.com/craftcms/cms/blob/4.x/CHANGELOG.md#482---2024-03-12). I don't really know of a solution for structures.
Craft CMS version
5.5.9
PHP version
8.2.8
Operating system and version
Docker
Database type and version
MySQL 9.0.1
Image driver and version
Imagick 3.7.0 (ImageMagick 7.1.1-13)
Installed plugins and versions
Blitz 5.9.9
CKEditor 4.4.0
Craftagram 4.1.0
GeoMate 3.0.0
Hyper 2.2.2
oEmbed 3.1.3
Retour 5.0.4
SEOmatic 5.1.8
Smith 3.1.0
Views Work 2.2.1
Vite 5.0.1
The text was updated successfully, but these errors were encountered: