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

Select satement return result very slow

hi all,

One of my customer having warehouse database running on DB2. Recently
when they execute the following query at db2 command line
the exepected result take ages before return result

select count(*) from dss.fncsvcar where ar_id no in (select ar_id from
dss.ar)

Both tables ar_id is not a key field. However, indexes are created
the following order

fncsvcar
--------
create index dss.fncsvcaridx on dss.fncsvcar(ar_id asc);

ar
---
create unique index dss.aridx on dss.ar(ar_id asc);
The fncsvcar table has 3 million records and ar table has 7 million
records. Is there any other way to improve this query?

Thanks
Uthuras

Nov 12 '05 #1
3 4262
Hi,

ut*****@hotmail.com wrote:
One of my customer having warehouse database running on DB2. Recently
when they execute the following query at db2 command line
the exepected result take ages before return result


which means, that this query ran within reasonable time before and the
behaviour then suddenly changed?

How old are statistics? (stats_time from syscat.tables)

regards,

Norbert
Nov 12 '05 #2
<ut*****@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
hi all,

One of my customer having warehouse database running on DB2. Recently
when they execute the following query at db2 command line
the exepected result take ages before return result

select count(*) from dss.fncsvcar where ar_id no in (select ar_id from
dss.ar)

Both tables ar_id is not a key field. However, indexes are created
the following order

fncsvcar
--------
create index dss.fncsvcaridx on dss.fncsvcar(ar_id asc);

ar
---
create unique index dss.aridx on dss.ar(ar_id asc);
The fncsvcar table has 3 million records and ar table has 7 million
records. Is there any other way to improve this query?

Thanks
Uthuras

Your query is doing a tablespace scan in the subselect each time. Try this:

SELECT
count(*)
FROM dss.fncsvcar a
WHERE a.ar_id not in
(SELECT ar_id
FROM dss.ar b
WHERE b.ar_id = a.ar_id )

Also, make sure you have run runstats command since you have created the
indexes.
Nov 12 '05 #3
The IN returns 7 million rows that you have to scan. Try to convince DB2 to
do a semijoin (see the documentation on the relevant registry variable)
and/or reformulate your query to use EXISTS:
select count(*) from dss.fncsvcar f where exists (select * from dss.ar d
where d.ad_id = f.ar_id)

<ut*****@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
hi all,

One of my customer having warehouse database running on DB2. Recently
when they execute the following query at db2 command line
the exepected result take ages before return result

select count(*) from dss.fncsvcar where ar_id no in (select ar_id from
dss.ar)

Both tables ar_id is not a key field. However, indexes are created
the following order

fncsvcar
--------
create index dss.fncsvcaridx on dss.fncsvcar(ar_id asc);

ar
---
create unique index dss.aridx on dss.ar(ar_id asc);
The fncsvcar table has 3 million records and ar table has 7 million
records. Is there any other way to improve this query?

Thanks
Uthuras

Nov 12 '05 #4

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

Similar topics

11
by: Jeff Sandler | last post by:
I need a MySQL select statement as part of a PHP script. I want to find rows where a certain column either starts with or equals a user-supplied string. The string will be 1 or more characters in...
5
by: eddie wang | last post by:
hello, I have the following query. it returns result in less than 1 second. select * from employee e, address a where e.id=a.emp_id and e.id=1234 The problem is that it becomes extremely slow...
3
by: dror | last post by:
Hello, I have a problem that actually doesn't even make sense. I have 4 million rows in my database. I want to get all records into a DataReader and then read. So if I do it in DAO (either in VB...
1
by: David Lawson | last post by:
The line indicated below from my php script is very slow (about 10 seconds). I have this field indexed so I thought that it would be much faster. Could someone tell me what might be wrong? I'm also...
6
by: RCS | last post by:
I've been running into more and more complexity with an application, because as time goes on - we need more and more high-level, rolled-up information. And so I've created views, and views that use...
13
by: kevinold | last post by:
Hello everyone, I have a list of about 1600 employees that I'd like to have displayed in a form. I'd like to make the "search" for the user as easy as possible. I ran across this:...
0
by: Florian | last post by:
Hi Uthuras, it would be helpful to see the access path. However sometimes it makes sense to rewrite a "not in" to gain better access paths: I tried the following - hopefully similar -...
18
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are...
1
by: martin | last post by:
Hi, I have a page that contain a dropdown list of values. This drop down list rarely changes so I wish to cache the page. However the values in the dropdown box are taken from a database, so if...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
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...

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.