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

Query Performance question

We have the following query and is taking considerable longer time to
run.

select A.*, B.name,B.user_type,C.task_id, c.queue_id, c.workid
FROM A, B, C
WHERE (B.user_type <2 and B.user_type is not null)
AND C.task_id = A.task_id
AND B.queue_id = C.queue_id
AND C.queue_id IN (1, 5, 9)
AND C.ready_status IN (1,2,3)
AND C.assign_user_id IS NULL
AND A.state_code in ('MA')

Our DBA has tried to optimize this query and basically added few dummy
COALESCE functions to the WHERE clause as following....

select A.*, B.name,B.user_type,C.task_id, c.queue_id, c.workid
FROM A, B, C
WHERE (B.user_type <2 and B.user_type is not null)
AND C.task_id = A.task_id
AND B.queue_id = C.queue_id
AND C.queue_id IN (1, 5, 9)
AND C.ready_status IN (1,2,3)
AND C.assign_user_id IS NULL
AND A.state_code in ('MA')
AND C.queue_id = COALESCE(C.queue_id, C.queue_id)
AND C.task_id = COALESCE(C.task_id, C.task_id)
AND C.ready_status = COALESCE(C.ready_status, C.ready_status)
AND A.task_id = COALESCE(A.task_id, A.task_id)
What is the significance of these COALSCE functions ??
How are they supposed to alter the query plan for better performance ?

Thanks in advance
Dec 13 '07 #1
2 2450
longer than before?

are statistics actual ?
do you have "good" indexes ?
On Dec 13, 11:37 am, Veeru71 <m_ad...@hotmail.comwrote:
We have the following query and is taking considerable longer time to
run.

select A.*, B.name,B.user_type,C.task_id, c.queue_id, c.workid
FROM A, B, C
WHERE (B.user_type <2 and B.user_type is not null)
AND C.task_id = A.task_id
AND B.queue_id = C.queue_id
AND C.queue_id IN (1, 5, 9)
AND C.ready_status IN (1,2,3)
AND C.assign_user_id IS NULL
AND A.state_code in ('MA')

Our DBA has tried to optimize this query and basically added few dummy
COALESCE functions to the WHERE clause as following....

select A.*, B.name,B.user_type,C.task_id, c.queue_id, c.workid
FROM A, B, C
WHERE (B.user_type <2 and B.user_type is not null)
AND C.task_id = A.task_id
AND B.queue_id = C.queue_id
AND C.queue_id IN (1, 5, 9)
AND C.ready_status IN (1,2,3)
AND C.assign_user_id IS NULL
AND A.state_code in ('MA')
AND C.queue_id = COALESCE(C.queue_id, C.queue_id)
AND C.task_id = COALESCE(C.task_id, C.task_id)
AND C.ready_status = COALESCE(C.ready_status, C.ready_status)
AND A.task_id = COALESCE(A.task_id, A.task_id)

What is the significance of these COALSCE functions ??
How are they supposed to alter the query plan for better performance ?

Thanks in advance
Dec 14 '07 #2
>select A.*, B.name,B.user_type,C.task_id, c.queue_id, c.workid
>FROM A, B, C
WHERE (B.user_type <2 and B.user_type is not null)
AND C.task_id = A.task_id
AND B.queue_id = C.queue_id
AND C.queue_id IN (1, 5, 9)
AND C.ready_status IN (1,2,3)
AND C.assign_user_id IS NULL
AND A.state_code in ('MA')
>Thanks in advance
I can say
that I think the best thing to do is for you to reply with the query's
plan, and let some of the fine minds that frequent these parts have a
crack at tuning your query.
Regards,
--Jeff

Without suggestion from Index Advisor and/or Database Monitor (and
coming from i5/OS DB2 world) - and without knowing anything about actual
indexing and constraints (and statistics) in your db - I'd try to build
the following indexes:
Create Index A1 on A (state_code, task_id);
Create Index B1 on B (user_type, queue_id, name);
Create Index C1 on C (assign_user_id, ready_status, queue_id, task_id,
workid).

On DB2 for i5/OS, B.name and C.workid would not be necessary for
indexing itself but they would probably make the query run faster (as
db2 engine could use directly B1 and C1 without accessing B and C ;-)

>Thanks in advance
HTH
Stefano P.

--
"Niuna impresa, per minima che sia,
può avere cominciamento e fine senza queste tre cose:
e cioè senza sapere, senza potere, senza con amor volere"
[Anonimo fiorentino, XIV sec.]

(togliere le "pinzillacchere" dall'indirizzo email ;-)
Dec 15 '07 #3

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

Similar topics

2
by: inna | last post by:
Hello. I have query performance question. I need to optimize procedure CREATE PROCEDURE dbo.SECUQUSRCOMPACCES @P1 VARCHAR(50), @P2 INTEGER AS DECLARE @IORGANIZATIONID INTEGER EXECUTE...
3
by: Andrew Mayo | last post by:
There is something very strange going on here. Tested with ADO 2.7 and MSDE/2000. At first, things look quite sensible. You have a simple SQL query, let's say select * from mytab where col1 =...
1
by: Paul | last post by:
Assume you have two varchar (or Text) columns named L and U which are identical except that the charset for L is latin1 and the charset for U is utf8. All the records in L and U are identical in...
3
by: krystoffff | last post by:
Hi I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
10
by: deko | last post by:
I've tried each of the below, but no luck. UPDATE tblEntity As tbl INNER JOIN search3220 As qry ON tbl.Entity_ID = qry.Entity_ID SET tbl.Cat_ID = 289; UPDATE tblEntity INNER JOIN search3220 ON...
0
by: phlype.johnson | last post by:
I'm struggling to find the best query from performance point of view and readability for a normalized DB design. To illustrate better my question on whether normalized designs lead to more complex...
4
by: newtophp2000 | last post by:
Hello, I am trying to find all records that have matching detail_1 or detail_2 columns. This is what I have now: select t1.id, t1.detail_1, t1.detail_2, t2.id from user_details t1,...
1
by: Jimbo | last post by:
I have a query..if you look at the bottom of the where clause you'll see an "NOT IN" statement that is really hanging up the query..i'm trying to replace with a "NOT EXISTS" but it isnt appearing...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.