473,406 Members | 2,259 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,406 software developers and data experts.

UNION ALL View

I'm testing a UNION ALL View (say UA_VIEW) of 12 tables - one table for
each year - 5 million records/table on an average.

Check constraints are defined on the base table -

EG. EFF_START_DATE BETWEEN ('2004-01-01' AND '2004-12-31') AND
EFF_END_DATE BETWEEN ('2004-01-01' and '2004-12-31')

and also on the view defn,

SELECT * from table_2004 where eff_start_date between '2004-01-01' and
'2004-12-31' and eff_end_date between '2004-01-01' and '2004-12-31'.

There is another table table2 with a column calendar_date, which
contains some details for each day of the last 12 years, one
record/day.

The following queries perform well, they scan through only one table :

SELECT 1 from UA_VIEW where '2004-04-01' between eff_start_date and
eff_end_date

SELECT 1 from UA_VIEW t1,table2 t2 where t2.calendar_date='2004-04-01'
and t2.calendar_date between eff_start_date and eff_end_date
But, the following queries scan through all the tables :
SELECT 1 from UA_VIEW t1,table2 t2 where t2.calendar_date in
('2004-04-01','2004-04-02') and t2.calendar_date between eff_start_date
and eff_end_date

SELECT 1 from UA_VIEW t1,table2 t2 where t2.calendar_date between
'2004-04-01' and '2004-04-02' and t2.calendar_date between
eff_start_date and eff_end_date

Is it by any chance, a documented 'limitation' of the using union all
view definitions ?

Please suggest on of how I can get the last two statements to do a
scan only on the relevant table(s) ?

Applying the where condition on the UA_VIEW is the last thing I want to
try as the query is being dynamically built using a third party query
tool ...

Thanks in advance

Sathyaram

Nov 12 '05 #1
2 3513
Sathyaram Sannasi wrote:
I'm testing a UNION ALL View (say UA_VIEW) of 12 tables - one table for
each year - 5 million records/table on an average.

Check constraints are defined on the base table -

EG. EFF_START_DATE BETWEEN ('2004-01-01' AND '2004-12-31') AND
EFF_END_DATE BETWEEN ('2004-01-01' and '2004-12-31')

and also on the view defn,

SELECT * from table_2004 where eff_start_date between '2004-01-01' and
'2004-12-31' and eff_end_date between '2004-01-01' and '2004-12-31'. There is no need to duplicate the predicates in the view definition.
If you stick to the constraints only (and forget about labeling the
tables by year), you can do efficient rollin/out just by playing with
the constraints.
There is another table table2 with a column calendar_date, which
contains some details for each day of the last 12 years, one
record/day.

The following queries perform well, they scan through only one table :

SELECT 1 from UA_VIEW where '2004-04-01' between eff_start_date and
eff_end_date

SELECT 1 from UA_VIEW t1,table2 t2 where t2.calendar_date='2004-04-01'
and t2.calendar_date between eff_start_date and eff_end_date
But, the following queries scan through all the tables :
SELECT 1 from UA_VIEW t1,table2 t2 where t2.calendar_date in
('2004-04-01','2004-04-02') and t2.calendar_date between eff_start_date
and eff_end_date

SELECT 1 from UA_VIEW t1,table2 t2 where t2.calendar_date between
'2004-04-01' and '2004-04-02' and t2.calendar_date between
eff_start_date and eff_end_date So the base tables ahve three date columns: calendar_date, eff_start and
eff_end?
Is it by any chance, a documented 'limitation' of the using union all
view definitions ? The optimizer and query rewrite can only be described so good without
being both overwelming or giving away the secret sauce....

I don't think query rewrite resolved the IN list/BETWEEN combination
into an OR/BETWEEN combination.
Do you have a constraint that specifies that eff_start <= calendar_date
<= eff_and. I doubt it will help, but it may be worth a shot.
Please suggest on of how I can get the last two statements to do a
scan only on the relevant table(s) ?

Applying the where condition on the UA_VIEW is the last thing I want to
try as the query is being dynamically built using a third party query
tool ...

You need to get the constants "closer" to the epartitioning constraints..
What about partitioning on the calendar_date instead?

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2
AK
>EG. EFF_START_DATE BETWEEN ('2004-01-01' AND '2004-12-31') AND
EFF_END_DATE BETWEEN ('2004-01-01' and '2004-12-31')


so no row can have EFF_START_DATE 5 minutes before New Year and
EFF_END_DATE 10 minutes after New year, correct?

Nov 12 '05 #3

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

Similar topics

1
by: Buttercup | last post by:
I am having alot of trouble with a union query Im trying to create. The bizarre thing is I initially created this query and managed to save it as a view SELECT ID, DepartureDate, City,...
1
by: jtwright | last post by:
I've got a view that creates a parent child relationship, this view is used in Analysis Services to create a dimension in a datastore. This query tends to deadlock after about 10 days of running...
6
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2):...
8
by: lyn.duong | last post by:
Hi, I have a large table (about 50G) which stores data for over 7 years. I decided to split this table up into a yearly basis and in order to allow minimum changes to the applications which...
6
by: _link98 | last post by:
Problem: getting SQL0181N for queries on nicknames to remote Union-All-View. Can't see what I'm doing wrong yet, maybe someone has seen this before. Environment: UDB ESE 8.1 + FIXPAK 9A, on...
2
by: Aaron Haspel | last post by:
Greetings Access gurus. I have clients with Access databases in the field that I need to update -- new tables, new indices, new queries, the works. Since these clients may have only the Access...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
7
by: jason.langdale | last post by:
I have 3 tables I want to use in a view. Table A has field 1,2,3,4,5 and table B has field 1,2,3,4,5. I want to do a union on these. (I have done so successfully if I stop here) I also want to join...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
0
by: oskhan | last post by:
Hello Everyone, I have a little different problem and I though anyone might give me any idea that what is going wrong. I have a view which consists of 3 tables linked by UNION ALL, overall...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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,...

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.