473,806 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query performance - Please help

I execute a query (against DB2 for iSeries), which, in its generic form
is as follows. This query runs just fine, executing in a couple of
seconds

SELECT V.FIELD01, V.FIELD02, V.FIELD03, V.FIELD04, V.FIELD05,
V.FIELD06, V.FIELD07, V.FIELD08, V.FIELD09, V.FIELD10,
V.FIELD11, V.FIELD12, V.FIELD13
FROM SCHEMA1.VIEW1 V
WHERE V.FIELD2 BETWEEN '03/10/2005' AND '03/10/2006'
AND (V.FIELD4 = '103' OR V.FIELD4 = '100' )
AND (V.FIELD8 = 120 OR V.FIELD15= 120)
AND V.FIELD16 <> '4'
ORDER BY V.FIELD05, V.FIELD12

Now, I modify the query, because some business reason dictates that I
do so. I perform a join of the original view with some table on a
particular (single) column and also add an OR clause in the WHERE
clause. The modifiied query looks as follows and (here is my problem!)
takes circa 40 seconds to run!

SELECT V.FIELD01, V.FIELD02, V.FIELD03, V.FIELD04, V.FIELD05,
V.FIELD06, V.FIELD07, V.FIELD08, V.FIELD09, V.FIELD10,
V.FIELD11, V.FIELD12, V.FIELD13
FROM SCHEMA1.VIEW1 V, SCHEMA2.TABLE1 T //<-- (1) Table added
WHERE T.FIELD1 = 1 and V.FIELD14 = T.FIELD2 //<-- (2) Join condition
AND V.FIELD2 BETWEEN '03/10/2005' AND '03/10/2006'
AND (V.FIELD4 = '103' OR V.FIELD4 = '100' )
AND (V.FIELD8 = 120 OR V.FIELD15= 120 OR T.FIELD3 = 120)
// (3) Added an OR statement here --|
AND V.FIELD16 <> '4'
ORDER BY V.FIELD05, V.FIELD12

I wonder why this, at first sight innocuous join, causes such a
deterioration in performance.
I've run both queries through the Visual Explain tool that comes with
the iSeries navigator. The bottleneck in the second case is the hash
join performed between the results of scanning the component tables of
view V and those of table T. The "Estimated Processing Time" for that
hash join is in the range of 40.

The graph in Visual Explain looks can be descibed as follows:
(1) "Index Scan - Key Positioning" is applied to two of the component
tables (say T1 and T2) of view V. A "Nested Loop Join" is applied to
the results
(2) "Table Scan" is applied to the remaining component table (say T3)
of V. A "Temporary Hash Table" is produced
[Note that this processing of V is the same as the one performed in the
original, simpler, query]
(3) "Table Scan, Parallel" is applied to table T, that has now come
into the picture. A "Temporary Hash Table" gets produced.

Then a grand hash join is produced from the results of (1), (2), (3)
that takes 41 seconds! How could I avoid this?

Many, many thanks in advance!!!

Panagiotis Varlagas
va******@yahoo. com

Mar 16 '06 #1
10 1866
I am by no means an expert. I will offer two comments, however.

1) (V.FIELD4 = '103' OR V.FIELD4 = '100' ) should probably be
V.FIELD4 IN ('103', '100' )

2) I did not see the second TABLE being output. Perhaps an EXISTS
clause would be more appropriate than a JOIN.

B.

Mar 16 '06 #2
Hi Brian!

Wrt comment 1), surely it is a correct one, however its contribution to
performance improvement of the particular query is minimal, if any.

I applied your suggestion in comment 2) too. It did not provide any
performance improvent (the query still takes 40'' to run), however
there are two good points about it:

(a) It is a more concise way of me expressing what I want to say. It is
much clearer to the person that reads the query and tries to understand
what it is supposed to do

(b) It _does_ change the path shown in Visual Explain. No hash joins
involved now... But this change is not reflected into improved
performance

Thanks for the help!
Panagiotis

Mar 17 '06 #3
>1), surely it is a correct one, however its contribution to performance improvement of the particular query is minimal, if any.

It's is just easier to read that way. When i first looked at

(V.FIELD4 = '103' OR V.FIELD4 = '100' )
AND (V.FIELD8 = 120 OR V.FIELD15= 120)

I figured the second clause was also FIELD8 twice. I only noticed it
was two different fields on second look. Had the FIELD4 been using an
IN, i probably would not have made that mistake. Nothing major here,
just the point that IN makes things more clear.
But this change is not reflected into improved performance


Hmm... perhaps try using IN instead? I would think EXISTS should always
be better, but in many cases IN() works much much better.

B.

Mar 17 '06 #4
Is T.FIELD2 indexed? If it isn't, then this could be the cause of the
slowdown, in which case adding an index should speed it up. Or, using
the IN clause instead of EXISTS should also speed it up.

Mar 17 '06 #5
I had already rewritten the query to use either EXISTS or IN in lieu of
the inner join, but it actually yielded worse, not better performance.
Thx for the suggestion, however.

Mar 21 '06 #6
Unfortunately, T.FIELD2 is already indexed...

