473,721 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_per iod datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3436
DEFAULT 1
CONSTRAINT Binary_flag_rul e667
CHECK (authority_flag IN
(0, 1)),
interpolated_fl ag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT692 6
DEFAULT 0
CONSTRAINT Binary_flag_rul e668
CHECK (interpolated_f lag IN
(0, 1)),
observation_val ue decimal_datatyp e NOT NULL,
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DE FAULT1807
DEFAULT getdate(),
CONSTRAINT XPKcs_working_e 2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_per iod)
--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_per iod ASC,
reference_year ASC,
observation_val ue ASC
)
go

CREATE INDEX XIE1cs_working_ e2 ON dbo.cs_working_ e2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_per iod ASC,
reference_year ASC,
observation_val ue 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_inde xes14
CHECK (formula_id between
7001 and 9000),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_per iod datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3437
DEFAULT 1
CONSTRAINT Binary_flag_rul e669
CHECK (authority_flag IN
(0, 1)),
observation_val ue decimal_datatyp e NOT NULL,
interpolated_fl ag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT692 7
DEFAULT 0
CONSTRAINT Binary_flag_rul e670
CHECK (interpolated_f lag IN
(0, 1)),
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DE FAULT1808
DEFAULT getdate(),
CONSTRAINT XPKcs_working_i ndexes2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_per iod)
--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_per iod ASC,
reference_year ASC,
observation_val ue ASC
)
go

CREATE INDEX XIE1cs_working_ indexes2 ON dbo.cs_working_ indexes2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_per iod ASC,
reference_year ASC,
observation_val ue 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_othe r14
CHECK (formula_id >= 9001),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_per iod datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3438
DEFAULT 1
CONSTRAINT Binary_flag_rul e671
CHECK (authority_flag IN
(0, 1)),
observation_val ue decimal_datatyp e NOT NULL,
interpolated_fl ag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT692 8
DEFAULT 0
CONSTRAINT Binary_flag_rul e672
CHECK (interpolated_f lag IN
(0, 1)),
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DE FAULT1809
DEFAULT getdate(),
CONSTRAINT XPKcs_working_o ther2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_per iod)
--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_per iod ASC,
reference_year ASC,
observation_val ue ASC
)
go

CREATE INDEX XIE1cs_working_ other2 ON dbo.cs_working_ other2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_per iod ASC,
reference_year ASC,
observation_val ue 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_p1q1 14
CHECK (formula_id between
3001 and 7000),
submission_id int NOT NULL,
node_id int NOT NULL,
reference_year smallint NOT NULL,
observation_per iod datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3439
DEFAULT 1
CONSTRAINT Binary_flag_rul e673
CHECK (authority_flag IN
(0, 1)),
interpolated_fl ag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT692 9
DEFAULT 0
CONSTRAINT Binary_flag_rul e674
CHECK (interpolated_f lag IN
(0, 1)),
observation_val ue decimal_datatyp e NOT NULL,
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DE FAULT1810
DEFAULT getdate(),
CONSTRAINT XPKcs_working_p 1q12
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_per iod)
--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_per iod ASC,
reference_year ASC,
observation_val ue ASC
)
go

CREATE INDEX XIE1cs_working_ p1q12 ON dbo.cs_working_ p1q12
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_per iod ASC,
reference_year ASC,
observation_val ue 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_per iod datetime NOT NULL,
authority_flag tinyint NOT NULL
CONSTRAINT ONE_DEFAULT3440
DEFAULT 1
CONSTRAINT Binary_flag_rul e675
CHECK (authority_flag IN
(0, 1)),
interpolated_fl ag tinyint NOT NULL
CONSTRAINT ZERO_DEFAULT693 0
DEFAULT 0
CONSTRAINT Binary_flag_rul e676
CHECK (interpolated_f lag IN
(0, 1)),
observation_val ue decimal_datatyp e NOT NULL,
time_created smalldatetime NOT NULL
CONSTRAINT
CURRENT_DATE_DE FAULT1811
DEFAULT getdate(),
CONSTRAINT XPKcs_working_p q2
PRIMARY KEY NONCLUSTERED (formula_id, submission_id,
node_id, reference_year, observation_per iod)
--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_per iod ASC,
reference_year ASC,
observation_val ue ASC
)
go

