473,395 Members | 2,253 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.

Static SQL SELECT FROM SYSTABLES with CREATOR and NAME = *doesn't*use index?

I bound my package with EXPLAIN(YES), and it's got the following static
SQL in it:

EXEC SQL SELECT CARDF, RECLENGTH
INTO :CARDF,:RECLENGTH
FROM SYSIBM.SYSTABLES
WHERE NAME = :TBNAME
AND CREATOR = :TBCREATOR

The explain shows that it does a *full table scan* on SYSIBM.SYSTABLES!
And the execution time seems to show that is what it is doing, it
takes about 3 seconds to get this 1 row executing this static SQL.

Using Visual Explain and putting in:

SELECT CARDF, RECLENGTH FROM SYSIBM.SYSTABLES
WHERE NAME = 'X' AND CREATOR = 'Y'

or:

SELECT CARDF, RECLENGTH FROM SYSIBM.SYSTABLES
WHERE NAME = ? AND CREATOR = ?

Both show an index scan (IXSCAN) to get the one row answer.

What is going on here? How could the query optimizer *not* be deciding
to use the primary key on CREATOR and NAME?

Here are some details to help:

1. DB2 7.1 on z/OS
2. Code written in C
2. bind variable TBCREATOR null terminated, defined as:
char TBCREATOR[9];
3. bind variable TBNAME is a VARCHAR type:
struct
{ short int TBNAME_len;
char TBNAME_data[18];
} TBNAME;
4. DB2 defines SYSIBM.SYSTABLES with a primary key on CREATOR and NAME
5. I have not gathered stats (RUNSTATS) on SYSIBM.SYSTABLES, so the
stats are all defaults (-1) on both the table and its indexes.

Any help would be appreciated.

- Gorilla

Nov 12 '05 #1
1 6708
I found the problem. The details below were not quite right.

The TBNAME and TBCREATOR bind variables were changed to work with DB2
8.1 as well (which has 128 byte names).

But this test was with DB2 7.1 which still has CREATOR AS CHAR(8) and
NAME as VARCHAR(18).

Due to the difference in the size of the bind variables, DB2 7.1's query
optimizer didn't use the primary index and reverted to a full table scan.

There are two possible ways out of this:

1. If you need to support both DB2 8.1 and DB2 7.1 (and earlier) with
the shorter names, have two code paths, one with 128 byte bind
variables and one with 8/18 length bind variables. I tested this,
and the access path is through the primary key.
2. Add FETCH FIRST ROW ONLY (or OPTIMIZE FOR 1 ROW if you need to
return multiple rows).

The second case here does something funny, but it's better than a full
table scan.

The PLAN_TABLE shows ACCESSTYPE=I and MATCHCOLS=0 which indicates a
nonmatching index scan.

So, because the bind variables were larger than the corresponding index
columns, DB2 reads every entry in the index (a "full index scan"),
returns the values from the index and evaluates the WHERE clause.

This would normally read the entire index, but that is probably faster
than a full table scan on the data. And, with FETCH FIRST ROW ONLY, it
will at least stop after the first row. Not too bad.

- Gorilla

Gorilla wrote:
I bound my package with EXPLAIN(YES), and it's got the following static
SQL in it:

EXEC SQL SELECT CARDF, RECLENGTH
INTO :CARDF,:RECLENGTH
FROM SYSIBM.SYSTABLES
WHERE NAME = :TBNAME
AND CREATOR = :TBCREATOR

The explain shows that it does a *full table scan* on SYSIBM.SYSTABLES!
And the execution time seems to show that is what it is doing, it takes
about 3 seconds to get this 1 row executing this static SQL.

Using Visual Explain and putting in:

SELECT CARDF, RECLENGTH FROM SYSIBM.SYSTABLES
WHERE NAME = 'X' AND CREATOR = 'Y'

or:

SELECT CARDF, RECLENGTH FROM SYSIBM.SYSTABLES
WHERE NAME = ? AND CREATOR = ?

Both show an index scan (IXSCAN) to get the one row answer.

What is going on here? How could the query optimizer *not* be deciding
to use the primary key on CREATOR and NAME?

Here are some details to help:

1. DB2 7.1 on z/OS
2. Code written in C
2. bind variable TBCREATOR null terminated, defined as:
char TBCREATOR[9];
3. bind variable TBNAME is a VARCHAR type:
struct
{ short int TBNAME_len;
char TBNAME_data[18];
} TBNAME;
4. DB2 defines SYSIBM.SYSTABLES with a primary key on CREATOR and NAME
5. I have not gathered stats (RUNSTATS) on SYSIBM.SYSTABLES, so the
stats are all defaults (-1) on both the table and its indexes.

Any help would be appreciated.

- Gorilla


Nov 12 '05 #2

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

Similar topics

1
by: Joshua McCulloch | last post by:
I have setup Apache 2.0.50 and JBoss 3.2.5 using mod_jk2. My application is defined to operate in the root context (http://servername/) by creating a WEB-INF/jboss-web.xml I am serving static...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
2
by: Timo | last post by:
Is there a way to give an image focus in Firefox? This works in IE and Opera: if (document.images('foo').focus) { document.images('foo').focus(); } Thanks Timo
6
by: Paul Sullivan | last post by:
Hi folks. I was hoping that someone can help me out here. I am adding items to a listbox from a database. So far, I've had no problems. However, when I try to use the SetSelected method and...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
7
by: gordon | last post by:
Hi I am learning C# from books. I am trying to understand the use of the word 'Static' on a method. When i look in the autos area (I often like to see what values are being resolved) i see...
0
by: ssims | last post by:
I've got a GridView that's sorted by a stored procedure with ROW_NUMBER: PROCEDURE dbo.GetCalendarsByStatusIDPaged ( @startRowIndex int, @maximumRows int, @statusID int ) AS
0
by: dave1 | last post by:
Probably an easy question for some. I'm trying to read the worksheet name, then use that name as a variable reference. Got this to work as a function with evaluate: function A() A = "255 plus...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
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.