Over the course of the past three weeks, I reviewed ZPARM settings (i.e., configuration parameter values) for three different production Db2 12 for z/OS environments at three different sites, and I noticed that index FTB (fast traverse block) functionality had been disabled in all three cases. I recommended to all three associated Db2-using organizations that they change the relevant ZPARM setting to re-enable FTB functionality, after first validating that the fixes for a set of related Db2 APARs have been applied to their Db2 12 code (the changes made by the fixes are part of the base Db2 13 code). My recommendation for you, if the FTB feature of Db2 has been "turned off" at your site, is to do the same: turn it on, after doing the aforementioned check of Db2 software maintenance if you're using Db2 12. In this blog entry, I'll explain what FTB functionality is, why it was disabled at some sites, and why it's time to go from "disabled" to "enabled" where feature deactivation has happened. I'll also provide information about the fixes (PTFs) that should be on your system to ensure the robust functioning of FTB-supporting Db2 code (again, if we're talking about Db2 12 - the base Db2 13 code has the solidified FTB functionality provided by the Db2 12 fixes).
The FTB raison d'etre: efficient use of non-leaf information in Db2 indexes
Db2 for z/OS indexes serve various purposes, such as assisting with maintenance of a desired ordering of rows in a table and ensuring uniqueness of key values for which duplicates would be problematic, but for the most part indexes in a Db2 system are there to speed the execution of queries (and of non-query SQL statements that contain predicates, aka search clauses). Indexes deliver this performance boost by enabling identification of query result set rows without a laborious row-by-row examination of values. It can be said that Db2 indexes provide shortcuts that get you to your destination (a query's result set) faster than would otherwise be possible.
The information in a Db2 index is arranged in what is known as a B-tree structure. The logical representation of this structure has something of the appearance of an upside-down tree: you have the root page at the top, and the leaf pages at the bottom. In-between the root page and the leaf pages of an index (unless the underlying Db2 table is quite small), you will have one or more levels of non-leaf pages. Finding a row in a table by way of an index on the table involves what is known as an index probe operation: Db2 starts at the root page and navigates down through the other non-leaf levels to reach the leaf page that contains the searched-for key value and the ID of the row (i.e., the row ID, or RID in Db2 parlance) or rows in which the key value can be found.
OK, so what is the value of index fast traverse blocks? Well, an index probe involves GETPAGE activity. A GETPAGE is a Db2 request to examine the contents of a page in an index or a table space (when the page in question is not already in a Db2 buffer pool in memory, the GETPAGE drives a read I/O request). The more rows a table has, the more levels an index on the table can have. More index levels means more GETPAGE activity associated with use of the index, and that matters because GETPAGE activity is one of the main determinants of the CPU cost of executing a query. Index fast traverse block functionality, introduced by Db2 12 for z/OS, improves CPU efficiency for query execution by reducing index-related GETPAGE activity.
An FTB reduces index GETPAGE activity by providing Db2 with a way to get to the leaf page of an index in which a query-predicate-matching key value is found without having to perform a top-to-bottom index probe. How that works: when Db2 builds an FTB structure in memory that is based on a given index, Db2 puts in that FTB structure the information in the non-leaf pages of the index (note that this is NOT just a matter of caching the index's non-leaf pages in memory - the FTB structure has a space requirement that is considerably smaller than what would be required to cache the index's non-leaf pages in an as-is manner); furthermore, navigation through an FTB structure does not require GETPAGE activity. Yes, FTB navigation does involve some instruction path length, but less than would be needed for the index GETPAGEs that would otherwise be required to get to a target leaf page. Let's say that an index on a large table has five levels. Retrieving a table row via the index will require six GETPAGEs - five for the index and one for the table space. If, on the other hand, Db2 has built an FTB structure from the index, when a query having a predicate that matches on the index's key is executed then Db2 can go to the FTB structure with the key value referenced in the predicate, and the FTB will tell Db2, "This is the leaf page in which you'll find that key value." Db2 then does one GETPAGE to examine that leaf page's contents, finds the key value and the associated RID, and does one more GETPAGE to access the row in the table space. Thanks to the FTB, we've gone from six GETPAGEs (five for the index and one for the table space) to two GETPAGEs (one for the index leaf page, one for the table space). Pretty good.
How is FTB functionality turned off, and why would anyone do that?
The FTB "on/off switch" is the ZPARM parameter INDEX_MEMORY_CONTROL. The default value for that parameter is AUTO. When INDEX_MEMORY_CONTROL is set to AUTO, Db2 notes the size of the subsystem's buffer pool configuration (i.e., the aggregate size of the subsystem's buffer pools) and says (figuratively speaking), "OK, I can create FTB structures from indexes, and the maximum amount of in-memory space I'll use for those FTB structures is equivalent to 20% of the size of the buffer pool configuration." Note that this is not space taken away from the buffer pools - it's net additional use of the z/OS LPAR's real storage by Db2. Consider an example: Db2 subsystem DB2P has 50 GB of buffer pools. If INDEX_MEMORY_CONTROL for DB2P is set to AUTO, DB2P can use up to 10 GB (20% times 50 GB) of memory for index FTBs. The size of the DB2P buffer pool configuration is not affected by FTBs - it remains at 50 GB. Got it?
Besides AUTO, another acceptable value for INDEX_MEMORY_CONTROL is an integer between 10 and 200,000. That would set the FTB memory usage limit in terms of megabytes. Using the previous example, if the z/OS LPAR in which subsystem DB2P is running is generously configured with memory, the organization might decide to set INDEX_MEMORY_CONTROL to 20000 if they want Db2 to be able to use up to about 20 GB of memory for index FTBs, versus the 10 GB limit established via the AUTO setting (20% of the 50 GB size of the buffer pool configuration assumed for the example). If, on the other hand, the z/OS LPAR's memory resource is quite limited, the organization might opt to set INDEX_MEMORY_CONTROL to 1000, to restrict DB2P's use of memory for index FTBs to about 1 GB (I say, "about," because 1 GB is actually 1024 MB).
INDEX_MEMORY_CONTROL can also be set to DISABLE. That has the effect of turning FTB functionality off. Why would someone disable a CPU efficiency-boosting Db2 feature? Well, relatively early on in the lifecycle of Db2 12 for z/OS (which became generally available in October of 2016), a few sites encountered some issues related to index FTB functionality. In some cases, use of an FTB was seen to cause a query to return incorrect output. These situations were pretty uncommon (recall that index FTB functionality is on by default, and most Db2 12 sites with INDEX_MEMORY_CONTROL set to AUTO encountered no problems in leveraging the technology), but they were real. Some organizations heard that other organizations had had some problems related to FTB usage, so they disabled the feature as a preemptive measure. I get it.
Why using FTB functionality makes sense now
In response to the FTB-related issues mentioned above, the IBM Db2 for z/OS development team created a number of code fixes that addressed the problems reported by Db2-using organizations. These fixes and their associated APARs (an APAR is an official description of a software problem for which IBM commits to providing corrective service) are noted in a blog entry, written by members of the Db2 development organization, that can be viewed at https://community.ibm.com/community/user/datamanagement/blogs/paul-mcwilliams1/2020/10/08/new-look-ftb-db2-12. If INDEX_MEMORY_CONTROL is set to DISABLE at your site, and if you are using Db2 12 for z/OS, check to see if the PTFs listed in this blog entry have been applied to your Db2 code. If they have been applied (or if you are using Db2 13), you can use index FTB functionality with confidence. If you are using Db2 12 and the fixes have not been applied in your environment, my recommendation is to get them applied, perhaps as part of a roll-out of a new and more-current level of z/OS software maintenance at your site.
The confidence that the IBM Db2 for z/OS development team has in FTB functionality, with the corrective maintenance applied, is evidenced by a couple of things. First, Db2 12 function level 508 extended FTB functionality to non-unique indexes (it had originally been limited to unique indexes). Second, Db2 13 for z/OS makes FTB functionality available for a larger set of indexes by doubling the key-length limit for FTB-qualifying indexes - from 64 bytes to 128 bytes for unique indexes, and from 56 bytes to 120 bytes for non-unique indexes (as previously mentioned, the code corrections made for Db2 12 by the FTB-related fixes listed in the above-referenced blog entry are part of the Db2 13 base code). The Db2 development team would not have made FTB functionality available for a wider range of indexes if they were anything less than highly confident in the quality of the FTB-supporting code.
Note that if you have INDEX_MEMORY_CONTROL set to DISABLE, and you're interested in turning FTB functionality on but would like to do so in a more-controlled and more-limited way before going to a setting of AUTO, that option is available to you. As noted in the blog entry for which I provided the link, above, and in the Db2 12 and Db2 13 online documentation, you can tell Db2, via a specification of (SELECTED, AUTO) or (SELECTED, n) for INDEX_MEMORY_CONTROL (where n would be a user-designated limit, in MB, on the memory that Db2 can use for FTB structures), that FTB structures can be built only for indexes that you have identified as FTB candidates by way of the SYSINDEXCONTROL table in the Db2 catalog.
In summary, if you have the FTB-solidifying fixes applied in your Db2 12 environment, or if you are running with Db2 13, and you have INDEX_MEMORY_CONTROL set to DISABLE, you should rethink that. The current FTB code is very robust, and if you don't leverage the functionality then you're leaving CPU savings on the table. I'd prefer to see you realize those CPU savings.
Very well explained about FTB .
ReplyDeleteCouple of questions
1.Is FTB useful only for smaller sized indexes ?
2.If you have 50% of your indexes are in memory (PGSTEAL(none) Bufferpools) , do you think it will be beneficial to use FTB ? Compare to the extra memory vs CPU benefits .
3.Do you know any client using FTB and getting CPU benefits as mentioned by IBM ?
1) Index size is not a limiting factor with regard to FTB functionality. Index key length is a limiting factor.
Delete2) If the LPAR's memory is not constrained (i.e., if the LPAR's demand paging rate is less than 1 per second), the extra memory used for FTBs would not be a concern for me. Yes, I would still expect some CPU benefit from FTBs, as even when an index is completely cached in a buffer pool there is still GETPAGE processing needed to navigate through the index. GETPAGE processing is not required for navigating through an FTB.
3) Yes. Keep in mind that FTB functionality is "on" by default in a Db2 12 (or 13) for z/OS environment. To not use FTB functionality, you have to set INDEX_MEMORY_CONTROL in ZPARM to DISABLE. In my personal experience, many organizations left the value of INDEX_MEMORY_CONTROL at the default value of AUTO, and they therefore utilized FTB functionality. That functionality has led to CPU efficiency gains.
Robert
Thanks Robert !
DeleteHello Robert
ReplyDeleteTo activate FTB we have to change INDEX_MEMORY_CONTROL=AUTO
and do a SET SYSPARM RELOAD (the manual says it is online changeable).
Is that all?
That should do it. Note that this will of course lead to additional use of virtual and real storage by Db2 for z/OS, for the FTB structures it builds. This should not be an issue for you, as long as the z/OS LPAR in question is not memory-constrained (and I would say that a z/OS LPAR is not memory-constrained if its demand paging rate is consistently below 1 per second).
DeleteRobert
Central storage seems okay:
DeleteRMF monitor shows 12M available frames , and DBM1 is allocating 2.3M pages.
That means FTB will allocate 460K pages...
Thank you Robert!
I wouldn't go by DBM1 usage of real storage, as not all of that is for buffer pools. Determine the size of the Db2 subsystem's buffer pool configuration by multiplying, for each buffer pool, VPSIZE by the size of buffers used for the pool (4 KB, 8 KB, 16 KB or 32 KB), and then summing all those individual buffer pool sizes. 20% of that will be the default limit on memory that Db2 will use for FTB structures.
DeleteAlso, while available page frames is a good thing to know for a z/OS LPAR, the metric I think is most important for monitoring the level of real storage usage is the LPAR's demand paging rate (available via an RMF Summary report - see https://robertsdb2blog.blogspot.com/2023/02/two-rmf-zos-monitor-reports-with-which.html).
Robert
Okay Robert
DeleteThank you for these valuable tips!
Hi Robert,
ReplyDeleteTo monitor FTB, we use DISPLAY STATS(INDEXTRAVERSECOUNT). This gives a count of the Traverse Count of the count. But the question is : what is the timeframe for this count?
For example: if ITC gives a count of 1000, then does that mean 1000 times Index was traverse in last 2 mins (As FTB checks for threshold every 2 mins) or does that mean 1000 times Index traversed in last 1 hour or does this count indicate since the last time stats were run on the Index?
My understanding is that this value is continuously maintained - i.e., it is not based on a time interval. Keep in mind that it is not necessarily a continuously-ascending value - the value will be decremented when an index is accessed in a sequential manner, or when the index has a page split operation.
DeleteRobert
Hi Robert
ReplyDeleteWe have enabled FTB in one of our system. But we are seeing the Trav. count as below for all the indexes. also when displaying INDEXMEMORYUSAGE it doesn't return any rows..what does this indicate.
TRAV. COUNT
----------
-000000001
What is the value of INDEX_MEMORY_CONTROL in ZPARM for this Db2 subsystem? What is the form of the command -DISPLAY STATS that you issued to get index traverse could information?
DeleteRobert
INDEX_MEMORY_CONTROL is set to AUTO and I am using the below command
Delete-DISPLAY STATS(INDEXTRAVERSECOUNT)
On the test Db2 for z/OS system that I use, I have seen the value -0000000001 in the FTB FACTOR column of DISPLAY STATS(INDEXTRAVERSECOUNT) output, but not in the TRAV COUNT column. My guess is that this is an indication that Db2 is not collecting this statistic for a given index. Why would that be? I'm not sure. Maybe a lack of activity for the index in question - or at least a lack of traverses versus scans (which could be the case for some indexes on small tables). In any case, I don't see that the meaning of the value -0000000001 is documented - you might need to open a case with IBM support to get information on this. Alternatively, you could contact the IBM Db2 for z/OS documentation team at db2zinfo@us.ibm.com, and report that this value (for traverse count and for FTB factor) is not documented and request that the documentation provide an explanation for the value. Over the years, I have found the Db2 documentation team to be very responsive to these communications.
DeleteRobert