Here is a small testcase of the problem which I'm facing in prod env.
db2 =describe table tab1
Column Type Type
name schema name Length
Scale Null
------------------------------ --------- ------------------ --------
----- ----
-
VIN SYSIBM INTEGER 4
0 Yes
SOURCE_SYS_CODE SYSIBM INTEGER 4
0 Yes
SEQ_NUM SYSIBM INTEGER 4
0 Yes
3 record(s) selected.
db2 =select * from tab1
VIN SOURCE_SYS_CODE SEQ_NUM
----------- --------------- -----------
11 100 1
21 200 1
21 200 2
31 100 1
31 100 2
31 100 3
6 record(s) selected.
My requirement is to get only the following rows in the o/p [ select
only the combination of VIN & SOURCE_SYS_CODE which has the max seq_num
]
VIN SOURCE_SYS_CODE SEQ_NUM
----------- --------------- -----------
11 100 1
21 200 2
31 100 3
So I used the query
select VIN,SOURCE_SYS_ CODE,max(seq_nu m)as seq_num from tab1 group by
VIN,SOURCE_SYS_ CODE
However this query is behaving poorly in our prod env. Where tab1 is a
logically partitioned table on 7 partitions and VIN is the partitioning
key.
Access plan in prod is as below
Total Cost: 9.04494e+06
Query Degree: 1
Rows
RETURN
( 1)
Cost
I/O
|
3.96437e+08
DTQ
( 2)
9.04494e+06
1.6326e+06
|
5.66339e+07
GRPBY
( 3)
8.94897e+06
1.6326e+06
|
5.66339e+07
TBSCAN
( 4)
8.94296e+06
1.6326e+06
|
5.66339e+07
SORT
( 5)
7.9601e+06
1.10822e+06
|
5.66339e+07
IXSCAN
( 6)
1.07497e+06
583829
|
5.66339e+07
INDEX: SYSIBM
Any help is greatly appreciated.
Thanks, Sam. 3 1370
Sam Durai wrote:
Here is a small testcase of the problem which I'm facing in prod env.
[...]
So I used the query
select VIN,SOURCE_SYS_ CODE,max(seq_nu m)as seq_num from tab1 group by
VIN,SOURCE_SYS_ CODE
However this query is behaving poorly in our prod env. Where tab1 is a
logically partitioned table on 7 partitions and VIN is the partitioning
key.
Not sure why you think the query is *behaving* poorly. With the
information you provided there aren't really any options for a
better access path.
Poor performance is a different matter, and may be related to things
like physical tablespace design (esp. the system temp tablespace),
bufferpools, or sort memory (you are sorting approx 56M rows x 16
bytes).
I'm not sure. But, followings might be worth trying.
Because, I expect the possibility that DB2 first get result pairs of
(Vin, Seq_num) only by using the Index. Then get directly corresponding
Source_sys_code value from the table.
So, table scan can be eliminated.
CREATE UNIQUE INDEX tab1_1 ON tab1
(Vin, Seq_num);
SELECT Vin, Source_sys_code , Seq_num
FROM (SELECT Vin, Source_sys_code , Seq_num
, MAX(Vin) OVER(ORDER BY Vin, Seq_num
ROWS BETWEEN 1 FOLLOWING
AND 1 FOLLOWING) Next_Vin
FROM tab1) Q
WHERE Vin <Next_Vin
OR Next_Vin IS NULL
;
I'm sorry very much confusing you.
Please forget my previous post.
I didn't read following condition.
Where tab1 is a
logically partitioned table on 7 partitions and VIN is the partitioning
key.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nuno |
last post by:
Is there any SQL Error?
Or I have to use Select case in VB code to control SQL instead.
Thank you for any ans.
Nuno
|
by: Ian T |
last post by:
Hi,
I've got what I think (probably incorrectly) should be a simple SELECT :
Two colums with data like
col1 col2
1 50
1 51
2 50
|
by: jimh |
last post by:
I'm not a SQL expert. I want to be able to write a stored procedure
that will return 'people who bought this product also bought this...'.
I have a user table that links to a transaction table that links to a
transaction items table that links to the products table:
(User Table)
UserID
Other user data
|
by: serge |
last post by:
Using "SELECT * " is a bad practice even
when using a VIEW instead of a table?
I have some stored procedures that are
identical with the difference of one statement
in the WHERE clause. If I create a single View
and specify also in this View the WHERE clause
that is common in these stored procedures, I
will have the new stored procecures changed to
be like:
|
by: Andrew McNab |
last post by:
Hi folks,
I have a problem with an MS Access SQL query which is being used in an
Access Report, and am wondering if anyone can help.
Basically, my query (shown below) gets some records from a couple of
tables in my database using INNER JOINS and the WHERE clause to
specify the required constraints. However, I also want to read two
fields from a *single* record from a table called 'Locations' and then
apply one of these field's values...
| |
by: Dan V. |
last post by:
How can I use real SQL on a DataTable? i.e. not array of rows using a
filter... as in DataTable.Select.
I read at : microsoft.public.dotnet.framework.adonet
"As others have posted: There is no SQL query processor for DataSets. You
can use XPath with an XMLDataDocument built from the DataSet. You can also
perform selections based on criteria, using the Find and
Select methods, and you can create row filters using DataViews."
|
by: Silvio Matthes |
last post by:
Hello,
I'm new to the list and did not find a suitable answer to my question so
here it is:
I try to select the rows of a table where the content of a varchar-column
is empty ('') and PostgresQL is doing a seqscan.
I've tried this on a PostgresQL-Serverversion 7.3.4 and 8.0 beta1.
|
by: Rickster66 |
last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back"
I'm sorry for the late response. I've been gathering up information and carefully with as much detail as possible, making clear and straiforward for you.
I need to create 3 new queries based on the queries that you wrote. Each query has a numerical value and a textual value. The new queries are based on the queries with a numerical value. I...
|
by: paulmitchell507 |
last post by:
I think I am attempting a simple procedure but I just can't figure out
the correct syntax. My asp (classic) page runs a SELECT query to
obtain dates and ID's from 2 tables
uSQL = "SELECT cal_date, holiday_ID from Calendar, holiday_tbl WHERE
(((calendar.cal_Date) Between . And
.)) And Email_sent=0 AND Staff_ID=" & Staff_ID
This works fine.
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |