473,408 Members | 2,477 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,408 software developers and data experts.

Browsing whole table?


Folks,

Our client has a program that browses whole table from begining to end.
The table has 1 million rows in it. REORGCHK does not show any problems.
It has unique index defined on KEY0 column.

If I use SELECT statement without OPTIMIZE FOR clause, then it uses
temporary table to sort the data, but if I use OPTIMIZE clause then it
uses index access without temporary table. If I use OPTIMIZE FOR more than
700 rows then it uses temporary table again.

How can I influence the optimizer not to use temporary table?

If I use OPTIMIZE FOR clause then what will happen to the performance
after 700th row?

I will not be able to modify the program.

Thanks.

# db2expln -d test -f /home/db2modl/tmp/test.ddl -t

DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL Explain Tool

DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL Explain Tool

******************** DYNAMIC ***************************************

==================== STATEMENT ==========================================

Isolation Level = Cursor Stability
Blocking = Block Unambiguous Cursors
Query Optimization Class = 5

Partition Parallel = No
Intra-Partition Parallel = No

SQL Path = "SYSIBM", "SYSFUN", "SYSPROC", "DB2MODL"
SQL Statement:

SELECT REC
FROM MODL.EADMFN00
WHERE KEY0 >=?
ORDER BY KEY0 ASC
FOR
FETCH ONLY
Section Code Page = 819

Estimated Cost = 107.394234
Estimated Cardinality = 1856.888184

Access Table Name = MODL.EADMFN00 ID = 6,22
| Index Scan: Name = MODL.EADMFN00_ASC ID = 1
| | Regular Index (Not Clustered)
| | Index Columns:
| | | 1: KEY0 (Ascending)
| #Columns = 0
| #Key Columns = 1
| | Start Key: Inclusive Value
| | | | 1: ?
| | Stop Key: End of Index
| Index-Only Access
| Index Prefetch: None
| Isolation Level: Uncommitted Read
| Lock Intents
| | Table: Intent None
| | Row : None
| Sargable Index Predicate(s)
| | Insert Into Sorted Temp Table ID = t1
| | | #Columns = 1
| | | #Sort Key Columns = 1
| | | | Key 1: (Ascending)
| | | Sortheap Allocation Parameters:
| | | | #Rows = 1857
| | | | Row Width = 12
| | | Piped
| | | Duplicate Elimination
Sorted Temp Table Completion ID = t1
List Prefetch Preparation
| Access Table Name = MODL.EADMFN00 ID = 6,22
| | #Columns = 2
| | Fetch Using Prefetched List
| | | Prefetch: 50 Pages
| | Lock Intents
| | | Table: Intent Share
| | | Row : Next Key Share
| | Sargable Predicate(s)
| | | #Predicates = 1
| | | Insert Into Sorted Temp Table ID = t2
| | | | #Columns = 2
| | | | #Sort Key Columns = 1
| | | | | Key 1: KEY0 (Ascending)
| | | | Sortheap Allocation Parameters:
| | | | | #Rows = 1857
| | | | | Row Width = 744
| | | | Piped
Sorted Temp Table Completion ID = t2
Access Temp Table ID = t2
| #Columns = 2
| Relation Scan
| | Prefetch: Eligible
| Sargable Predicate(s)
| | Return Data to Application
| | | #Columns = 1
Return Data Completion

End of section
# db2expln -d test -f /home/db2modl/tmp/test1.ddl -t

DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL Explain Tool

DB2 Universal Database Version 8.1, 5622-044 (c) Copyright IBM Corp. 1991, 2002
Licensed Material - Program Property of IBM
IBM DB2 Universal Database SQL Explain Tool

******************** DYNAMIC ***************************************

==================== STATEMENT ==========================================

Isolation Level = Cursor Stability
Blocking = Block Unambiguous Cursors
Query Optimization Class = 5

Partition Parallel = No
Intra-Partition Parallel = No

SQL Path = "SYSIBM", "SYSFUN", "SYSPROC", "DB2MODL"
SQL Statement:

SELECT REC
FROM MODL.EADMFN00
WHERE KEY0 >=?
ORDER BY KEY0 ASC
OPTIMIZE
FOR 700 ROWS
FOR
FETCH ONLY
Section Code Page = 819

Estimated Cost = 238.005768
Estimated Cardinality = 1856.888184

Access Table Name = MODL.EADMFN00 ID = 6,22
| Index Scan: Name = MODL.EADMFN00_ASC ID = 1
| | Regular Index (Not Clustered)
| | Index Columns:
| | | 1: KEY0 (Ascending)
| #Columns = 2
| #Key Columns = 1
| | Start Key: Inclusive Value
| | | | 1: ?
| | Stop Key: End of Index
| Data Prefetch: Eligible 20
| Index Prefetch: Eligible 20
| Lock Intents
| | Table: Intent Share
| | Row : Next Key Share
| Sargable Predicate(s)
| | Return Data to Application
| | | #Columns = 1
Return Data Completion

