I’m having trouble trying to optimize the following query for sql server 2005. Does anyone know how could I improve it. Each one of the tables used there have about 40 million rows each. I’ve tried my best trying to optimize it but I manage to do the exact opposite.
Thanks
SELECT cos , SIN FROM ConSisHis2005 union all SELECT cos , SIN FROM ConSisHis2006 union all SELECT cos , SIN FROM ConSisHis2007 UNION ALL SELECT cos , SIN FROM ConSisHis2008
Maybe I should have said something else about the schema, all the tables used here are historical tables, they are not referenced to any other table. And theres already an index for cos and SIN. I was just wondering if there was any other way to optimize the query… as you can imagine 160millon records are hard to get :s
It seems that the query is just combining the separated history tables into a single result set containing all the data. In that case the query is already optimal.