大数据查询的问题!请帮忙。
类似这样一个IMEI的数据。因为数据量比较大。目前5W多的数据就查询就超时了。。
不知道大家是否有更加快速的办法
INSERT INTO dbo.KFService_IMEIErrorTB
SELECT isnull(dbo.KFService_IMEIInfoTempTB.IMEINo,''), isnull( dbo.KFService_IMEIInfoTempTB.TerminalSerialNo,''),'产品型号与产品类型不匹配'
FROM dbo.KFService_IMEIInfoTempTB
WHERE IMEINo NOT IN (
SELECT dbo.KFService_IMEIInfoTempTB.IMEINo
FROM dbo.Sys_ComplexParameterTB INNER JOIN
dbo.KFService_ProductModelTB ON dbo.Sys_ComplexParameterTB.ComplexParameterID = dbo.KFService_ProductModelTB.ProductTypeCodeID INNER JOIN
dbo.KFService_IMEIInfoTempTB ON dbo.Sys_ComplexParameterTB.ComplexParameterName = dbo.KFService_IMEIInfoTempTB.ProductTypeCode AND
dbo.KFService_ProductModelTB.ProductModelCode = dbo.KFService_IMEIInfoTempTB.ProductModelCode
WHERE (dbo.Sys_ComplexParameterTB.ComplexParameterTypeCodeID = 3001))
------解决方案--------------------把子查询改成关联查询 才5w数据也不算多。看看是不是计划,不行的话 加索引看看!
------解决方案--------------------
1、用not exsits代替not in,
2、在dbo.Sys_ComplexParameterTB.ComplexParameterTypeCodeID、
dbo.KFService_ProductModelTB.ProductTypeCodeID、
dbo.Sys_ComplexParameterTB.ComplexParameterName 、
dbo.KFService_IMEIInfoTempTB.ProductTypeCode、
dbo.KFService_ProductModelTB.ProductModelCode、
dbo.KFService_IMEIInfoTempTB.ProductModelCode
上建索引
SQL code
INSERT INTO dbo.KFService_IMEIErrorTB
SELECT isnull(dbo.KFService_IMEIInfoTempTB.IMEINo,''), isnull( dbo.KFService_IMEIInfoTempTB.TerminalSerialNo,''),'产品型号与产品类型不匹配'
FROM dbo.KFService_IMEIInfoTempTB TB
WHERE NOT exists (
SELECT 1
FROM dbo.Sys_ComplexParameterTB INNER JOIN
dbo.KFService_ProductModelTB ON dbo.Sys_ComplexParameterTB.ComplexParameterID = dbo.KFService_ProductModelTB.ProductTypeCodeID INNER JOIN
dbo.KFService_IMEIInfoTempTB ON dbo.Sys_ComplexParameterTB.ComplexParameterName = dbo.KFService_IMEIInfoTempTB.ProductTypeCode AND
dbo.KFService_ProductModelTB.ProductModelCode = dbo.KFService_IMEIInfoTempTB.ProductModelCode
WHERE (dbo.Sys_ComplexParameterTB.ComplexParameterTypeCodeID = 3001)
and TB.IMEINo=dbo.KFService_IMEIInfoTempTB.IMEINo
)