SQL选择查询性能改进

时间:2015-05-23 05:39:26

标签: performance sql-server-2012 projection

我有很多这样的问题:

-- get all data that exists in source but not yet in destination
SELECT 
*
INTO #temp
FROM source T010T
WHERE NOT EXISTS
                (
                SELECT TOP 1 1 FROM destination P510T
                WHERE WH_CD = T010T.WH_CD  
                AND   POS_NO = T010T.POS_NO 
                AND   SLIP_NO = T010T.TRAN_NO
                AND   OPE_DATE = T010T.SL_REC_DATE 
                ) 
-- process the data 
....
-- insert data into destination 
Insert into destination select * From #temp

我想知道这种方法会影响性能吗?因为我没有得到真正的数据来测试,而且这是在本地运行所以我有点害怕,当实现时,这些查询将是一个痛苦的@@!

还有更好的选择吗?

p / s:比较中使用的两个表上的列都是主键primarykey(wh_cd,pos_no,slip_no,ope_date) ...

1 个答案:

答案 0 :(得分:1)

尝试使用Song.prototype.songIntersect = function(input) { var bestSong = null; var bestCount = -Infinity; for (var i in songs) { var currentCount = setIntersection(songs[i].lyrics, input).length; if (currentCount > best.count) { bestSong = song[i]; bestCount = currentCount; } } return bestSong && bestSong.name; } 代替:

Left Join