查询带小表的巨大表时如何进行有效的连接 [英] How to do a effective Join when querying Huge table with small table
问题描述
我有2个表考虑表A和表B.表A有500万条记录,表B有20条K记录。我正在加入带有小表的大表,在那里我检查表A记录,每个记录都有表B记录。
I have 2 tables consider TABLE A and TABLE B .TABLE A have 5 million records and TABLE B have 20 K records . I'm joining the large table with small table where I checking TABLE A record with table B record each by each.
DECLARE @ 大
表 ( INN BIGINT , OUTT BIGINT
)
INSERT INTO
@ 大 ( INN , OUTT ) 值
( 11356686 , 2101189 < span class ="pun">)
INSERT INTO
@ < span class ="pln">大 ( INN , OUTT ) 值
( 11369336 , 2101301 )
INSERT INTO
@ 大 ( INN , OUTT ) 值 < span class ="pln">
( 11358687 , 2101487 )
INSERT INTO
@ 大 ( INN , OUTT ) 值
( 11369337 , 2101609 )
DECLARE @ small
< span class ="kwd"> TABLE ( INN BIGINT , OUTT BIGINT
)
INSERT INTO
@ small ( INN , OUTT ) 值
( 11356686 , 2101189 )
INSERT INTO
@ small ( INN , OUTT ) 值
( 11369337 , 2101609 )
DECLARE @Large
TABLE (INN BIGINT,OUTT BIGINT
)
INSERT INTO
@Large (INN,OUTT)values
(11356686,2101189)
INSERT INTO
@Large (INN,OUTT)values
(11369336,2101301)
INSERT INTO
@Large (INN,OUTT)values
(11358687,2101487)
INSERT INTO
@Large (INN,OUTT)values
(11369337,2101609)
DECLARE @small
TABLE (INN BIGINT,OUTT BIGINT
)
INSERT INTO
@small (INN,OUTT)values
(11356686,2101189)
INSERT INTO
@small (INN,OUTT)values
(11369337,2101609)
大:
INN OUTT
11356686 2101189
11369336 2101301
11358687 2101487
11369337 2101609
小:
INN OUTT
11356686 2101189
11369337 2101609
我的查询:
Select CASE WHEN T.INN IS NULL THEN O ELSE 1 END from @LARGE T
LEFT JOIN @SMALLTT
ON T.INN = TT.INN AND T.OUTT = TT.OUTT
来到表格时,它们已被很好地编入索引,甚至在执行计划中也没有提示添加更多索引。 任何人都可以建议我在查询级别应该做什么来更快地获得结果,如CROSS APPLY,HASH JOIN等;
Coming to the tables they are well indexed and even no hints are there in Execution plan to add more indexes. Can any one suggest me what should I do in the query level to get results more quicker like CROSS APPLY,HASH JOIN etc.;
推荐答案
stackoverflow 。如果您要将相同的问题交叉发布到mutliple论坛,那么您至少可以将它们链接起来,这样人们就不会浪费精力。
Duplicate of stackoverflow. If you're going to cross post the same question to mutliple forums, the least you can do is link them so people don't waste the efforts.
这篇关于查询带小表的巨大表时如何进行有效的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!