Figure 1. BMC AMI Utilities for Db2
You might also want to take a look at this blog post from BMC that discusses how to Save Time and Money with Updated Unload Times
And this analysis of the BMC next generation REORG technology from Ptak Associates
You might also want to take a look at this blog post from BMC that discusses how to Save Time and Money with Updated Unload Times
And this analysis of the BMC next generation REORG technology from Ptak Associates
How do you delete N rows from a Db2 table?
Also, how do you retrieve bottom N rows from a Db2 table without sorting the table on key?
And here is my response:
First things first, you need to refresh your knowledge of "relational" database systems and Db2. There really is no such thing as the "top" or "bottom" N rows in a table. Tables are sets of data that have no inherent logical order.
With regard to the result set though, there is a top and a bottom. You can use the FETCH FIRST N ROWS ONLY clause to retrieve only the first N rows, but to retrieve only the bottom N rows is a bit more difficult. For that, you would have to use scrollable cursors.
A scrollable cursor allows you to move back and forth through the results set without first having to read/retrieve all of the rows before. I suggest that you read up on scrollable cursors in the Db2 SQL Reference manual and the Db2 Application Programming manual. All Db2 manuals can be downloaded in Adobe PDF format for free over the IBM web site.
Basically, you would want to FETCH LAST from the scrollable cursor and then loop through with a FETCH PRIOR statement executing the loop N-1 times. That would give you the "bottom" N of any results set -- sorted or not.
As for your other question, I am confused as to why you would want to delete N rows from a table. Doesn't it matter what the data in the rows is? My guess is that you are asking how you would limit a DELETE to a subset of the rows that would apply to the WHERE condition of the DELETE. The answer is, you cannot, at least not without writing some code.
You would have to open a cursor with the same WHERE conditions specifying FOR UPDATE OF. Then you would FETCH and DELETE WHERE CURRENT OF cursor for that row in a loop that occurs N times. Of course, that means you have to write a program to embed that SQL in.
Hope this answer helps...
Recently I was invited by BMC Software to participate in their AMI Z Talk podcast series to talk about modern data management for Db2... and I was happy to accept.
Anne Hoelscher, Director of R+D for BMC's Db2 solutions, and I spent about 30 minutes discussing modern data management, the need for intelligent automation, DevOps, the cloud, and how organizations can achieve greater availability, resiliency, and agility managing their mainframe Db2 environment.
Here's a link to the podcast that you can play right here in the blog!
Modern data management, to me, means flexibility, adaptability, and working in an integrated way with a team. Today’s data professionals have to move faster and more nimbly than ever before. This has given rise to agile development and DevOps - and, as such, modern DBAs participate in development teams. And DBA tasks and procedures are integrated into the DevOps pipeline.
I’d also like to extend an offer to all the listeners of this BMC podcast (and readers of this blog post) to get a
discount on my latest book, A Guide to Db2 Performance for Application
Developers. The link is https://tinyurl.com/craigdb2
There’s
also a link to the book publisher on home page of my website. Once you are there, click on the link/banner for the book and when you order from the publisher you can use the discount code 10percent to get 10% off
your order of the print or ebook.
A recent, recurring theme of my blog posts has been the advancement of in-memory processing to improve the performance of database access and application execution. I wrote an in-depth blog post, The Benefits of In-Memory Processing, back in September 2020, and I definitely recommend you take a moment or two to read through that to understand the various ways that processing data in-memory can provide significant optimization.
There are multiple different ways to incorporate in-memory techniques into your systems ranging from system caching to in-memory tables to in-memory database systems and beyond. These techniques are gaining traction and being adopted at increasingly higher rates because they deliver better performance and better transaction throughput.
Processing
in-memory instead of on disk can have a measurable impact on not just the
performance of you mainframe applications and systems, but also on your monthly
software bill. If you reduce the time it takes to process your mainframe
workload by more effectively using memory, you can reduce the number of MSUs you
consume to process your mission-critical applications. And depending upon the
type of mainframe pricing model you deploy you can either be saving now or be
planning to save in the future as you move to Tailored-Fit
Pricing.
So
it makes sense for organizations to look for ways to adopt in-memory
techniques. With that in mind, I recommend that you plan to attend this
upcoming IBM Systems webinar titled The
benefits and growth of in-memory database and data processing to be held Tuesday,
October 27, 2020 at 12:00 PM CDT.
This presentation features two great speakers: Nathan Brice, Program Director at IBM
for IBM Z AIOps, and Larry Strickland, Chief Product Officer at DataKinetics.
In
this webinar Nathan and Larry will take a look at the industry trends moving to
in-memory, help to explain why in-memory is gaining traction, and review
some examples of in-memory databases and alternate in-memory techniques that
can deliver rapid transaction throughput. And they’ll also look at
the latest Db2 for z/OS features like FTBs, contiguous buffer pools, fast
insert and more that have caused analysts to call Db2 an in-memory
database system.
Don’t
miss this great session if you are at all interested in better performance, Db2’s
in-memory capabilities, and a discussion of other tools that can aid you in
adopting an in-memory approach to data processing.
Register today by clicking here!
This month, October 2020, IBM introduced the latest new function level, FL508, for Db2 12 for z/OS. This is the second new function level this year (the first came out in June and you can learn more about it here).
With FL508, IBM adds support for moving tables from multi-table table spaces, both simple and segmented, to partition-by-growth (PBG) universal table spaces (UTS). For an overview of UTS capabilities and types, check out this blog post I made earlier this year: Know Your Db2 Universal Table Spaces.
Multi-table table spaces are deprecated functionality, which means that even though they are still supported, they are on their way out. So it makes sense for IBM to give us a better way to convert them to PBG UTS without having to experience an outage. And that is just what FL508 delivers.
This is accomplished in FL508 by enhancements to the ALTER TABLESPACE statement. A new option, MOVE TABLE, is delivered which, as you might expect from its name, can be used to move a table from its current table space to a target table space.
If, as you would expect in most cases, the source table space data sets are already created, the changes made by MOVE TABLE are pending changes and a REORG must be run on the source table space (the current one you are moving from) to materialize the change. Of course, this is an online REORG, so no outage is required.
The target table space must already exist as a PBG UTS in the same database as the current, source multi-table table space. Furthermore, the PBG UTS must be defined with MAXPARTITIONS 1, DEFINE NO, and [NOT] LOGGED and CCSID values that are the same as the current, existing table space. You can move only one table per ALTER TABLESPACE statement, meaning that each table in a multi-table table space must be moved with a separate ALTER TABLESPACE execution. However, because the changes are pending, you can issue multiple ALTER TABLESPACE statements, one for each table in the multi-table table space, and wait until they have all completed successfully before materializing all of the changes with a single REORG run.
It seems simple, and the functionality is nice, but don't just go willy-nilly into things moving tables all over the place once you get this capability in FL508. IBM has documented the things to take care of before you begin to move tables using ALTER TABLESPACE. Check out the IBM recommendations here.
It is also worth mentioning that you still need to keep in mind the impact that moving all tables from multi-table table spaces into their own table space will have on the system. By that I mean, you have to consider the potential impact on things like the number of open data sets (DSMAX ZPARM), DBD size, EDM pool size, and management issues (number of utility jobs, for example).
But it is nice that we now have a reasonable approach for moving tables out of deprecated multi-table table spaces so we can begin the process of moving them before they are no longer supported. A lot of shops "out there" have been waiting for something like this and it is likely to cause FL508 to be adopted quickly.
Let me know what you think by commenting below...