【发布时间】:2011-05-14 09:10:55
【问题描述】:
我有 3 张桌子:
table_product (30 000 row)
---------
ID
label
_
table_period (225 000 row)
---------
ID
date_start
date_end
default_price
FK_ID_product
和
table_special_offer (10 000 row)
-----
ID
label
date_start,
date_end,
special_offer_price
FK_ID_period
所以我需要从所有这些表中加载数据,所以这就是我要做的: 1/ 像这样从“table_product”加载数据
select *
from table_product
where label like 'gun%'
2/ 像这样从“table_period”加载数据
select *
from table_period
where FK_ID_product IN(list of all the ids selected in the 1)
3/ 像这样从“table_special_offer”加载数据
select *
from table_special_offer
where FK_ID_period IN(list of all the ids selected in the 2)
您可能认为第 3 点中的 IN 子句可能非常大(例如 75 000 大),所以我有很多机会获得超时或类似“已达到表达式服务限制”的内容.
你有没有遇到过这样的事情,你是怎么避免的?
PS: 上下文:SQL server 2005,.net 2.0 (请不要告诉我我的设计不好,或者我不应该做“选择*”,我只是简化了我的问题,所以它比描述我的业务的 500 页简单一点)。
谢谢。
【问题讨论】:
标签: sql sql-server optimization