473,378 Members | 1,142 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.

Long running of DB2 Queries

Hello! If there’s anyone who can help with this problem…

We created two working environments, creating the same table (TABLEX), same indexes (INDEX1, INDEX2 & INDEX3) and executing the same SQL Statements (SQL1, SQL2 & SQL3) thru spufi. Here is exactly what we did.

For both environments, these SQL statements were created. The ‘where clause’ of the first SQL statement is patterned after INDEX1. The ‘where clause’ of the second SQL statement is patterned after INDEX2. The ‘where clause’ of the third SQL statement is patterned after INDEX3.

Environment 1: We created three indexes (INDEX1, INDEX2 & INDEX3). Then we ran SQL1, this ran for 5 seconds and TMONDB2 displayed INDEX1. Then we ran SQL2, this ran for 5 seconds and TMONDB2 displayed INDEX2. Then we ran SQL3, this also ran for 5 seconds and TMONDB2 displayed INDEX3.

Environment 2: At first, we did not create any index, then we ran the three SQLs. SQL1 ran for 28 seconds, SQL2 for 26 seconds and SQL3 for 30 seconds.

Then we created INDEX3. SQL1 ran for 38 seconds, TMONDB2 displayed INDEX3. SQL2 ran for 28 seconds, TMONDB2 displayed INDEX3. SQL3 ran for 5 seconds, TMONDB2 displayed INDEX3.

Then we created INDEX2. So, we now have INDEX2 & INDEX3. SQL1 ran for 26 seconds, TMONDB2 displayed INDEX2 & INDEX3. SQL2 ran for 28 seconds, TMONDB2 displayed INDEX2 & INDEX3. SQL3 ran for 9 seconds, TMONDB2 ONLY displayed INDEX3.

Then we created INDEX1. Now, we have all indexes. SQL1 ran for 7 seconds, TMONDB2 displayed INDEX1. SQL2 ran for 58 seconds, TMONDB2 displayed INDEX1. SQL3 ran for 41 seconds, TMONDB2 displayed INDEX1.

The following are the SQL statements:
1. SELECT *
FROM TABLEX
WHERE BANKCD = 12345
AND MONTHENDDT = 20070131
AND BATCHSYS = ‘SYS’
AND ACCTCD = 123

2. SELECT *
FROM TABLEX
WHERE BANKCD = 12345
AND BATCHSYS = ‘SYS’
AND CLIENT = 12345
AND ACCTCD = 123
AND MONTHENDDT = 20070131

3. SELECT *
FROM TABLEX
WHERE MONTHENDDT = 20070131
AND UNIT = 5423
AND ACCTOFF = 111112
AND BATCHSYS = ‘SYS’

Why is the runtime of environment 2 different from environment 1 when all the indexes are created? Why is the display of TMONDB2 different from environment 1 and environment 2 after creating the three indexes? What could be the other factors that may affect this difference?
Jun 29 '07 #1
6 4684
Not sure, but at a guess I'd say Environment 2 is attempting to cluster by index 3, where-as env 1 would be clustering by index 1 (assuming you created them in 1-2-3 order). At least I think that's how db2 works - unless you specify one of the indexes as clustering, it will pick the 1st one created. Even if runstats aren't collected, I guess that would alter the access paths.
Jun 29 '07 #2
Snib
24
Ben is correct in what he has stated. If you check the the following URL:

Index Design for Performance

Under the section titled "Recommendations" it confirms that DB2 will select the first index added to the table as the clustering index if that is the only index being added at that time.

What is not clear from your statements is if/when you ran a RE-ORG, when you loaded the tables and whether you ran RUNSTATs.

If you are creating a new table which you are going to load rows onto after it is created (i.e. you are not starting off with an empty table and then adding rows via an application as they are created), then one option is as follows:

1/ Define the table structure
2/ Define the clustering index
3/ Load the data (use the DB2 load facility as this will ensure the rows are sorted in the clustering index order as they are stored on the data portion of the table)
4/ Define second index
5/ Define third index
6/ Execute RUN-STATs
7/ If the SQL is being executed from a program and not as dynamic SQL then execute a REBIND to allow DB2 to re-analyse the most efficient access paths for the SQL.

