1
je requête suivanteMysql lent groupe de requêtes concat avec sous-requête
select
`cs`.sku ,
group_concat(
IF(
(
(
SELECT
count(id_catalog_category)
from
`catalog_category`
where
lft <= `ccg`.lft
and rgt >= `ccg`.rgt
)=2
),
`ccg`.name_en,
NULL
)
) as level_1_categories
from
catalog_simple `cs`
left join `catalog_config` `cc`
on `cs`.`fk_catalog_config` = `cc`.`id_catalog_config`
left join `catalog_config_has_catalog_category` `cchcc`
on `cc`.`id_catalog_config` = `cchcc`.`fk_catalog_config`
left join `catalog_category` `ccg`
on `cchcc`.`fk_catalog_category` = `ccg`.`id_catalog_category`
group by `cc`.sku
Expliquer donner des résultats étendus suivants.
"id" "select_type" "table" "type" "possible_keys" "key" "key_len" "ref" "rows" "filtered" "Extra"
"1" "PRIMARY" "cs" "ALL" NULL NULL NULL NULL "27384" "100.00" "Using temporary; Using filesort"
"1" "PRIMARY" "cc" "eq_ref" "PRIMARY" "PRIMARY" "4" "pkfas.cs.fk_catalog_config" "1" "100.00" ""
"1" "PRIMARY" "cchcc" "ref" "uk_id_catalog_config_has_catalog_category,fk_catalog_config" "uk_id_catalog_config_has_catalog_category" "4" "pkfas.cc.id_catalog_config" "2" "100.00" "Using index"
"1" "PRIMARY" "ccg" "eq_ref" "PRIMARY" "PRIMARY" "4" "pkfas.cchcc.fk_catalog_category" "1" "100.00" ""
"2" "DEPENDENT SUBQUERY" "catalog_category" "ALL" "lft,rgt" NULL NULL NULL "1739" "100.00" "Using where"
Cette requête prend environ 100 secondes pour exécuter
Sql lent a des résultats suivants
Query_time: 95.189445 Lock_time: 0.000000 Rows_sent: 8523 Rows_examined: 242668622
S'il vous plaît me guider la façon de le faire rapidement. Merci à l'avance
Merci avec quelques modifications ... ça a marché :) –
Np :) Pouvez-vous me dire combien de temps cela a pris? et quelles modifications avez-vous faites? – Stephan
C'était la sous-requête finale. SELECT 'ccg'.'id_catalog_category', SUM (IF (' ccg1'.'id_catalog_category' IS NULL, 0,1)) comme za_count FROM '' catalog_category' ccg' LEFT JOIN '' catalog_category' ccg1' ON 'ccg1'.lft <=' ccg'.lft ET 'ccg1'.rgt> =' ccg'.rgt GROUPE BY 'ccg'.'''_catalogue_catégorie' –