473,406 Members | 2,956 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.

Query Tuning Help

Greetings,
I have the following query which takes very long time to execute hence
can you please help to fine tune it as I'm new to DB2 World. Thanks

SELECT
char(VEH_IDENT_NBR) as VEH_IDENT_NBR,
OPTN_CD,
SRC_TRMNT_TIMSTM,
DWH_EFCTV_TIMSTM,
DWH_UPD_TIMSTM
FROM
CARD.VIN_VEH_OPTNS a
WHERE
(
a.DWH_EFCTV_TIMSTM >
(
SELECT
MAX(DWH_ETL_ST_TIMSTM)
FROM
card.DWH_CONTROL
where
DWH_SEQ_NM = 'a' and
DWH_ETL_STATUS='S'
)
OR
a.DWH_UPD_TIMSTM >
(
SELECT
MAX(DWH_ETL_ST_TIMSTM)
FROM
card.DWH_CONTROL
where
DWH_SEQ_NM ='a' and
DWH_ETL_STATUS='S'
)
)
and
VEH_OPTN_CD_CSI=1

CARD.VIN_VEH_OPTNS Table details
- Has 58 Million rows
- Partitioned table based on VEH_IDENT_NBR
- Indexes & Keys
1. INDEX on ( DWH_UPD_TIMSTM ASC,VEH_IDENT_NBR
ASC,OPTN_CD ASC,VEH_OPTN_CD_CSI
ASC)
2. PRIMARY KEY (VEH_IDENT_NBR, OPTN_CD, VEH_OPTN_CD_CSI);

CARD.DWH_CONTROL
- Small table with 2000 rows
- Non-partitioned table

Regards,
Sam

Apr 25 '06 #1
5 1389
Sam,

I just reorganized your statement. Select stmt in your where clause
seemed repeating. But I am not sure how this would affect overall
performance. Give it a try and let me know your results.

regards,

Mehmet

SELECT
char(VEH_IDENT_NBR) as VEH_IDENT_NBR,
OPTN_CD,
SRC_TRMNT_TIMSTM,
DWH_EFCTV_TIMSTM,
DWH_UPD_TIMSTM
FROM
CARD.VIN_VEH_OPTNS a,

( SELECT MAX(DWH_ETL_ST_TIMSTM) as tempfield
FROM card.DWH_CONTROL
where DWH_SEQ_NM = 'a' and DWH_ETL_STATUS='S' ) as temptable

WHERE
(
a.DWH_EFCTV_TIMSTM > temptable.tempfield

OR
a.DWH_UPD_TIMSTM > temptable.tempfield

)
and
VEH_OPTN_CD_CSI=1

Apr 25 '06 #2
Thanks for your query. But after adding a new index on VEH_OPTN_CD_CSI
I have got a same performance using both the query. The access plan is
as below and I'm still looking for options to improve the performance.

Access Plan:
-----------
Total Cost: 335820
Query Degree: 1

Rows
RETURN
( 1)
Cost
I/O
|
1.4601e+07
DTQ
( 2)
335820
180963
|
4.867e+06
NLJOIN
( 3)
331100
180963
/------+------\
1 4.867e+06
GRPBY FETCH
( 4) ( 9)
12.952 331087
1 180962
| /----+---\
3 6.4895e+06 1.94685e+07
BTQ IXSCAN TABLE: CARD
( 5) ( 10) VIN_VEH_OPTNS
12.9516 25082.3
1 11149.1
| |
1 1.94685e+07
GRPBY INDEX: CARD
( 6) I3
12.891
1
|
1
FETCH
( 7)
12.8908
1
/----+---\
1 14
IXSCAN TABLE: CARD
( 8) DWH_CONTROL
0.0331973
0
|
14
INDEX: SYSIBM
SQL0602122312521

Thanks,
Sam

Apr 26 '06 #3
Sam,

What about indexes on DWH_SEQ_NM and DWH_ETL_STATUS fields?

Regards,

Mehmet

Apr 26 '06 #4
Mehmet, I dont have any index on DWH_CONTROL table apart the primary
key on DWH_LOAD_ID and DWH_SEQ_NM. Also this has around 1000 rows so it
doesn't matter I guess.

Thanks,
Sam

Apr 26 '06 #5
Sam,

Sorry for overlooking your first postl. Other than your 2 nested query
and being run on a partioned table, the main query is so straight
forward. With indexes on DWH_UPD_TIMSTM and VEH_OPTN_CD_CSI, your query
should really rock. I

When you replace the nested queries with scalars, shouldn't you get the
bare minimum cost? If the cost is still big then you may need to do
change the partion key?

regards,

mehmet

Apr 26 '06 #6

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

Similar topics

6
by: Mahesh Hardikar | last post by:
Hi , Oracle 8.1.7.0.0 on HP-UX 11.0 I am a newbie as far as PL-SQL is concerned . I have Sybase/MSSQL T-SQL background. We have a report which uses a select statement . This select...
14
by: Bob | last post by:
Hi there, Need a little help with a certain query that's causing a lot of acid in my stomach... Have a table that stores sales measures for a given client. The sales measures are stored per...
3
by: Maryam | last post by:
Hi, I am having problems getting anything useful out of the index tuning wizard. I have created a table and inserted data into it. When i run the index tuning wizard i expect 2 indexes to be...
9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
1
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,...
4
by: Raj | last post by:
Hi all, I have couple of questions some one plzz help 1.I have a query which run for 2 hours on my production machine, it returns 1.5 millon rows, i looked at the explain plan it is picking up...
1
by: Jean-Marc Blaise | last post by:
Hi, I find much regrettable that Database Engine Tuning Advisor be not part of MS-Express Edition ... A server without such help is not a server. Besides, you've got the tutorials, but not the...
3
by: dba_222 | last post by:
Dear experts, I hate to ask such a seemingly dumb question. But I have spent some time trying to solve this already to no avail. When I was using my query analyzer last, a few months ago, I...
13
by: atlaste | last post by:
Hi, I'm currently developing an application that uses a lot of computational power, disk access and memory caching (to be more exact: an information retrieval platform). In these kind of...
1
by: Vinod Sadanandan | last post by:
A Roadmap To Query Tuning ============================ For each SQL statement, there are different approaches that could be used to retrieve the required data. Optimization is the process of...
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?
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
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...
0
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...
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.