Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Partitioned views and query compile time.


Partitioned views and query compile time.

Author
Message
blernsball
blernsball
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 84
So I've inherited a SQL Server 2005 DB with a whole bunch of tables in the following format:

rank_xxxx, where xxxx is a date identifier.
ex:
rank_3425
rank_3426
etc.

Then they have stored procedures that use dynamic SQL to generate queries that will access the correct "partition". It's an awful mess.

Because I can't change the tables, I thought that a quick way to gain some performance improvements would be to create a partitioned view of these tables. In that way we could simplify the queries and speed things up.

Starting issues:
1. There isn't a useful partitioning key available in these tables...
2. There are a lot of these rank_xxxx tables. And there is that 256 table limit...

What I did was create some subviews in this format:

CREATE VIEW
[dbo].[vw_rank_all_part_1]
AS
SELECT 1 as period, * FROM dbo.rank_3425
UNION ALL
SELECT 2 as period, * FROM dbo.rank_3426
....


So period is set up to be the partition key.

And then I create a master view like this:

CREATE VIEW
[dbo].[vw_rank_all]
AS
SELECT * FROM vw_rank_all_part_1
UNION ALL
SELECT * FROM vw_rank_all_part_2
...



This seems to work. Sort of.

If I query the vw_rank_all table and provide period as a static value like so:

SELECT
count(*)
FROM
dbo.vw_rank_all
where
period = 400


And then check my plan, I can see that partition elimination is working. It finds the base table and only looks at that one. So far so good.

The problem occurs when I drop the view into the stored procedure:

CREATE PROCEDURE [dbo].[a_test_rankpartitoning]
@period int
AS
BEGIN

SELECT
top 100
*
FROM
dbo.vw_rank_all
where
period = @period
END


The plan looks ok, and partition elimination is happening.
But.
The compile time on first run is massive compared to the execution time. In the above SP it's not a huge amount, but when I use the view in a more complicated SP it drives the compile time through the roof (resulting in a total time of 50s on first run and then 2s on subsequent runs).

Any idea why this is happening? Is it just a side affect of using partitioned views? Is it because of my partitioning key? Any way to avoid this?

Thanks in advance for any comments.
blernsball
blernsball
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 84
nobody has come across this before?
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