I need to optimize the following query (table group_attributes) got columns group_id, attribute_id and int_value.
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)
that group_attributes is a huge table and the query takes forever.
I am not so much of expert in SQL so I wonder which query would work faster? It seems that in general these IN queries are damn slow.
Best, Askar
Solution – I
I think you can improve the performance by creating following indexes.
Solution – II
You can also insert all int_values into a temp table and then create the non_clustered index on temp table. Also create non clustered index on int_value of main table.