Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-08-25 : 09:17:42
|
Hi all, To improve the performance, I splitted the single heavy table in my db into two new tables and created a partitioned view on it. Following is an oversimplified example:create table test_1( a int primary key check ( a between 1 and 10))GOcreate table test_2( a int primary key check ( a between 11 and 20))GOinsert into test_1select 1 union allselect 2 union allselect 3 union allselect 4 union allselect 5 union allselect 6 union allselect 7 union allselect 8 union allselect 9 union allselect 10insert into test_2select 11 union allselect 12 union allselect 13 union allselect 14 union allselect 15 union allselect 16 union allselect 17 union allselect 18 union allselect 19 union allselect 20GOcreate view vw_testasselect * from test_1union allselect * from test_2Goselect * from vw_test where a between 1 and 5 When I execute the above query and see the execution plan, I see that both the tables are seen as a part of execution plan even though my WHERE clause is satisfied only by the first table, what is the reason behind this?This does not happens when I use = or IN operators !Can anybody please explain this behavior?Thanks.Harsh AthalyeIndia."Nothing is Impossible" |
|
|
hrishi_des
Yak Posting Veteran
76 Posts |
Posted - 2006-10-10 : 01:36:10
|
Hi Harsh,Always Use SET STATISTICS IO ON to verify which tables are being accessed and not rely on Execution plan.I tried that example it shows it is accessing proper table.thanks,Hrishikeshquote: Originally posted by harsh_athalye Hi all, To improve the performance, I splitted the single heavy table in my db into two new tables and created a partitioned view on it. Following is an oversimplified example:create table test_1( a int primary key check ( a between 1 and 10))GOcreate table test_2( a int primary key check ( a between 11 and 20))GOinsert into test_1select 1 union allselect 2 union allselect 3 union allselect 4 union allselect 5 union allselect 6 union allselect 7 union allselect 8 union allselect 9 union allselect 10insert into test_2select 11 union allselect 12 union allselect 13 union allselect 14 union allselect 15 union allselect 16 union allselect 17 union allselect 18 union allselect 19 union allselect 20GOcreate view vw_testasselect * from test_1union allselect * from test_2Goselect * from vw_test where a between 1 and 5 When I execute the above query and see the execution plan, I see that both the tables are seen as a part of execution plan even though my WHERE clause is satisfied only by the first table, what is the reason behind this?This does not happens when I use = or IN operators !Can anybody please explain this behavior?Thanks.Harsh AthalyeIndia."Nothing is Impossible"
|
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-10-10 : 14:54:54
|
| FYI, I have seen big differences between 2005 and 2000, on how they handle partitioned views.I have seen the same as Harsh on 2000,but the same data + same query on 2005 efficiently eliminates unwanted tables from the actual execution plan.rockmoose |
 |
|
|
Kristen
Test
22859 Posts |
|
|
hrishi_des
Yak Posting Veteran
76 Posts |
Posted - 2006-11-14 : 02:03:38
|
| yea i second rockmoose's opinion even i have seen different behaviour... it works ok. if primary key is absent in 2005!!!! |
 |
|
|
|
|
|
|
|