If you load the data onto a table before creating the primary index then it will be loaded in the order of the input file used. Even when you create the clusting index if you do not RE-ORG the table the data stays in this order on the data portion of the table. If you do not execute RUNSTATs then the details used during the REBIND/BIND will not be up-to-date and may again impact performance.

There are a number of fields that affect the access paths for "static" SQL - I susgest you runs some searches on the Internet to find the list of the latest ones for your version of DB2.

One thing to remember - if you do not RE-ORG and RUNSTAT then access paths may not be as you expected. If you do not specify the clustering index for a TABLE then access paths may not be as you expected.

I suspect that if you dropped the indexes from Environment 2, create them again but define Index 1 as clustering, execute a RE-ORG, execute RUNSTATS, BIND the SQL if it is static and in a program and then run the SQL again you will finds things are bettter.

If they are still not the same as Env 1 then I would suggest you repeat the same process against Env 1 to ensure the indexes, runstats and access paths are as up-to-date as possible.

Regards

Snib
Jun 30 '07 #3
thank you so much, snib and ben...!!!!
i'l update you, guys...thank you!!!
Jul 1 '07 #4
hello...i just found out that both environments were clustered with INDEX1.
:)
Jul 2 '07 #5
Snib
24
OK, so does that mean you still have a problem or is everything no working ok?

If you still have a problem it would help if you could run an EXPLAIN for each piece of SQL against each environment and then post the details from the PLANTABLE. We can then review exactly what order the SQL is being executed in and the indexes DB2 has selected.

One other thing, before you run the EXPLAIN ensure you have executed RUNSTATS and is the SQL is in a program then execute a REBIND. If you do a REBIND you can request this to produce the EXPLAIN output at the same time.

Regards

Snib
Jul 5 '07 #6
Yes! it worked for both development and production environments..

Here is what we did....
in our development environment:
  1. we dropped all indexes and tables
  2. created the table and defined the primary index with clustering
  3. restored all data
  4. created other indexes
  5. RUNSTATS
  6. rebind programs
  7. run programs

in our production environment:
  1. we dropped all indexes
  2. defined the primary index with clustering
  3. REORG
  4. created other indexes
  5. RUNSTATS
  6. run programs

thanks a lot!
Jul 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sqlserver yeahbaby | last post by:
I can't seem to find a step-by-step guide to how to detect or continuously monitor for long-running queries that is suitable for a comparative SQL Server novice. I know that it is possible to...
4
by: Gary | last post by:
I am having a problem executing long running queries from an ASP application which connects to SQL Server 2000. Basically, I have batches of queries that are run using ADO in a loop written in...
29
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using...
2
by: peteraguard-google | last post by:
Hi, I have a 120M record table that needs to have indexes added as a background process. While running the CREATE INDEX command, which is taking several days, all other SELECT queries on the...
12
by: strict9 | last post by:
Hello all, I'm writing several queries which need to do various string formating, including changing a phone number from (123) 456-7890. After some problem with data mismatches, I finally got it...
2
by: Gershon | last post by:
I have an ASP.NET/C# web application running against a SQL Server database using ADO.NET. Whenever there is a long-running database query, the web application hangs until the database query is...
4
by: ImSoLost | last post by:
I'm running a really long process from ASP.NET and need some help... I am making a method call when the user presses a button from my webpage, which goes into a database and parses a file. This...
9
by: Fish Womper | last post by:
I am at best a part time developer of Access databases. I use Access 2.0, as this is all my employer has on its computers. Even so, to use this ancient version requires a fairly convoluted...
1
by: Aaron West | last post by:
Try this script to see what queries are taking over a second. To get some real output, you need a long-running query. Here's one (estimated to take over an hour): PRINT GETDATE() select...
3
by: rfuscjr via AccessMonster.com | last post by:
This is truly bizzare. I have a query that runs for hours in one Access db. When I import it into another Access db, it runs in minutes. I compacted and repaired the original, relinked tables...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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.