Partitioned view optimized incorrectly

Partitioned view optimized incorrectly

Post by Seth » Thu, 13 Mar 2003 17:56:32



The query optimizer fails to recognize partitioning function involving
modulus function. For example a partitioned view over tables partitioned as
follows is not optimized correctly:

CREATE TABLE Table_0 (
 ID int NOT NULL CHECK (ID%10 = 0),
 FirstName varchar (60) NOT NULL ,
 LastName varchar (60) NOT NULL ,
 GenderID tinyint NOT NULL ,
 CONSTRAINT xPKTable_0 PRIMARY KEY  CLUSTERED (ID)
)

But does work correctly with this

CREATE TABLE Table_0 (
 ID int NOT NULL CHECK (ID between 0 and 10000),
 FirstName varchar (60) NOT NULL ,
 LastName varchar (60) NOT NULL ,
 GenderID tinyint NOT NULL ,
 CONSTRAINT xPKTable_0 PRIMARY KEY  CLUSTERED (ID)
)

When the partitioned view is build over tables using the modulus function,
the optimizer will access each table in the view to satisfy a SELECT query
(select * from Table_View where ID = 25). When the view is built over the
BETWEEN comparison, the optimizer will only reference the relevant table.
This can be seen by setting statistics io on.

Is this a bug? I see nothing in BOL that indicates that the first check
constraint should not work. Is there a way to make this work? Having a
dynamic partitioning function is much more flexible that hard-coded ranges.
All the examples I have seen have been hard-coded, typically to a date
range.

Thanks,
Seth

 
 
 

Partitioned view optimized incorrectly

Post by Chri » Fri, 14 Mar 2003 21:03:28


It's not a bug, see below (from books on-line):

Partitioning Column Rules
A 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, <, <=, >, >=, =.

Quote:>-----Original Message-----
>The query optimizer fails to recognize partitioning
function involving
>modulus function. For example a partitioned view over

tables partitioned as
Quote:>follows is not optimized correctly:

>CREATE TABLE Table_0 (
> ID int NOT NULL CHECK (ID%10 = 0),
> FirstName varchar (60) NOT NULL ,
> LastName varchar (60) NOT NULL ,
> GenderID tinyint NOT NULL ,
> CONSTRAINT xPKTable_0 PRIMARY KEY  CLUSTERED (ID)
>)

>But does work correctly with this

>CREATE TABLE Table_0 (
> ID int NOT NULL CHECK (ID between 0 and 10000),
> FirstName varchar (60) NOT NULL ,
> LastName varchar (60) NOT NULL ,
> GenderID tinyint NOT NULL ,
> CONSTRAINT xPKTable_0 PRIMARY KEY  CLUSTERED (ID)
>)

>When the partitioned view is build over tables using the
modulus function,
>the optimizer will access each table in the view to

satisfy a SELECT query

- Show quoted text -

Quote:>(select * from Table_View where ID = 25). When the view
is built over the
>BETWEEN comparison, the optimizer will only reference the
relevant table.
>This can be seen by setting statistics io on.

>Is this a bug? I see nothing in BOL that indicates that
the first check
>constraint should not work. Is there a way to make this
work? Having a
>dynamic partitioning function is much more flexible that
hard-coded ranges.
>All the examples I have seen have been hard-coded,
typically to a date
>range.

>Thanks,
>Seth

>.


 
 
 

Partitioned view optimized incorrectly

Post by Seth » Fri, 14 Mar 2003 22:02:24


I did read the restrictions. But I am using the = operator, which is
permitted. Also, BOL has examples using dates with the datepart function. So
what would be different about using the modulus function with an integer?

I used CHECK (ID%10 = 0)
BOL shows CHECK (DATEPART(yy, OrderDate) = 1998)

Why should the query optimizer recognize the partitioning scheme on the
latter but not the former?

Thanks,
Seth
=======================================


It's not a bug, see below (from books on-line):

Partitioning Column Rules
A 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, <, <=, >, >=, =.

Quote:>-----Original Message-----
>The query optimizer fails to recognize partitioning
function involving
>modulus function. For example a partitioned view over

tables partitioned as
Quote:>follows is not optimized correctly:

>CREATE TABLE Table_0 (
> ID int NOT NULL CHECK (ID%10 = 0),
> FirstName varchar (60) NOT NULL ,
> LastName varchar (60) NOT NULL ,
> GenderID tinyint NOT NULL ,
> CONSTRAINT xPKTable_0 PRIMARY KEY  CLUSTERED (ID)
>)

>But does work correctly with this

>CREATE TABLE Table_0 (
> ID int NOT NULL CHECK (ID between 0 and 10000),
> FirstName varchar (60) NOT NULL ,
> LastName varchar (60) NOT NULL ,
> GenderID tinyint NOT NULL ,
> CONSTRAINT xPKTable_0 PRIMARY KEY  CLUSTERED (ID)
>)

>When the partitioned view is build over tables using the
modulus function,
>the optimizer will access each table in the view to

satisfy a SELECT query

- Show quoted text -

Quote:>(select * from Table_View where ID = 25). When the view
is built over the
>BETWEEN comparison, the optimizer will only reference the
relevant table.
>This can be seen by setting statistics io on.

>Is this a bug? I see nothing in BOL that indicates that
the first check
>constraint should not work. Is there a way to make this
work? Having a
>dynamic partitioning function is much more flexible that
hard-coded ranges.
>All the examples I have seen have been hard-coded,
typically to a date
>range.

>Thanks,
>Seth

>.

 
 
 

1. Optimizing UNION ALL (partition) views in 7.3

According to Oracle literature, when using partition views in version
7.3, the optimizer can intelligently eliminate tables from consideration
when processing queries where the scope of the query is limited to a
single table (or subset of tables) within the UNION ALL view.

I would like details on the following:

A. What is required in order for the optimizer to do this "weeding" of
tables?  

Notes: I'm assuming that tables and indexes should be analyzed
(COMPUTE/ESTIMATE STATISTICS).  I've also heard that constraints on the
partitioning column are required.

B. What does the EXPLAIN PLAN output look like when the optimizer is
"doing the right thing"?

Notes: I've not yet been able to get a plan that doesn't either INDEX
RANGE SCAN or FULL TABLE SCAN all tables in the view.  However, it
appears that in some cases the INDEX RANGE SCANS could be false and the
tables might be being eliminated from consideration without I/O against
the tables or the indexes.

Any and all tid bits will be appreciated.

Tom Larson

2. please help can not get sqlmail started

3. Create procedure on Ingres 2.5

4. Partitioned views - how to size partitions?

5. performance of Progress

6. partition views vs partition tables

7. How do I declare a database as a user-defined data type?

8. O7 to O8 Partitioned Views to Partitioned Tables

9. Partitioned views vs. partitioned tables

10. optimize: view of views

11. ASA6: Optimize view of a view?????

12. Replicating a distributed partition view (Federated View)