ここ2 MySQLのクエリが...これは単純なものですが、最初に別のフィールド を選択をmytable_planing二にmytable_cityを選択し、両方のフィールドには、フロンのテーブルを結合します。 1.82977秒なぜ異なるSQL実行時刻ですか?
いくつかのフィールド
SELECT SQL_NO_CACHE
DISTINCT `mytable_planing`.`NAME` AS `FILTER_CITY`
FROM `b_iblock_element` `mytable`
LEFT JOIN `b_iblock_element_property` `mytable_planing_id`
ON `mytable`.`ID` = `mytable_planing_id`.`IBLOCK_ELEMENT_ID`
AND `mytable_planing_id`.`IBLOCK_PROPERTY_ID` = 70
INNER JOIN `b_iblock_element` `mytable_planing`
ON `mytable_planing_id`.`VALUE_HASH` = `mytable_planing`.`XML_HASH`
LEFT JOIN `b_iblock_element_property` `mytable_housetype_id`
ON `mytable_planing`.`ID` = `mytable_housetype_id`.`IBLOCK_ELEMENT_ID`
AND `mytable_housetype_id`.`IBLOCK_PROPERTY_ID` = 46
INNER JOIN `b_iblock_element` `mytable_housetype`
ON `mytable_housetype_id`.`VALUE_HASH` = `mytable_housetype`.`XML_HASH`
LEFT JOIN `b_iblock_element_prop_s4` `mytable_street_id`
ON `mytable_street_id`.`PROP_60_HASH` = `mytable_housetype`.`XML_HASH`
INNER JOIN `b_iblock_element` `mytable_street`
ON `mytable_street_id`.`IBLOCK_ELEMENT_ID` = `mytable_street`.`ID`
LEFT JOIN `b_iblock_section` `mytable_city`
ON `mytable_street`.`IBLOCK_SECTION_ID` = `mytable_city`.`ID`
INNER JOIN `b_iblock_element_property` `mytable_archive`
ON `mytable`.`ID` = `mytable_archive`.`IBLOCK_ELEMENT_ID`
AND `mytable_archive`.`IBLOCK_PROPERTY_ID` = 321
WHERE `mytable`.`IBLOCK_ID` = 7
AND (`mytable_archive`.`VALUE_NUM` IS NULL OR `mytable_archive`.`VALUE_NUM` = 0)
AND (`mytable_planing`.`NAME` IS NOT NULL AND LENGTH(`mytable_planing`.`NAME`) > 0)
時間の選択異なる場所でいくつかの
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE mytable_housetype_id ref IBLOCK_PROPERTY_ID IBLOCK_PROPERTY_ID 4 const 4 Using where; Using temporary
1 SIMPLE mytable_planing eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_housetype_id.IBLOCK_ELEMENT_ID 1
1 SIMPLE mytable_housetype ref XML_HASH XML_HASH 96 tesserbd.mytable_housetype_id.VALUE_HASH 1 Using index
1 SIMPLE mytable_planing_id ref VALUE_HASH VALUE_HASH 96 tesserbd.mytable_planing.XML_HASH 15 Using where
1 SIMPLE mytable_archive ref ix_iblock_element_property_1 ix_iblock_element_property_1 8 tesserbd.mytable_planing_id.IBLOCK_ELEMENT_ID,const 1 Using where
1 SIMPLE mytable_street_id ref PROP_60_HASH PROP_60_HASH 96 tesserbd.mytable_housetype_id.VALUE_HASH 185 Using where
1 SIMPLE mytable eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_planing_id.IBLOCK_ELEMENT_ID 1 Using where
1 SIMPLE mytable_street eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_street_id.IBLOCK_ELEMENT_ID 1
1 SIMPLE mytable_city eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_street.IBLOCK_SECTION_ID 1 Using where
第二EXPLAIN:しかし、クエリ
SELECT SQL_NO_CACHE
DISTINCT `mytable_city`.`NAME` AS `FILTER_CITY`
FROM `b_iblock_element` `mytable`
LEFT JOIN `b_iblock_element_property` `mytable_planing_id`
ON `mytable`.`ID` = `mytable_planing_id`.`IBLOCK_ELEMENT_ID`
AND `mytable_planing_id`.`IBLOCK_PROPERTY_ID` = 70
INNER JOIN `b_iblock_element` `mytable_planing`
ON `mytable_planing_id`.`VALUE_HASH` = `mytable_planing`.`XML_HASH`
LEFT JOIN `b_iblock_element_property` `mytable_housetype_id`
ON `mytable_planing`.`ID` = `mytable_housetype_id`.`IBLOCK_ELEMENT_ID`
AND `mytable_housetype_id`.`IBLOCK_PROPERTY_ID` = 46
INNER JOIN `b_iblock_element` `mytable_housetype`
ON `mytable_housetype_id`.`VALUE_HASH` = `mytable_housetype`.`XML_HASH`
LEFT JOIN `b_iblock_element_prop_s4` `mytable_street_id`
ON `mytable_street_id`.`PROP_60_HASH` = `mytable_housetype`.`XML_HASH`
INNER JOIN `b_iblock_element` `mytable_street`
ON `mytable_street_id`.`IBLOCK_ELEMENT_ID` = `mytable_street`.`ID`
LEFT JOIN `b_iblock_section` `mytable_city`
ON `mytable_street`.`IBLOCK_SECTION_ID` = `mytable_city`.`ID`
INNER JOIN `b_iblock_element_property` `mytable_archive`
ON `mytable`.`ID` = `mytable_archive`.`IBLOCK_ELEMENT_ID`
AND `mytable_archive`.`IBLOCK_PROPERTY_ID` = 321
WHERE `mytable`.`IBLOCK_ID` = 7
AND (`mytable_archive`.`VALUE_NUM` IS NULL OR `mytable_archive`.`VALUE_NUM` = 0)
AND (`mytable_city`.`NAME` IS NOT NULL AND LENGTH(`mytable_city`.`NAME`) > 0)
は時間の時間に大きな違いを実行します。 0.00206秒。最初の明確な
なぜなし -
は
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE mytable_housetype_id ref IBLOCK_PROPERTY_ID IBLOCK_PROPERTY_ID 4 const 4 Using where; Using temporary
1 SIMPLE mytable_planing eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_housetype_id.IBLOCK_ELEMENT_ID 1 Using where
1 SIMPLE mytable_housetype ref XML_HASH XML_HASH 96 tesserbd.mytable_housetype_id.VALUE_HASH 1 Using index; Distinct
1 SIMPLE mytable_planing_id ref VALUE_HASH VALUE_HASH 96 tesserbd.mytable_planing.XML_HASH 15 Using where; Distinct
1 SIMPLE mytable eq_ref PRIMARY,ix_iblock_element_1 PRIMARY 4 tesserbd.mytable_planing_id.IBLOCK_ELEMENT_ID 1 Using where; Distinct
1 SIMPLE mytable_archive ref ix_iblock_element_property_1 ix_iblock_element_property_1 8 tesserbd.mytable_planing_id.IBLOCK_ELEMENT_ID,const 1 Using where; Distinct
1 SIMPLE mytable_street_id ref PROP_60_HASH PROP_60_HASH 96 tesserbd.mytable_housetype_id.VALUE_HASH 185 Using where; Distinct
1 SIMPLE mytable_street eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_street_id.IBLOCK_ELEMENT_ID 1 Distinct
1 SIMPLE mytable_city eq_ref PRIMARY PRIMARY 4 tesserbd.mytable_street.IBLOCK_SECTION_ID 1 Using index; Distinct
だけ余分に違うのEXPLAIN?
私は別のフィールドとフィールドの組み合わせにインデックスを追加しようとしましたが、結果はありません。
これが第二に、あなたは、いくつかの列にアクセスすることを意味し、私が最初に
1 SIMPLE mytable_city Using where
で任意の助け秒で
インデックスの簡単な経験則:クエリの「決定」コンテキストで使用されるフィールドにはインデックスを付ける必要があります。つまり、 'where'、' join'、 'order by'などでフィールドが使用されている場合は、インデックスを付ける必要があります。 –
@MarcBイムすべてのフィールドがそれぞれ1上と 'mytable_planing'.'ID' =' mytable_housetype_id'.'IBLOCK_ELEMENT_ID' と 'mytable_housetype_id'.'IBLOCK_PROPERTY_ID' = ONこのためIBLOCK_ELEMENT_ID、IBLOCK_PROPERTY_IDのようないくつかの組み合わせにインデックスを持って、それを知っています46 – Gelid