473,795 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Optimizer

In a cobol program I have an SQL instruction like following:

EXEC SQL DECLARE CURSORE_1 CURSOR FOR
SELECT CAMPO1,
CAMPO2,
CAMPO3,
CAMPO4,
CAMPO5,
CAMPO6,
CAMPO7,
CAMPO8
FROM TABELLA1

WHERE CAMPO3 = :CAMPO3 AND
(CAMPO8 BETWEEN :WS-CAMPO8-FROM AND :WS-CAMPO8-
TO) AND
(CAMPO5 BETWEEN :WS-CAMPO5-FROM AND :WS-CAMPO5-
TO) AND
(CAMPO1 BETWEEN :WS-CAMPO1-FROM AND :WS-CAMPO1-
TO) AND
((CAMPO1 :WS-CAMPO1-FROM) OR
(CAMPO1 = :WS-CAMPO1-FROM AND
CAMPO2 :WS-CAMPO2-FROM) OR
(CAMPO1 = :WS-CAMPO1-FROM AND
CAMPO2 = :WS-CAMPO2-FROM AND
CAMPO8 :CAMPO8XX-FROM) OR
(CAMPO1 = :WS-CAMPO1-FROM AND
CAMPO2 = :WS-CAMPO2-FROM AND
CAMPO8 = :CAMPO8XX-FROM AND
CAMPO4 < :WS-CAMPO4-FROM) OR
(CAMPO1 = :WS-CAMPO1-FROM AND
CAMPO2 = :WS-CAMPO2-FROM AND
CAMPO8 = :CAMPO8XX-FROM AND
CAMPO4 = :WS-CAMPO4-FROM AND
CAMPO5 >= :WS-CAMPO5-FROM))

ORDER BY CAMPO1,
CAMPO2,
CAMPO3,
CAMPO8,
CAMPO4 DESC,
CAMPO5
END-EXEC.
the table contains 16.000.000 records and during the execution of the
program, for this query, optimizer chose to create a temporary index
and indicate in the job log the key field used for building the access
path (I have in QAQQINI MESSAGES_DEBUG = *YES).

The field used for the key are the same ones of the ORDER BY and I
already have an index like this.
I don't know why the optimizer does not use the existing index (in
some conditions the query durations exceeds 5 minutes)
Can someone help me ?
Thanks

Feb 26 '07 #1
4 2708
Did you specify DESC for CAMPO4 in your index?

Feb 27 '07 #2
On 27 Feb, 06:07, "Tonkuma" <tonk...@jp.ibm .comwrote:
Did you specify DESC for CAMPO4 in your index?

the index created is:
CREATE UNIQUE INDEX TABELLAI1 ON TABELLA1
(CAMPO1, CAMPO2, CAMPO3, CAMPO8, CAMPO4 DESC, CAMPO5 );

like indicated in joblog...

Feb 27 '07 #3
How about this index? (Expecting more matching with WHERE clause)

CREATE UNIQUE INDEX TABELLAI2 ON TABELLA1
(CAMPO3, CAMPO1, CAMPO8, CAMPO5, CAMPO2, CAMPO4);

Feb 27 '07 #4
On 27 Feb, 11:51, "Tonkuma" <tonk...@jp.ibm .comwrote:
How about this index? (Expecting more matching with WHERE clause)

CREATE UNIQUE INDEX TABELLAI2 ON TABELLA1
(CAMPO3, CAMPO1, CAMPO8, CAMPO5, CAMPO2, CAMPO4);
thanks for the suggestion, unfortunately this index has no effects;

the message in joblog are:

