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 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2007-06-18 : 14:05:47
|
I thought I new this, but all I get is index scan..not the seek operation and parallelism I'm looking for...there is no data in the table, but I thought that wouldn't matterUSE NorthwindGOCREATE TABLE myTable99_1 ( Account char(3) , Ledger char(4) , PostDate datetime , PRIMARY KEY (Account, Ledger) , CHECK(PostDate> '1/1/1999' and PostDate < '12/31/1999 23:59:59'))CREATE TABLE myTable99_2 ( Account char(3) , Ledger char(4) , PostDate datetime , PRIMARY KEY (Account, Ledger) , CHECK(PostDate> '1/1/2000' and PostDate < '12/31/2000 23:59:59'))CREATE TABLE myTable99_3 ( Account char(3) , Ledger char(4) , PostDate datetime , PRIMARY KEY (Account, Ledger) , CHECK(PostDate> '1/1/2001' and PostDate < '12/31/2001 23:59:59'))CREATE INDEX myTable99_1_IX ON MyTable99_1 (Account, Ledger)CREATE INDEX myTable99_2_IX ON MyTable99_2 (Account, Ledger)CREATE INDEX myTable99_3_IX ON MyTable99_3 (Account, Ledger)GOCREATE VIEW myView99ASSELECT Account , Ledger , PostDate FROM myTable99_1UNION ALLSELECT Account , Ledger , PostDate FROM myTable99_2UNION ALLSELECT Account , Ledger , PostDate FROM myTable99_3GOSELECT * FROM myView99 WHERE Account = 1 AND Ledger = 1GODROP VIEW myView99DROP TABLE myTable99_1, myTable99_2, myTable99_3GO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-06-18 : 14:18:29
|
| Data in a table definitely matters when SQL Server picks the execution plan. I'm not sure what the magic number is, but they say somewhere around 1000-10000 rows are needed in a table before SQL Server will stop scanning. Scanning apparently is the cheapest way to read a table when there's not much data in it.Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2007-06-18 : 14:25:42
|
| Yeah, tha would be true in DB2 as well...But...I do thisINSERT INTO myView99 (Account, Ledger, PostDate)SELECT 1,1,'1/1/1999'and get thisServer: Msg 4436, Level 16, State 12, Line 1UNION ALL view 'myView99' is not updatable because a partitioning column was not found.So I guess the contraint isn't correct...does the contraint have to be on the primary Key?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-06-18 : 14:30:45
|
There are a lot of requirements when creating a partitioned view. I'm going to refer you to BOL for them.Here's a quote though:quote: To perform updates on a partitioned view, the partitioning column must be a part of the primary key of the base table.
Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-06-19 : 03:23:33
|
"all I get is index scan..not the seek operation and parallelism I'm looking for ...... WHERE Account = 1 AND Ledger = 1"You'll need to query based on [PostDate] to get a Filter in the Query Plan ..."INSERT INTO myView99 (Account, Ledger, PostDate)SELECT 1,1,'1/1/1999'"That, as luck would have it!!!, is outside the CHECK constraint.CHECK(PostDate > '1/1/1999' and ... "There are a lot of requirements when creating a partitioned view"In case it is helpful there is a precis here:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Requirements%20for%20Horizontal%20PartitionsKristen |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-06-19 : 15:17:33
|
Partitioned Views are "funky" to say the least. I've seem all kinds of wierdness with with. At any rate, here is a link for you to check out: [url]http://msdn2.microsoft.com/en-us/library/aa933141(SQL.80).aspx[/url] Here is a snippet:quote: Table RulesMember tables are defined in the FROM clause in each SELECT statement in the view definition. Each member table must adhere to these rules: - Member tables cannot be referenced more than once in the view. - Member tables cannot have indexes created on any computed columns. - Member tables must have all PRIMARY KEY constraints on an identical number of columns. - Member tables must have the same ANSI padding setting. For more information about the ANSI padding setting, see SET ANSI_PADDING. Column RulesColumns are defined in the select list of each SELECT statement in the view definition. The columns must follow these rules. - All columns in each member table must be included in the select list. SELECT * FROM <member table> is acceptable syntax. - Columns cannot be referenced more than once in the select list. - The columns must be in the same ordinal position in the select list - The columns in the select list of each SELECT statement must be of the same type (including data type, precision, scale, and collation). For example, this view definition fails because the first column in both SELECT statements does not have the same data type:CREATE VIEW NonUpdatableASSELECT IntPrimaryKey, IntPartNmbrFROM FirstTable UNION ALLSELECT NumericPrimaryKey, IntPartNmbrFROM SecondTable Partitioning Column RulesA partitioning column exists on each member table and, through CHECK constraints, identifies the data available in that specific table. Partitioning columns must adhere to these rules: - Each base table has a partitioning column whose key values are enforced by CHECK constraints. The key ranges of the CHECK constraints in each table do not overlap with the ranges of any other table. Any given value of the partitioning column must map to only one table. The CHECK constraints can only use these operators: BETWEEN, AND, OR, <, <=, >, >=, =. - The partitioning column cannot be an identity, default or timestamp column. - The partitioning column must be in the same ordinal location in the select list of each SELECT statement in the view. For example, the partitioning column is always the first column in each select list, or the second column in each select list, and so on. - Partitioning columns cannot allow nulls. - Partitioning columns must be a part of the primary key of the table. - Partitioning columns cannot be computed columns. - There must be only one constraint on the partitioning column. If there is more than one constraint, SQL Server ignores all the constraints and will not consider them when determining whether or not the view is a partitioned view. - There are no restrictions on the updatability of the partitioning columns.
Cheers,-Ryan |
 |
|
|
|
|
|
|
|