473,378 Members | 1,679 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,378 software developers and data experts.

Performance question DB2 UDB v8.1.9 Linux

The following sql is expanded from an example from Tonkuma to my
complete application. It runs for over 6 minutes when my separate sql
statements wrapped with some PHP code can do the same thing in less than
3 seconds. For reasons which I need not go into here, I need to do this
is on sql statement. I take the performance hit because of the 7 nested
full table scans even though cow_bhid is the first primary key column of
taa, tba and tca; (bhid, herd_owner) is the whole primary key of
animals_priv (tab, tbb, tcb). What I would like to know is how to
improve the performance of this query.

select t1.animal_id, t1.locname, t1.bhid,
ta.herd_id, ta.datex, ta.time_code,
ta.datex+283 days as date_due,
tb.herd_id, tb.datex, tb.time_code,
tb.datex+283 days as date_due,
tc.herd_id, tc.in_date, tc.out_end_date,
tc.in_date+282 days as start_date_due,
tc.out_end_date+283 days as end_date_due
from is3.animals2 t1
left outer join
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
order by taa.datex) ta
full outer join
(select tba.*, tbb.herd_id,
ROWNUMBER() OVER(PARTITION BY tba.cow_bhid) rn
from is3.service_ai tba
left outer
join is3.animals_priv tbb
on tbb.herd_owner_id=1
and tbb.bhid=tba.bull_bhid
// where tba.cow_bhid=t1.bhid
order by tba.datex) tb
on tb.cow_bhid=ta.cow_bhid
and tb.rn=ta.rn
full outer join
(select tca.*,tcb.herd_id,
ROWNUMBER() OVER(PARTITION BY tca.cow_bhid) rn
from is3.service_pasture tca
left outer
join is3.animals_priv tcb
on tcb.herd_owner_id=1
and tcb.bhid=tca.bull_bhid
// where tca.cow.bhid=t1.bhid
order by tca.in_date) tc
on tc.cow_bhid=coalesce(ta.cow_bhid, tb.cow_bhid)
and tc.rn=coalesce(ta.rn,tb.rn)
on t1.bhid=coalesce(ta.cow_bhid, tb.cow_bhid, tc.cow_bhid)
where t1.bhid in
(select bhid
from is3.animal_sets
where set_name='Bred_Cows'
and userid='jhough')
order by t1.animal_id
Feb 4 '06 #1
3 1432
Those some ideas came in mind, but not so sure and not tested.
Especially 4th idea might not work.

1) I feel ta and tb are completely same except table correlation names.
So, you may remove tb nested table expression.

2) Move the position of ORDER BY
From:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
order by taa.datex) ta

To:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid
ORDER BY taa.datex) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
) ta

3) Make indexes
(cow_bhid, datex, bull_bhid) for taa, tba and tca.

4) Correlate with t1 by WHERE caluse in nested table expression.
And remove corresponding conditions from ON clause.
From:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
order by taa.datex) ta

To:
TABLE
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid
ORDER BY taa.datex) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
where taa.cow_bhid=t1.bhid
) ta

Change last ON condition.
From:
on t1.bhid=coalesce(ta.cow_bhid, tb.cow_bhid, tc.cow_bhid)
To:
on 0=0

Feb 5 '06 #2
Tonkuma wrote:
Those some ideas came in mind, but not so sure and not tested.
Especially 4th idea might not work.

1) I feel ta and tb are completely same except table correlation names.
So, you may remove tb nested table expression.

2) Move the position of ORDER BY
From:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
order by taa.datex) ta

To:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid
ORDER BY taa.datex) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
) ta

3) Make indexes
(cow_bhid, datex, bull_bhid) for taa, tba and tca.

4) Correlate with t1 by WHERE caluse in nested table expression.
And remove corresponding conditions from ON clause.
From:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
order by taa.datex) ta

To:
TABLE
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid
ORDER BY taa.datex) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
where taa.cow_bhid=t1.bhid
) ta

Change last ON condition.
From:
on t1.bhid=coalesce(ta.cow_bhid, tb.cow_bhid, tc.cow_bhid)
To:
on 0=0

Item 1 was an error on my part; tb should have been base on is3.service_obs

Items 2 and 3 made only slight differences.

Item 4 was the key. After I implemented it properly, the query took 875
ms. I had tried the correlation, as evidenced by the comments, but I did
not have the TABLE keyword. I do not understand how that keyword makes
t1.bhid "visible" in the subselects, whereas without the TABLE, t1.bhid
is not defined therein.
Feb 7 '06 #3
Bob Stearns wrote:
Tonkuma wrote:
4) Correlate with t1 by WHERE caluse in nested table expression.
And remove corresponding conditions from ON clause.
From:
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
// where taa.cow_bhid=t1.bhid
order by taa.datex) ta

To:
TABLE
(select taa.*, tab.herd_id,
ROWNUMBER() OVER(PARTITION BY taa.cow_bhid
ORDER BY taa.datex) rn
from is3.service_ai taa
left outer
join is3.animals_priv tab
on tab.herd_owner_id=1
and tab.bhid=taa.bull_bhid
where taa.cow_bhid=t1.bhid
) ta

Change last ON condition.
From:
on t1.bhid=coalesce(ta.cow_bhid, tb.cow_bhid, tc.cow_bhid)
To:
on 0=0

Item 4 was the key. After I implemented it properly, the query took 875
ms. I had tried the correlation, as evidenced by the comments, but I did
not have the TABLE keyword. I do not understand how that keyword makes
t1.bhid "visible" in the subselects, whereas without the TABLE, t1.bhid
is not defined therein.

The history behind TABLE is simple.
Example:
DECLARE x INT;
SELECT * FROM T AS X(x), (SELECT * FROM S AS A(a) WHERE S.a = x) AS Z
In the original behavior from DB2 for zOS which PRECEEDS the SQL
Standard rules x will resolve to the variable x (or a higher level query).
Since being compatible with DB2 zOS at the time was considered quite
important, but the standard folks thought it important to be able to
resolve to X(x) a keyword needed to be introduced.
Originally teh name was TABLE, but it was changed a later stage (after
DB2 incorporated the change) to LATERAL.
That's what "existing customers" do to you. You can't take back semantics.
Nowadays DBS for iSeries 5R4 and DB2 for LUW V8.2 have added LATERAL as
a synonym for TABLE to comply with the standard. I'd expect DB2 for zOS
to fall in line with the next release.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Feb 7 '06 #4

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

Similar topics

57
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
13
by: Shane Wright | last post by:
Hi, I've been trying to spec a new server for my company's database for a few weeks and one of the biggest problems I've had is trying to find meaningful performance information about how...
2
by: tomdean20 | last post by:
Does anyone have a general idea of the difference in performance when compiling PHP with primarily shared extensions rather than static? A recent Yahoo presentation "PHP at Yahoo" highlighted that...
4
by: joa2212 | last post by:
Hello everybody, I'm posting this message because I'm quiet frustrated. We just bought a software from a small software vendor. In the beginning he hosted our application on a small server at...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...

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.