需要MySQL專家的幫助來提高以下查詢的執行時間。由於將更多數據添加到rsdata和trdata表中,它每天晚上大約需要1小時25分鐘,每天增長几分鐘。其他3個表格是靜態的。MySQL:需要SQL查詢性能改進幫助
任何幫助非常感謝。
表大小爲:
rsdata - 480,566 rows/130.4 MiB
trdata - 522,506 rows/64.3 MiB
module - 1,458 rows/164 KiB
variantgates - 87 rows/8 KiB
testatussequence - 8 rows/2.3 KiB
查詢:
select distinct
rsdata.rs_variant,
rsdata.weeknumber,
rsdata.rs_moduleid,
rsdata.rs_objectidentifier,
trdata.tr_objectidentifier,
trdata.tr_testversion,
trdata.tr_plannedgate,
trdata.tr_vnvmethod,
testatussequence.tesequencenr,
trdata.tr_testexecutionstatus
from rsdata,
trdata,
module,
variantgates,
testatussequence
where rsdata.weeknumber='1408'
and rsdata.rs_moduleid = module.moduleid
and rsdata.rs_reviewstatus != 'Obsolete'
and rsdata.rs_reviewstatus != 'Rejected'
and rsdata.rs_introbjectidentifieralllevels != ''
and rsdata.rs_introbjectidentifieralllevels != 'Unknown'
and trdata.weeknumber='1408'
and trdata.tr_plannedgate != ''
and trdata.tr_plannedgate != 'Unknown'
and trdata.tr_plannedgate = variantgates.gate
and trdata.tr_variant = variantgates.variant
and trdata.tr_testexecutionstatus = testatussequence.testatus
and find_in_set(trdata.tr_objectidentifier, (select rsdata.rs_introbjectidentifieralllevels))
order by
rs_variant ASC,
weeknumber ASC,
rs_moduleid ASC,
rs_objectidentifier ASC,
tr_testversion ASC,
tr_plannedgate ASC,
tr_vnvmethod ASC,
tesequencenr DESC;
輸出從解釋查詢:
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY variantgates ALL Variant_2,Variant NULL NULL NULL 87 Using where; Using temporary; Using filesort
1 PRIMARY trdata ref TR_Variant,WeekNumber TR_Variant 23 remets.variantgates.Variant 5226 Using where
1 PRIMARY testatussequence eq_ref PRIMARY,TEStatus PRIMARY 22 remets.trdata.TR_TestExecutionStatus 1
1 PRIMARY rsdata ref RSDataSI1,RSDataUI2,WeekNumber RSDataUI2 7 const 75658 Using where
1 PRIMARY module ref ModuleUI1 ModuleUI1 11 remets.rsdata.RS_ModuleID 10 Using where; Using index
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used
表的細節:
CREATE TABLE `rsdata` (
`RS_Variant` varchar(20) default 'Unknown',
`RS_ModuleID` varchar(8) default 'Unknown',
`RS_ObjectIdentifier` varchar(50) default 'Unknown',
`RS_ObjectType` varchar(20) default 'Unknown',
`WeekNumber` varchar(4) default '9999',
`RS_ReviewStatus` varchar(12) default 'Unknown',
`RS_Priority` varchar(20) default 'Unknown',
`RS_PlannedGate` varchar(10) default 'Unknown',
`RS_VnVMethod` varchar(50) default 'Unknown',
`RS_Datasheet` varchar(1) default NULL,
`RS_RSLinks` int(11) default '0',
`RS_TSLinks` int(11) default '0',
`RS_ReqLinked` varchar(10) default 'Unknown',
`RS_VnVLinked` varchar(10) default 'Unknown',
`RS_InRSObjectIdentifierOneLevel` varchar(500) default 'Unknown',
`RS_InTSObjectIdentifierOneLevel` varchar(500) default 'Unknown',
`RS_InTSObjectIdentifierAllLevels` varchar(750) default 'Unknown',
`RS_InTRObjectIdentifierAllLevels` varchar(750) default 'Unknown',
UNIQUE KEY `RSDataUI1` (`RS_Variant`,`RS_ModuleID`,`RS_ObjectIdentifier`,`WeekNumber`),
KEY `RSDataSI1` (`RS_ModuleID`,`WeekNumber`),
KEY `RSDataUI2` (`WeekNumber`,`RS_Variant`,`RS_ModuleID`,`RS_ObjectIdentifier`),
KEY `WeekNumber` (`WeekNumber`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `trdata` (
`TR_Variant` varchar(20) default NULL,
`TR_ModuleID` varchar(8) default NULL,
`TR_ObjectIdentifier` varchar(50) default NULL,
`TR_ObjectType` varchar(20) default 'Unknown',
`WeekNumber` varchar(4) default '9999',
`TR_ReviewStatus` varchar(12) default 'Unknown',
`TR_Priority` varchar(20) default 'Unknown',
`TR_PlannedGate` varchar(10) default 'Unknown',
`TR_VnVMethod` varchar(50) default 'Unknown',
`TR_TestVersion` varchar(12) default 'Unknown',
`TR_TestExecutionStatus` varchar(20) default 'Unknown',
UNIQUE KEY `TR_Variant` (`TR_Variant`,`TR_ModuleID`,`TR_ObjectIdentifier`,`WeekNumber`),
KEY `TRDataSI1` (`TR_ModuleID`,`WeekNumber`),
KEY `WeekNumber` (`WeekNumber`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `module` (
`ModuleID` varchar(8) default NULL,
`ModuleType` varchar(5) default NULL,
`ModuleName` varchar(50) default NULL,
`ModuleNameLng` varchar(250) default NULL,
UNIQUE KEY `ModuleUI1` (`ModuleID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `variantgates` (
`Variant` varchar(20) default NULL,
`GateGroup` varchar(20) default NULL,
`GateSequenceNr` int(11) default NULL,
`Gate` varchar(10) default NULL,
UNIQUE KEY `Variant_2` (`Variant`,`GateGroup`,`GateSequenceNr`),
KEY `Variant` (`Variant`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE `testatussequence` (
`TESequenceNr` int(11) NOT NULL,
`TEStatus` varchar(20) NOT NULL default '',
PRIMARY KEY (`TEStatus`),
UNIQUE KEY `TEStatus` (`TEStatus`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
任何索引?我猜 – Alexander
絕對應該索引你的表 – developerCoder
表被索引 - 你可以在最後的代碼片段中看到索引 – user2301506