SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sql partiton view


sql partiton view

Author
Message
sharon-472085
sharon-472085
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 804
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 ? Smile )

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
Mansfield
Mansfield
SSC-Addicted
SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)

Group: General Forum Members
Points: 424 Visits: 394
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.
sharon-472085
sharon-472085
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 804
thanks you for you your answer
how can i mark your answer as a good one
thanks sharon
Mansfield
Mansfield
SSC-Addicted
SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)

Group: General Forum Members
Points: 424 Visits: 394
You're welcome.

These forums don't have a "mark as answer" facility, however ask.sqlservercentral.com does :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search