April 23, 2013 at 2:37 am
hi,
i build view that contain lat say 10 table, each table contain check constraint on column name origtime
type datetime , after create the partiton view i build quary to test it so:
SELECT * FROM partition_view
WHERE A=5 AND origTIME = '2012-01-01'
in this case sql engine work perfectly :
it look of data i looking for of a specific one table from all tables in view.
the probloem start here :
DECLARE @NEW_DATA DATETIME
SET @NEW_DATA='2012-01-01'
SELECT * FROM partition_view
WHERE A=5 AND origTIME = @NEW_DATA DATETIME
this is the way i plan to search in this table in my procedure in db (it very logic no ? 🙂 )
after i check it in sql plan the behavior of sql wes strange:
sql loop over all tables in the partiton view the quaesition is why ? (every table have index so still was fast but this is not the point )
and how can avoid this?
thank alot sharon
April 23, 2013 at 3:08 pm
This is because on the first query you have hard coded the date as a constant, then using available table statistics, the optimiser shortcuts the execution plan so that it only looks at the single underlying table.
However if the date is parameterised then the optimiser doesn't know which date value to use when compiling the execution plan. So the query will need to look through all the tables to ensure that the returned results are correct.
April 25, 2013 at 2:10 am
thanks you for you your answer
how can i mark your answer as a good one
thanks sharon
April 25, 2013 at 2:31 pm
You're welcome.
These forums don't have a "mark as answer" facility, however ask.sqlservercentral.com does 🙂
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply