我有mysql查询,它在发送数据阶段时会挂起。分析慢查询日志时
Rows_sent:176975081
Rows_examined:408406766
这些行数大于表中的行数。
以下是查询
select md.Event_id,db.Listing_ID,db.original_date,
DATE_FORMAT(ed.event_date, '%m-%d-%Y') AS 'EventDate',
datediff(ed.event_date,db.original_date),
zn.zonename,
sn.sectionname,
rn.Row_Name,
db.original_price,
db.last_date,
db.last_price,
(1 - (original_price/Last_Price)) as 'PercentChange'
from market_data as md
inner join id_result as db
on db.id=md.id
left join
zonename zn ON md.zn_id = zn.zoneId
inner JOIN
rowname rn ON md.RN_ID = rn.RN_ID
inner JOIN
sectionname sn ON md.SN_ID = sn.SN_ID
inner JOIN
event_data ed ON md.Event_id = ed.Event_id
where md.dirtyTicketInd=0
以下是表格结构
'CREATE TABLE `id_result` (
`id` int(11) NOT NULL,
`listing_id` int(20) DEFAULT NULL,
`original_date` date DEFAULT NULL,
`original_price` decimal(10,2) DEFAULT NULL,
`last_date` date DEFAULT NULL,
`last_price` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `listing_id` (`listing_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1'
'CREATE TABLE `market_data` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`currentPrice` varchar(10) NOT NULL DEFAULT ''0'',
`SN_ID` int(11) NOT NULL,
`quantity` tinyint(2) NOT NULL DEFAULT ''0'',
`seatNumbers` varchar(60) NOT NULL DEFAULT ''0'',
`ZN_ID` int(11) NOT NULL,
`listingAttributeList` varchar(15) NOT NULL DEFAULT ''0'',
`listingAttributeCategoryList` varchar(15) NOT NULL DEFAULT ''0'',
`deliveryTypeList` varchar(15) NOT NULL DEFAULT ''0'',
`ticketClass` varchar(15) NOT NULL DEFAULT ''0'',
`dirtyTicketInd` tinyint(4) NOT NULL DEFAULT ''0'',
`splitOption` tinyint(2) NOT NULL DEFAULT ''0'',
`ticketSplit` tinyint(3) NOT NULL DEFAULT ''0'',
`splitVector` varchar(40) NOT NULL DEFAULT ''0'',
`sellerOwnInd` tinyint(3) NOT NULL DEFAULT ''0'',
`faceValue` varchar(25) NOT NULL DEFAULT ''0'',
`serviceFee` varchar(15) NOT NULL DEFAULT ''0'',
`deliveryFee` varchar(12) NOT NULL DEFAULT ''0'',
`totalCost` varchar(25) NOT NULL DEFAULT ''0'',
`score` decimal(12,7) NOT NULL DEFAULT ''0.0000000'',
`seller_price` decimal(10,5) NOT NULL DEFAULT ''0.00000'',
`Event_id` int(11) DEFAULT NULL,
`RN_ID` int(11) NOT NULL,
`SSN_ID` int(11) NOT NULL,
`LI_ID` int(11) NOT NULL,
`TS_ID` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `SSN_ID` (`SSN_ID`),
KEY `SN_ID` (`SN_ID`),
KEY `ZN_ID` (`ZN_ID`),
KEY `event_id` (`Event_id`),
KEY `ts_id` (`TS_ID`),
KEY `LI_ID` (`LI_ID`)
) ENGINE=MyISAM AUTO_INCREMENT=218909923 DEFAULT CHARSET=utf16'
答案 0 :(得分:0)
你有JOIN
。它需要“检查”两个表中的行,因此计数很高。而且,由于您需要行的组合,'sent'比任何一个表都要大。
(无关的说明......)
UTF16?我不认为我听说有人使用它。加入字符串时要小心,特别是如果它们有不同的CHARACTER SETs
。
VARCHARs
中的费用和成本?很难做算术或排序。