我需要优化以下查询(表group_attributes
)得到列group_id
,attribute_id
和int_value
。带IN子句的SQL Server语句:如何使它们更快?
select group_id
from group_attributes
where attribute_id= 1049
and int_value in (1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255,
1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264,
1265, 1266, 1267, 1268, 1269, 1270, 1271)
即group_attributes
是一个巨大的表和查询需要永远。
我不是那么熟悉SQL,所以我想知道哪个查询会更快?看起来总的来说这些IN
查询是该死的慢。
最佳阿斯卡尔
你在桌上有什么指标?你能展示执行计划吗? – 2012-07-31 11:16:35
我想''(attribute_id,int_value,group_id)'上的索引将是有效的。 – 2012-07-31 11:17:37
可能只是“样式”的问题,但在您的特殊查询中,您可以使用“int_value BETWEEN 1247 AND 1271”。 – Marco 2012-07-31 11:18:24