この調整が可能かどうかアドバイスが必要です。
テーブル:
CREATE TABLE UTIL_DAY (
CompID varchar(15) collate utf8_czech_ci NOT NULL,
TestplanID int(10) unsigned NOT NULL default '0',
FromDate datetime NOT NULL default '0000-00-00 00:00:00',
ToDate datetime NOT NULL default '0000-00-00 00:00:00',
Interval int(11) NOT NULL default '0',
Variant varchar(25) collate utf8_czech_ci default NULL,
WO_ID int(11) default NULL,
SAPTime int(5) default NULL,
UseTime int(5) NOT NULL,
MeasureCount int(10) unsigned NOT NULL,
KEY CompID (CompID),
KEY TestplanID (TestplanID),
KEY WO_ID (WO_ID),
KEY FromDate (FromDate),
KEY Variant (Variant)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
現在のクエリ:
UPDATE UTIL_DAY UDAY SET TestplanID = (SELECT TestplanID
FROM (SELECT UD_U.Variant,UD_U.WO_ID,VS.TestplanID
FROM (SELECT UD.Variant,UD.WO_ID
FROM UTIL_DAY UD WHERE SUBSTR(CompID,1,3) <> 'AOI'
GROUP BY UD.Variant,UD.WO_ID) UD_U
JOIN VARIANTS V ON UD_U.Variant = V.Variant
JOIN VARIANT_STATUS VS ON V.VariantID = VS.VariantID
JOIN TESTPLANS_WO_ID TW ON UD_U.WO_ID = TW.WO_ID
WHERE VS.TestplanID = TW.TestplanID
GROUP BY UD_U.Variant,UD_U.WO_ID ) TP
WHERE TP.Variant = UDAY.Variant AND TP.WO_ID = UDAY.WO_ID)
そして私の更新は一時テーブルです:
CREATE TEMPORARY TABLE UTIL_DAY_TEMP (
Variant varchar(25) COLLATE 'utf8_czech_ci' NOT NULL,
WO_ID int unsigned NOT NULL,
TestplanID int unsigned NOT NULL,
PRIMARY KEY Variant_WO_ID (Variant, WO_ID)) COMMENT='' ENGINE='InnoDB' COLLATE 'utf8_czech_ci';
INSERT IGNORE INTO UTIL_DAY_TMP (SELECT UD_U.Variant,UD_U.WO_ID,VS.TestplanID
FROM (SELECT UD.Variant,UD.WO_ID
FROM UTIL_DAY UD WHERE SUBSTR(CompID,1,3) <> 'AOI'
GROUP BY UD.Variant,UD.WO_ID) UD_U
JOIN VARIANTS V ON UD_U.Variant = V.Variant
JOIN VARIANT_STATUS VS ON V.VariantID = VS.VariantID
JOIN TESTPLANS_WO_ID TW ON UD_U.WO_ID = TW.WO_ID
WHERE VS.TestplanID = TW.TestplanID
GROUP BY UD_U.Variant,UD_U.WO_ID);
UPDATE UTIL_DAY UDAY SET TestplanID = (SELECT TestplanID
FROM UTIL_DAY_TEMP TP
WHERE TP.Variant = UDAY.Variant AND TP.WO_ID = UDAY.WO_ID);
この改善により、200 万行を超えるクエリが 400% 高速化されました。しかし、この改善は同じ結果をもたらしますか? 回答ありがとうございます。