Mar 21 '06 #7
va******@yahoo. com wrote:
Unfortunately, T.FIELD2 is already indexed...


Have you tried the Design Advisor by providing your query as workload? It
should give you some suggestions regarding additional indexes. Likewise, a
MQT might help.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Mar 21 '06 #8
How did you use EXISTS?

How about try following ways with appropriate index.
1)
SELECT V.FIELD01, V.FIELD02, V.FIELD03, V.FIELD04, V.FIELD05,
V.FIELD06, V.FIELD07, V.FIELD08, V.FIELD09, V.FIELD10,
V.FIELD11, V.FIELD12, V.FIELD13
FROM SCHEMA1.VIEW1 V
WHERE
V.FIELD2 BETWEEN '03/10/2005' AND '03/10/2006'
AND V.FIELD4 IN ('103', '100')
AND V.FIELD16 <> '4'
AND EXISTS
(SELECT *
FROM SCHEMA2.TABLE1 T
WHERE V.FIELD14 = T.FIELD2
AND T.FIELD1 = 1
AND (V.FIELD8 = 120 OR V.FIELD15= 120 OR T.FIELD3 = 120)
)
ORDER BY
V.FIELD05, V.FIELD12

2)
SELECT V.FIELD01, V.FIELD02, V.FIELD03, V.FIELD04, V.FIELD05,
V.FIELD06, V.FIELD07, V.FIELD08, V.FIELD09, V.FIELD10,
V.FIELD11, V.FIELD12, V.FIELD13
FROM SCHEMA1.VIEW1 V
WHERE
V.FIELD2 BETWEEN '03/10/2005' AND '03/10/2006'
AND (V.FIELD8 = 120 OR V.FIELD15= 120)
AND V.FIELD4 IN ('103', '100')
AND V.FIELD16 <> '4'
AND EXISTS
(SELECT *
FROM SCHEMA2.TABLE1 T
WHERE V.FIELD14 = T.FIELD2
AND T.FIELD1 = 1)
)
OR
V.FIELD2 BETWEEN '03/10/2005' AND '03/10/2006'
AND V.FIELD4 IN ('103', '100')
AND V.FIELD16 <> '4'
AND EXISTS
(SELECT *
FROM SCHEMA2.TABLE1 T
WHERE V.FIELD14 = T.FIELD2
AND T.FIELD1 = 1
AND T.FIELD3 = 120)
)
ORDER BY
V.FIELD05, V.FIELD12

Mar 21 '06 #9
No. Actually, I am not familiar with these tools...

Mar 23 '06 #10

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

Similar topics

1
8269
by: Shaun | last post by:
Hi, I have a table called Bookings which has two important columns; Booking_Start_Date and Booking_End_Date. These columns are both of type DATETIME. The following query calculates how many hours are available between the hours of 09.00 and 17.30 so a user can see at a glance how many hours they have unbooked on a particular day (i.e. 8.5 hours less the time of any bookings on that day). However, when a booking spans more than one day...
11
5416
by: Eugenio | last post by:
Excuse me in advance fo my little English. I've got this stored procedure **************************************************************************** ********** declare @Azienda as varchar(3), @Utente as varchar(20), @DataDa as datetime, @DataA as datetime, @AreaDa as varchar(3), @AreaA as varchar(3),
2
1933
by: m3ckon | last post by:
Hi there, had to rush some sql and am now going back to it due to a slow db performance. I have a db for sales leads and have created 3 views based on the data I need to produce. However one o the views, which has subqueries to the other views is VERY slow and it needs to be speeded up, but am unsure how, can anyone help... below is the sql?
1
2716
by: Robert Neville | last post by:
The solution to my dilemma seems straight-forward, yet my mind has not been forthcoming with a direct route. My Project form has a tab control with multiple sub-forms; these distinct sub-forms relate addresses (multiple addresses); companies, contacts, and tasks to each project (one to many). My challenge lies with the task sub-form which links to the Project form through ProjID. The task record links back to the respective master...
1
2018
by: Peter Alberer | last post by:
Hi there, i have a problem with a query that uses the result of a plsql function In the where clause: SELECT assignments.assignment_id, assignments.package_id AS package_id, assignments.title AS title, COUNT(*) AS Count
14
3507
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the productivity, but what I'm being asked is to look at the average productivity/performance compared to...
2
2426
by: Brian Tabios | last post by:
Hello Everyone, I have a very complex performance issue with our production database. Here's the scenario. We have a production webserver server and a development web server. Both are running SQL Server 2000. I encounted various performance issues with the production server with a particular query. It would take approximately 22 seconds to return 100 rows, thats about 0.22 seconds per row. Note: I ran the query in single user mode. So...
0
975
by: dilippanda | last post by:
Hi, I have the following query. select distinct a.*,b.launch_dt from ( select list_id, run_seq,
25
2547
by: Darsin | last post by:
Hi all I need to perform a summation on a column of a table based on a criteria given in another column in the same table. The catch is i need to perform different sums according to the number of criterias in the criteria column, in a single query. the structure of the table is somethinmg like this (only relevant columns are shown) TABLE1 Value - numeric(20,6) Month - int
0
9719
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
9597
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
10620
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...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
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,...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.