473,774 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,:RECLENG TH
FROM SYSIBM.SYSTABLE S
WHERE NAME = :TBNAME
AND CREATOR = :TBCREATOR

The explain shows that it does a *full table scan* on SYSIBM.SYSTABLE S!
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.SYSTABLE S
WHERE NAME = 'X' AND CREATOR = 'Y'

or:

SELECT CARDF, RECLENGTH FROM SYSIBM.SYSTABLE S
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.SYSTABLE S with a primary key on CREATOR and NAME
5. I have not gathered stats (RUNSTATS) on SYSIBM.SYSTABLE S, 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 6742
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,:RECLENG TH
FROM SYSIBM.SYSTABLE S
WHERE NAME = :TBNAME
AND CREATOR = :TBCREATOR

The explain shows that it does a *full table scan* on SYSIBM.SYSTABLE S!
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.SYSTABLE S
WHERE NAME = 'X' AND CREATOR = 'Y'

or:

SELECT CARDF, RECLENGTH FROM SYSIBM.SYSTABLE S
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.SYSTABLE S with a primary key on CREATOR and NAME
5. I have not gathered stats (RUNSTATS) on SYSIBM.SYSTABLE S, 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
7612
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 files (with apache) from a directory off the file system, by setting the DirectoryRoot variable in httpd.conf. JBoss is working off a .WAR built from this directory. Is there any way to reference the unarchived files from Apache?
17
5029
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 cust_no, ded_type_cd, chk_no)
11
3039
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> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&that=this&when=now#21> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&when=now> Before I go offering it in public (and writing it into any number of the 'development kits'...
2
1690
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
1829
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 there is only one item in the list box (who's index is 0), it won't highlight (or at least, it doesn't show it on the screen). Here my relevant code: ' Load Product List
8
20369
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: Start with original thumbnails & two empty sub directories STEP 2: Create smaller versions of the originals for one sub directory STEP 3: Create thumbnail version of the originals the other sub directory STEP 4: Create an index.html pointing to the...
7
1563
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 that there are also static members and non public members. Could you please explain to me how the static method differs from others, how static members differ from others?
0
8062
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
1290
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 characters" end function sub callit() evaluate(activesheet.name & "()") end sub but the 255 char limit ended that...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10040
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.