End of section
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Apr 30 '07 #1
4 3696
WHERE KEY0 >=?
The optimizer ha to assume that on average you are selecting half the rows.
There are two way for you to improve that.
1. Use the REOPT(ONCE) or REOPT(ALWAYS) attributes to either train or
recompile teh query with real values.
2. use SELECTIVITY e.g: WHERE KEY0 >= ? SELECTIVITY 0.01 if you want to
bias the the assumption.
Note that you need to set db2set DB2_SELECTIVITY=ALL to get this to work

OPTIMIZE FOR n ROWS discourages the optimizer from using TEMPs or SORTs
because they delay the time it takes for teh first row to be returned.
In your case (possibly because your key isn't linked to a clustering
index) the optimizer figures that after hundreds or so random I/Os over
the table it has expended more resources than if it fetched the whole
table and then sorted it so it might as well..

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 30 '07 #2
Thank Serge, I will give it a try.

While stranded on information super highway Serge Rielau wrote:
WHERE KEY0 >=?
The optimizer ha to assume that on average you are selecting half the rows.
There are two way for you to improve that.
1. Use the REOPT(ONCE) or REOPT(ALWAYS) attributes to either train or
recompile teh query with real values.
2. use SELECTIVITY e.g: WHERE KEY0 >= ? SELECTIVITY 0.01 if you want to
bias the the assumption.
Note that you need to set db2set DB2_SELECTIVITY=ALL to get this to work

OPTIMIZE FOR n ROWS discourages the optimizer from using TEMPs or SORTs
because they delay the time it takes for teh first row to be returned.
In your case (possibly because your key isn't linked to a clustering
index) the optimizer figures that after hundreds or so random I/Os over
the table it has expended more resources than if it fetched the whole
table and then sorted it so it might as well..

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Apr 30 '07 #3

Serge,

When I use the SELECTIVITY clause with dynamic SQL it works, but when I
add it to my C program that uses host variable I get error while
running db2 PREP command:

LINE MESSAGES FOR BTRERE00.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
179 SQL20046N SELECTIVITY clause following "H00001
" can only be specified for a valid user-defined predicate.
SQLSTATE=428E5


While stranded on information super highway Serge Rielau wrote:
WHERE KEY0 >=?
The optimizer ha to assume that on average you are selecting half the rows.
There are two way for you to improve that.
1. Use the REOPT(ONCE) or REOPT(ALWAYS) attributes to either train or
recompile teh query with real values.
2. use SELECTIVITY e.g: WHERE KEY0 >= ? SELECTIVITY 0.01 if you want to
bias the the assumption.
Note that you need to set db2set DB2_SELECTIVITY=ALL to get this to work

OPTIMIZE FOR n ROWS discourages the optimizer from using TEMPs or SORTs
because they delay the time it takes for teh first row to be returned.
In your case (possibly because your key isn't linked to a clustering
index) the optimizer figures that after hundreds or so random I/Os over
the table it has expended more resources than if it fetched the whole
table and then sorted it so it might as well..

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: No************@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
May 3 '07 #4
Hemant Shah wrote:
Serge,

When I use the SELECTIVITY clause with dynamic SQL it works, but when I
add it to my C program that uses host variable I get error while
running db2 PREP command:

LINE MESSAGES FOR BTRERE00.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
179 SQL20046N SELECTIVITY clause following "H00001
" can only be specified for a valid user-defined predicate.
SQLSTATE=428E5
db2set DB2_SELECTIVITY=ALL
db2stop
db2start
Try again..
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 3 '07 #5

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

Similar topics

7
by: redneck_kiwi | last post by:
Need some opinions on how best to display in excess of 14K records based on users search criteria. Application Concept: ----------------------- User enters various search criteria (as many...
26
by: Dan Nash | last post by:
Hi guys I have a page that is *supposed* to list the directories on the server. Here's the code... folderspec = server.MapPath("./images/") set fso =...
4
by: Jurgen Haan | last post by:
Hello all you Gurus. I'm trying to find out how to fetch sequential blocks of data from a table in a most efficient way. Let's suppose the following: I have a reasonably large table (say...
8
by: UJ | last post by:
I have a table with multiple cells and I want to draw a box around the entire table but not around the individual cells. How do I do that? TIA - Jeff.
19
by: Martin Eyles | last post by:
Hi, I want to make a whole table a link, so that clicking anywhere on it takes you to another page. Unfortunately the way I initially thought of doing this involved invalid html. I have tried a...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
2
by: Joe Kovac | last post by:
Hi! I have a Web Site, where I turned directory browsing off. I want only one sub folder to be browsable: e.g. MyApp/Files/... How do I do that? Any setting in the web.config? Thanks Joe
1
by: martens | last post by:
Hi everybody, got the problem that one of my users cannot browse through the data of my database. He only sees 1/1. But I can browse through it seeing 1/457. So does somebody know if there is a...
3
by: Dan99 | last post by:
I am not sure if I should post this here or in a potgre group, but I will start here. I recently got a new server and thus when I copied all the files to the new machine, I logically decided to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
0
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...

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.