473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems with partitioned views and pruning

SM
/*
problem: Trying to get partitioned views to "prune" unneeded
partitions from
select statements against the partitioned view. There are 5
partitioned
tables. Each with a check constraint based on a range of formula_id
column.

Test: Run this script to create the 5 partitioned tables and the
partitioned view. Then
run the explain plans on the select statements at the end of the
script and see that we
can only prune if we give a seemingly superfluous is not null
criteria in addition to
the formula_id.

Ideal: We want to only have to use the formula_id in the select
statement to prune.
*/

/*note: you may get errors on the drops first time run*/
drop table dbo.cs_working_e2
go
CREATE TABLE dbo.cs_working_e2 (
formula_id int NOT NULL
CONSTRAINT formula_id_e14
CHECK (formula_id between 1
and 1000),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_period datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3436
DEFAULT 1
CONSTRAINT Binary_flag_rule667
CHECK (authority_flag IN
(0, 1)),
interpolated_flag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT6926
DEFAULT 0
CONSTRAINT Binary_flag_rule668
CHECK (interpolated_flag IN
(0, 1)),
observation_value decimal_datatype NOT NULL,
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DEFAULT1807
DEFAULT getdate(),
CONSTRAINT XPKcs_working_e2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_period)
--ON "INDEXES"
)
--ON "WORKING"
go
CREATE UNIQUE CLUSTERED INDEX XAK1cs_working_e2 ON dbo.cs_working_e2
(
submission_id ASC,
formula_id ASC,
node_id ASC,
authority_flag ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
go

CREATE INDEX XIE1cs_working_e2 ON dbo.cs_working_e2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
--ON "INDEXES"
go
drop table dbo.cs_working_indexes2
go
CREATE TABLE dbo.cs_working_indexes2 (
formula_id int NOT NULL
CONSTRAINT formula_id_indexes14
CHECK (formula_id between
7001 and 9000),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_period datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3437
DEFAULT 1
CONSTRAINT Binary_flag_rule669
CHECK (authority_flag IN
(0, 1)),
observation_value decimal_datatype NOT NULL,
interpolated_flag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT6927
DEFAULT 0
CONSTRAINT Binary_flag_rule670
CHECK (interpolated_flag IN
(0, 1)),
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DEFAULT1808
DEFAULT getdate(),
CONSTRAINT XPKcs_working_indexes2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_period)
--ON "INDEXES"
)
--ON "WORKING"
go

CREATE UNIQUE CLUSTERED INDEX XAK1cs_working_indexes2 ON
dbo.cs_working_indexes2
(
submission_id ASC,
formula_id ASC,
node_id ASC,
authority_flag ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
go

CREATE INDEX XIE1cs_working_indexes2 ON dbo.cs_working_indexes2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
--ON "INDEXES"
go

drop table dbo.cs_working_other2
go
CREATE TABLE dbo.cs_working_other2 (
formula_id int NOT NULL
CONSTRAINT formula_id_other14
CHECK (formula_id >= 9001),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_period datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3438
DEFAULT 1
CONSTRAINT Binary_flag_rule671
CHECK (authority_flag IN
(0, 1)),
observation_value decimal_datatype NOT NULL,
interpolated_flag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT6928
DEFAULT 0
CONSTRAINT Binary_flag_rule672
CHECK (interpolated_flag IN
(0, 1)),
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DEFAULT1809
DEFAULT getdate(),
CONSTRAINT XPKcs_working_other2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_period)
--ON "INDEXES"
)
--ON "WORKING"
go

CREATE UNIQUE CLUSTERED INDEX XAK1cs_working_other2 ON
dbo.cs_working_other2
(
submission_id ASC,
formula_id ASC,
node_id ASC,
authority_flag ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
go

CREATE INDEX XIE1cs_working_other2 ON dbo.cs_working_other2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
--ON "INDEXES"
go

drop table dbo.cs_working_p1q12
go
CREATE TABLE dbo.cs_working_p1q12 (
formula_id int NOT NULL
CONSTRAINT formula_id_p1q114
CHECK (formula_id between
3001 and 7000),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_period datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3439
DEFAULT 1
CONSTRAINT Binary_flag_rule673
CHECK (authority_flag IN
(0, 1)),
interpolated_flag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT6929
DEFAULT 0
CONSTRAINT Binary_flag_rule674
CHECK (interpolated_flag IN
(0, 1)),
observation_value decimal_datatype NOT NULL,
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DEFAULT1810
DEFAULT getdate(),
CONSTRAINT XPKcs_working_p1q12
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_period)
--ON "INDEXES"
)
--ON "WORKING"
go

CREATE UNIQUE CLUSTERED INDEX XAK1cs_working_p1q12 ON
dbo.cs_working_p1q12
(
submission_id ASC,
formula_id ASC,
node_id ASC,
authority_flag ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
go

CREATE INDEX XIE1cs_working_p1q12 ON dbo.cs_working_p1q12
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
--ON "INDEXES"
go

drop table dbo.cs_working_pq2
go
CREATE TABLE dbo.cs_working_pq2 (
formula_id int NOT NULL
CONSTRAINT formula_id_pq14
CHECK (formula_id between
1001 and 3000),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_period datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3440
DEFAULT 1
CONSTRAINT Binary_flag_rule675
CHECK (authority_flag IN
(0, 1)),
interpolated_flag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT6930
DEFAULT 0
CONSTRAINT Binary_flag_rule676
CHECK (interpolated_flag IN
(0, 1)),
observation_value decimal_datatype NOT NULL,
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DEFAULT1811
DEFAULT getdate(),
CONSTRAINT XPKcs_working_pq2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_period)
--ON "INDEXES"
)
--ON "WORKING"
go

