Quantcast
Viewing all articles
Browse latest Browse all 15889

Partition Elimination doesn't occur with CHAR column and basic queries?

It seems that partitioning on a CHAR column is not at straight forward as I imagined.  

I have several ODS and data warehouse databases where almost every table is being queried with a char(3) column in the where clause.  This column, Div, is for the division (company) ID.  Thus, Div is a natural candidate for partitioning, not only for query performance, but also ETL efficiency, as companies are sending data late or out of band but then expecting immediate gratification.

During initial testing of partitioning on this CHAR(3) column, it became immediately apparent that our basic (automated) where filtering does not work as expected.  On a table with a defined partition function using CHAR(3) and the 43 Div literals, here are two illustrative queries:

Select 
count(1)
from PARTMSTP_PT t
where 
t.Div = 'atk'

Select 
count(1)
from PARTMSTP_PT t
where 
t.DIv = cast('atk' as char(3))


and their Statistics IO ouput:

(1 row(s) affected)
Table 'PARTMSTP_PT'. Scan count 42, logical reads 171174, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
(1 row(s) affected)
Table 'PARTMSTP_PT'. Scan count 1, logical reads 4245, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

As you can see, the simple div = 'xxx' is scanning all 42 partitions, but the overly complex clause using a cast to char(3) results in the expected single patition scan.

It is unreasonable to expect all queries in our ad-hoc reporting system to cast to char(3).  I'm planning on testing a similar test case with a partition function defined with varchar(3), but would like to throw out the questions....

What is the accepted pattern for partitioning (and subesquent querying by ad-hoc and other means) of a CHAR column?  Users, admins, reporting systems, developers, etc.,  can't possibly be expected to cast for every query they build or execute!

Is it acceptable to use a varchar PF against a known CHAR column (if it works), and what additional gotcha's should I be considering if this does work?  Will joins be aligned, indexes, indexed views, etc., etc.?

I don't have a good feeling about these results at such an early stage of testing!



Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>