The OS/400® Query optimizer considered all access paths built over
member TABELLA1 of file TABELLA1 ...
....
Following each access path name in the list is a reason code which
explains why the access path was not used. A reason code of 0
indicates that the access path was used to implement the query.
LIBRARY/TABELLAI2 5, LIBRARY/TABELLAI1 4
....
4 - The cost to use this access path, as determined by the optimizer,
was higher than the cost associated with the chosen access method.
5 - The keys of the access path did not match the fields specified for
the ordering/grouping criteria. For distributed file queries, the
access path keys must exactly match the ordering fields if the access
path is to be used when ALWCPYDTA(*YES or *NO) is specified.
....
....
A temporary access path was built to access records from member
TABELLA1 of file TABELLA1 in library LIBRARY for reason code 1
( Perform specified ordering/grouping criteria)
....
The access path was built using the following key fields. The key
fields and their corresponding sequence (ASCEND or DESCEND) will be
shown:
(CAMPO1 ASCEND, CAMPO2 ASCEND, CAMPO3 ASCEND, CAMPO8
ASCEND, CAMPO4 DESCEND, CAMPO5 ASCEND )
And this is the index TABELLAI1 already in the system...


Feb 27 '07 #5

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

Similar topics

1
2401
by: Nick Mudge | last post by:
Hi, Does anybody know the performance difference between having your PHP code cached and just running your code with the zend optimizer? Is there much difference? Nick
9
4750
by: hemal | last post by:
I came across a very strange situation at work. There is an order of magnitude difference in execution time for the following two queries (10 v/s ~130 msec): select count(*) from table_name where column_name = 'value' or 1 = 0 select count(*) from table_name where column_name = 'value' I do not want to go into the reason why the redundent condition exists, the example is representative of the real query where it
2
2354
by: gefek | last post by:
Hello, I've got a server postgresql 7.4.6 installed from RPM for linux RH 9. Lately, I've noticed, that some queries last too long... It appears to me, that the optimizer does not use index optimizing.... This is what analyze shows: ------ explain analyze update activities set act_synch_date='2005-02-03 00:00:00' where activities.act_id=17; QUERY PLAN...
3
1596
by: Philip Yale | last post by:
I'm very puzzled by the choice of NC index being made by the optimizer in this example. I don't actually think it should use an NC index at all. I have: Table: CustomerStatus_T Single data page 19 records Clustered Index on CustomerStatusID:
3
2097
by: Peter Arrenbrecht | last post by:
Hi all We ran into a very annoying optimizer problem recently. We had added a new key and self-join relation to a large production table. That key will be filled very rarely and having just being added was practically never filled in when the first user tried to delete a row from the table. Now, the optimizer tried to enforce RI on the new relation. But instead of using the index generated by the relation, it used a table scan!
9
2806
by: Andrea | last post by:
Hi, I've read the former postings but was not able to solve my problem: I have a Summary Table (or MQT as you like it) and the query optimizer does not seem to use the summary table. I run the following commands: set current query optimization 9;
5
3057
by: Kevin | last post by:
Using a base table, a MQT table was created. With optimization - when querying the base table with calcuation that are already completed in the MQT - I would assume the optimizer would use the MQT table instead of the base table. What causes the optimizer to use the MQT tables rather than the tables as defined by the query? Is there a way to "encourage" use of the MQT tables? Thanks.
2
3907
by: boa sema | last post by:
Way back when, and at least in version 7 IIRC, the query optimizer gave up when the where clause in a statement contained more than 4 search conditions. Does anyone know if such a limitation still exist in MS SQL 2005? The BOL seems to be silent on the issue. Boa
3
2376
by: aj | last post by:
DB2 LUW v8.2 FP 14 RHAS 2.1 Sorry if these are newbie questions. Optimizer stuff is black magic to me. For both of these, assume stats are current and an even distribution of data. ------------------------- Lets say I have a table FOO1 that has, among other columns, a column named A. There is a non-unique index on A that has medium selectivity. Lets also say I have a table FOO2 that has, among other columns, a column named B. ...
0
1668
by: P. Adhia | last post by:
Hi, Consider the following query select * from t1 where c1 = ? and c2 = ?
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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...
0
10001
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
9043
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...
1
7541
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
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.