CREATE UNIQUE CLUSTERED INDEX XAK1cs_working_pq2 ON
dbo.cs_working_pq2
(
submission_id ASC,
formula_id ASC,
node_id ASC,
authority_flag ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
go

CREATE INDEX XIE1cs_working_pq2 ON dbo.cs_working_pq2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_period ASC,
reference_year ASC,
observation_value ASC
)
--ON "INDEXES"
go
----- create view ---------
drop view cs_working2
go
CREATE VIEW cs_working2 (submission_id, node_id, reference_year,
observation_period, formula_id, observation_value, interpolated_flag,
time_created, authority_flag) AS
SELECT we.submission_id, we.node_id, we.reference_year,
we.observation_period, we.formula_id, we.observation_value,
we.interpolated_flag, we.time_created, we.authority_flag
FROM cs_working_e2 we
union all
SELECT wo.submission_id, wo.node_id, wo.reference_year,
wo.observation_period, wo.formula_id, wo.observation_value,
wo.interpolated_flag, wo.time_created, wo.authority_flag
FROM cs_working_other2 wo
union all
SELECT wpq.submission_id, wpq.node_id, wpq.reference_year,
wpq.observation_period, wpq.formula_id, wpq.observation_value,
wpq.interpolated_flag, wpq.time_created, wpq.authority_flag
FROM cs_working_pq2 wpq
union all
SELECT wp1q1.submission_id, wp1q1.node_id, wp1q1.reference_year,
wp1q1.observation_period, wp1q1.formula_id, wp1q1.observation_value,
wp1q1.interpolated_flag, wp1q1.time_created, wp1q1.authority_flag
FROM cs_working_p1q12 wp1q1
union all
SELECT wi.submission_id, wi.node_id, wi.reference_year,
wi.observation_period, wi.formula_id, wi.observation_value,
wi.interpolated_flag, wi.time_created, wi.authority_flag
FROM cs_working_indexes2 wi
go

--- sample selects against partitioned view -----
/*
--run explain plan here and see all 5 partitions being pulled
select * from cs_working

--run explain plan here and see just the 1 partition
select * from cs_working_e2

--run explain plan and see this is not pruning to the needed partition
select * from cs_working
where formula_id = 1

--run explain plan and see it is now pruning to the needed partition
select * from cs_working
where formula_id = 1
and submission_id is not null

--run explain plan and see it is now pruning to the needed partition,
too
select * from cs_working
where formula_id = 1
and observation_value is not null
*/
Jul 20 '05 #1
1 3206
[posted and mailed, please reply in news]

SM (mu************@hotmail.com) writes:
problem: Trying to get partitioned views to "prune" unneeded partitions
from select statements against the partitioned view. There are 5
partitioned tables. Each with a check constraint based on a range of
formula_id column.

Test: Run this script to create the 5 partitioned tables and the
partitioned view. Then run the explain plans on the select statements at
the end of the script and see that we can only prune if we give a
seemingly superfluous is not null criteria in addition to the
formula_id.


I looked this, and indeed the behaviour is surprising. However, it is
benign. If you look closer at the plans, you see that there is a filter
which includes a STARTUP EXPR. What this is all about is that before
doing anyhing else, SQL Server filters on the partitoning column.

If you populate the table with some data, and run a query with
SET STATISTICS IO ON, you will something like this:

Table 'c'. Scan count 1, logical reads 2, physical reads 0, read-ahead
reads 0.
Table 'b'. Scan count 0, logical reads 0, physical reads 0, read-ahead
reads 0.
Table 'a'. Scan count 0, logical reads 0, physical reads 0, read-ahead
reads 0.

Thus, only one of the table is accessed.

So while it may not seem so at first glance, you do actually achieve
your goal of partitioning the column.

It seems that this happens because there more than column in the primary
key of the tables.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Thomas R. Hummel | last post by:
Hello, I have a large set of data that I have set up as a partitioned view. The view is partitioned by a datetime column and the individual tables each represent one month's worth of data. I...
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
3
by: Thomas R. Hummel | last post by:
I am using SQL Server 2000, SP3. I created an updatable partitioned view awhile ago and it has been running smoothly for some time. The partition is on a DATETIME column and it is partitioned by...
4
by: karthik | last post by:
I have a partitioned view sitting over several tables and I'm slowly approaching the 256 number. Can anybody confirm if there is such a limit for the maximum number of tables that a partitioned...
6
by: Smutny30 | last post by:
Hello, I consider partitioning a huge table. I am not sure wheather it is possioble only in partitioned databases. I found somewhere in docs ( http://tinyurl.com/4oara ) that there are (simple,...
11
by: steve.keanie | last post by:
Hi ... we're a mainframe V7 shop planning an imminent upgrade to V8. My application team is converting an IMS DB into a DB/2 table ... approximately 40GB of uncompressed (~20 GB compressed) data...
1
by: Bryan | last post by:
We have a SQL 2005 server running the following backup job: EXECUTE master.dbo.xp_create_subdir N'\\Server\Backups\DBServerName\\DB_Name__METABASE' GO EXECUTE master.dbo.xp_create_subdir...
0
by: Damir | last post by:
Hello all! I created a range-partitioned table, and noticed that indexes were created as "NOT PARTITIONED" (through db2look), even though I ran the index creating commands without this parameter....
2
by: eeriehunk | last post by:
Hi All, Is it possible to create a partitioned index on a table which is not partitioned? If so what is such a partition called and please explain? I have done some research on partitions and index...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.