0

我已将以下查询转换为视图表名销售板:

select 
distinct(p.paymentID) AS paymentID,
j.jobID AS jobID,j.jobNumber AS jobNumber,j.jobType AS jobType, j.countType AS countType, j.countID AS countID,
ui.userID AS salesRep,
(
    case 
        when (j.idType = 'dealership') then d.dealershipName 
        when (j.idType = 'Group') then g.groupName 
        when (j.idType = 'Agency') then a.agencyName 
    end
) AS dealershipName,
(
    case 
        when (p.manualTimestamp <> '0000-00-00 00:00:00') then p.manualTimestamp 
        when (p.manualTimestamp = '0000-00-00 00:00:00') then from_unixtime(p.timestamp) 
    end
) AS checkTS,
p.paymentAmount AS paymentAmount,
po.estimatedMailArrival AS estimatedMailArrival 
from jobs j 
left join smdealershipjoins smdj on j.dealershipID = smdj.dealership 
left join smgroupjoins smgj on j.dealershipID = smgj.groupID 
left join smagencyjoins smaj on j.dealershipID = smaj.agencyID 
join userinfo ui on 
(
    case 
        when (j.idType = 'dealership') then (smdj.sm = ui.userID) 
        when (j.idType = 'Group') then (smgj.sm = ui.userID) 
        when (j.idType = 'Agency') then (smaj.sm = ui.userID) 
    end
) 
left join dealerships d on smdj.dealership = d.dealershipID 
left join dealershipgroups g on smgj.groupID = g.groupID 
left join agencies a on smaj.agencyID = a.agencyID 
join payments p on j.jobID = p.jobID 
left join purchaseorders po on j.jobID = po.jobID 
order by 
(
    case 
        when (p.manualTimestamp <> '0000-00-00 00:00:00') then p.manualTimestamp 
        when (p.manualTimestamp = '0000-00-00 00:00:00') then from_unixtime(p.timestamp) 
    end
) desc

视图保存并返回预期结果。但是,每当我在新视图表上运行最简单的查询时,查询都需要几分钟才能运行。我四处搜寻,看看是否有什么可以解决的 - 但我空手而归:(

有什么可以做的吗?我绞尽脑汁想寻求帮助。

4

1 回答 1

1

如果任何结果集的大小超过了您的查询的大小,innodb_buffer_pool_size由于 I/O 分页,您的查询将花费大量时间。ORDER BY在您的情况下,由于该子句,您的 from 语句中包含的每个表都必须加载到内存中。

通过使用分区或增加缓冲池的大小来减少提取的数据量。

于 2013-04-02T01:57:48.803 回答