Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sql partiton view Expand / Collapse
Author
Message
Posted Tuesday, April 23, 2013 2:37 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 17, 2014 2:22 AM
Points: 28, Visits: 540
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


Post #1445314
Posted Tuesday, April 23, 2013 3:08 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 2:20 PM
Points: 364, Visits: 384
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.
Post #1445692
Posted Thursday, April 25, 2013 2:10 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 17, 2014 2:22 AM
Points: 28, Visits: 540
thanks you for you your answer
how can i mark your answer as a good one
thanks sharon
Post #1446338
Posted Thursday, April 25, 2013 2:31 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 2:20 PM
Points: 364, Visits: 384
You're welcome.

These forums don't have a "mark as answer" facility, however ask.sqlservercentral.com does
Post #1446717
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse