I'm in the process of optimizing my queries from my web app. But as I do not have much experience I can not find a solution to remove the use of FILESORT.
Does anyone have any idea what to do to stop this FILESORT? What indices to create?
SELECT 'essences'.*, 'brands'.'name' as brand_name, 'brands'.'sigla'
FROM ('essences')
INNER JOIN 'brands' ON 'brands'.'id' = 'essences'.'brand_id'
WHERE essences.published = 1
ORDER BY 'essences'.'name' asc
EXPLAIN
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE brands ALL PRIMARY - - - 11 Using temporary; Using filesort
1 SIMPLE essences ref name name 4 receitadiy.brands.id 69 Using index condition
Table brands
CREATE TABLE 'brands' (
'id' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
'name' VARCHAR(50) NOT NULL,
'description' TEXT NULL,
'sigla' VARCHAR(50) NULL DEFAULT NULL,
'url' VARCHAR(250) NULL DEFAULT NULL,
'published' TINYINT(4) NULL DEFAULT '0',
PRIMARY KEY ('id'),
INDEX 'name' ('name', 'published')
)
Table essences
CREATE TABLE 'essences' (
'id' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
'name' VARCHAR(150) NOT NULL,
'brand_id' INT(10) UNSIGNED NOT NULL,
'tag' CHAR(10) NULL DEFAULT NULL,
'desc' TEXT NULL,
'alert' TINYINT(2) NULL DEFAULT NULL,
'alert_color' VARCHAR(50) NULL DEFAULT NULL,
'alert_notes' TEXT NULL,
'preco_ml' DECIMAL(10,2) NOT NULL,
'published' TINYINT(4) NULL DEFAULT '0',
PRIMARY KEY ('id'),
INDEX 'tag' ('tag'),
INDEX 'name' ('brand_id', 'name', 'published')
)