CREATE INDEX XIE1cs_working_ pq2 ON dbo.cs_working_ pq2
(
node_id ASC,
authority_flag ASC,
formula_id ASC,
observation_per iod ASC,
reference_year ASC,
observation_val ue ASC
)
--ON "INDEXES"
go
----- create view ---------
drop view cs_working2
go
CREATE VIEW cs_working2 (submission_id, node_id, reference_year,
observation_per iod, formula_id, observation_val ue, interpolated_fl ag,
time_created, authority_flag) AS
SELECT we.submission_i d, we.node_id, we.reference_ye ar,
we.observation_ period, we.formula_id, we.observation_ value,
we.interpolated _flag, we.time_created , we.authority_fl ag
FROM cs_working_e2 we
union all
SELECT wo.submission_i d, wo.node_id, wo.reference_ye ar,
wo.observation_ period, wo.formula_id, wo.observation_ value,
wo.interpolated _flag, wo.time_created , wo.authority_fl ag
FROM cs_working_othe r2 wo
union all
SELECT wpq.submission_ id, wpq.node_id, wpq.reference_y ear,
wpq.observation _period, wpq.formula_id, wpq.observation _value,
wpq.interpolate d_flag, wpq.time_create d, wpq.authority_f lag
FROM cs_working_pq2 wpq
union all
SELECT wp1q1.submissio n_id, wp1q1.node_id, wp1q1.reference _year,
wp1q1.observati on_period, wp1q1.formula_i d, wp1q1.observati on_value,
wp1q1.interpola ted_flag, wp1q1.time_crea ted, wp1q1.authority _flag
FROM cs_working_p1q1 2 wp1q1
union all
SELECT wi.submission_i d, wi.node_id, wi.reference_ye ar,
wi.observation_ period, wi.formula_id, wi.observation_ value,
wi.interpolated _flag, wi.time_created , wi.authority_fl ag
FROM cs_working_inde xes2 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_val ue is not null
*/
Jul 20 '05 #1
1 3233
[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
2427
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 need to keep at least two year's worth of data at all times, but after two years I can archive the data. A sample of the code used is below. It is simplified for space reasons. My question is, how do other people maintain the database in this type
0
2425
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, Swedish or English). There are about a dozen tables with columns that need localization. Doing this in the application level was a no-goer. It would have taken far too much time (there is a *lot* of code and unfortunately most of the...
3
3806
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 month. Each month a stored procedure is scheduled that creates the new month's table, and alters the view to include it. Again... working like a charm for quite some time. This past weekend I moved some of the first tables onto a new file...
4
3500
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 view can hold? If this is true, does anybody have any suggestions or ideas to work around this max limit? TIA!
6
6906
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, segmented and partitioned) tablespaces. What is segmented tablespace ? Is it possible to span the the tables within multiple containers (but in some ordered manner) with no db partitions ?
11
1888
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 spread over 10 partitions. Approximately 35% of the data is "inactive" (easily identifiable as such) and of limited (but some) use. We require 2 non-partitioning indexes on the data. The DBA group would like us to put the "inactive" data into a...
1
4054
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 N'\\server\Backups\DBServerName\\DB_Name__MSCRM'
0
1670
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. Not that I care too much now about it :-) But what will happen when once upon a time in the future I execute the "attach partition" command, and so add another partition to the existing (partitioned) table. Will the indexes then be automatically...
2
13615
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 partitions and this is where I hit the wall the 2nd time. As per my study there are 3 types of indexed partitions: Global index (which is on an entire partitioned table) then there is Local Index (on just the partition of the table) and then there...
0
8834
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8727
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9365
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9127
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9056
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4483
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4748
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3186
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.