如何让我的状态更快。 [英] How to make my where in condition faster.

查看:60
本文介绍了如何让我的状态更快。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行以下查询



'

 选择 id 来自产品其中 id  (约4lakh记录)

'



我怎样才能得到结果?



对于简单的1000,2000工作正常



但这需要很长时间才能做出回应。

解决方案

在where子句中放入4lakh == 4 * 100,000条记录是一种愚蠢的做事方式。



首先根据标准选择你的id:

 产品 id  =code-keyword>其中 id   select  id 来自 sometable 其中​​ thecolumn =   mycriteria



或根据标准选择您的产品:

 选择 id 来自产品其中​​ category =  食品 


 创建  TABLE  #tempSource_Table_Name(
Id int
);





  BULK  
INSERT #tempSource_Table_Name
FROM ' C:\\\ n12345.txt'
WITH

FIELDTERMINATOR = ' ,'
ROWTERMINATOR = ' \ n'





 选择 * 来自 #tempSource_Table_Name 









文本文件

1

2

3

4

5



感谢Mehdi Gholam给我一个有价值的链接。





最终查询



 选择 id 来自产品其中​​ id    选择 * 来自 #tempSource_Table_Name)





 <   pre     lang   =  SQL >  drop table #tempSource_Table_Name <   / pre  >  


I want to execute a below query

'

Select id from product where id in ( approximately 4lakh records)

'

How can i get the result?

For simple 1000, 2000 working fine

But this is taking to long to respond.

解决方案

Putting 4lakh == 4*100,000 records in a where clause is a silly way to do things.

Try selecting your id based on a criteria first:

Select id from product where id in ( select id from sometable where thecolumn = "mycriteria" )


Or select your products based on a criteria:

Select id from product where category = "food"


CREATE TABLE #tempSource_Table_Name (
    Id int
);



BULK
INSERT #tempSource_Table_Name
FROM 'C:\12345.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)



select * from #tempSource_Table_Name





Text file
1
2
3
4
5

Thanks Mehdi Gholam for give me a valuable link.


Final query

select id from product where id not in (select * from #tempSource_Table_Name)



<pre lang="SQL">drop table #tempSource_Table_Name</pre>


这篇关于如何让我的状态更快。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