Db2 User Group | July 2026

Mastering Access Path Management in Db2 for z/OS:
Simplify, Optimize, and Succeed

This session explores strategies for simplifying and optimizing access path management in Db2 for z/OS environments. Attendees will gain insight into techniques for improving query performance, reducing operational complexity, and supporting more efficient database administration practices.

The discussion will focus on practical approaches to tuning and optimization that help organizations improve performance, reduce technical debt, and maximize the value of their Db2 infrastructure investments.

Read the Transcription
Amanda Hendley
Welcome. My name is Amanda Henley. I am your host for today’s virtual mainframe user group. I am with Planet Mainframe, and today we are talking about mastering access path management in Db2 for z/OS. Simplify, optimize, and succeed. And as we get going today, I wonder if you would be so kind as to drop your location into chat. I’d love to see where some of you are coming from. I am in the Atlanta, Georgia area, actually, so we are right at midday here. Awesome. Thank you. Great. Also another Atlanta. Look at that. Denis, do you see anyone close to home? Sorry, I was wondering if you saw anyone close to home in chat.

 

Denis Tronin
Uh, not yet. I see people from Europe, which is good.

 

Amanda Hendley
Great. Well, I do have my email address on the screen, ahenley@planetmainframe.com. I want to encourage anyone on today’s session to send me the Db2 topics that you want to hear about. It will help us develop our calendar as we move forward. And before we get going with our session, I just want to do a quick plug for a webinar I’m doing next week. It’s part of what the Persona Series, What Mainframe Teams Can Learn from Each Other, and we’ll be talking about accelerating mainframe efficiency next week. And this particular session will be targeted at training and on-boarding and education. So I do hope you’ll join us for this free webinar series. And if you’re interested in the SysProg DBA session that happened about a month ago, you can check that out at planetmainframe.com. And as we get started today, I’ll throw up some links so you don’t necessarily have to scan the QR code. But I think we’re about ready to get started. Again, there’s my email address. For, um, for call for sessions. Also, I should mention, you can tell me what sessions you want to hear, but if you have a session you’d like to present, I’m happy to talk to you about that as well.

 

Amanda Hendley
So we are here for, um, as I said, Mastering Access Path Management. I’m going to stop my share, Denis, so you can start your share, and I’ll introduce Denis as he does that. So Denis is a seasoned product manager in Broadcom’s mainframe software division. He has years of experience in product management and software development, and his work focuses on mainframe technologies, particularly in data management and DevOps domains. He has— is an IBM Champion for Analytics since 2016. So let me make sure you’re all set on your screen share, and I will turn it over to you, Denis.

 

Denis Tronin
Okay, do you see my screen?

 

Amanda Hendley
It looks great.

 

Denis Tronin
Okay, so first of all, thank you for having me and welcome everyone. I saw some familiar names, so don’t hesitate to bring the questions as we go. So today I want to talk about the mastering access pass management in Db2 for z/OS. So I will give you some of the overview and talk about some techniques that you can apply for establishing and more importantly maintaining the access pass in Db2. So what are we going to talk about? Generally, I will refresh you on what the query access pass is, how to deal with that. We will look more into the explain, how you can get the details about the access pass. And then dive into the course of the how to set the plan management policies, how to work with those. And the big chunk of the presentation will be about the optimization hints, the techniques you can use to stabilize the access paths or apply the access paths. And again, don’t hesitate. I always like to have it more interactive, so Amanda will be looking at the chat and if anything I hope Amanda will ping me.

 

Amanda Hendley
Absolutely.

 

Denis Tronin
Okay, so talking about the access path, what it is, I like to talk about that as this is basically the program that is built for us, SQL statement, so that the Db2 itself can execute when processing the query. Because if you look at the query, it just doesn’t tell it basically defines how to retrieve the data from the database, but it doesn’t say how to do that. This is where the important Db2 component, Db2 Optimizer, steps in. That looks at multiple factors related to the SQL, including SQL tags, statistics, indexes, and then decides how to translate that SQL query into an executable form. Typically, that executable form is created and stored in the catalog. Probably you all know the common access paths like tablespace scan or index scan, index-only access. I will not go into these details too much, just give you some high-level overview. But what is important to think of is when the access path is established. And that would be different for the dynamic and static statements, right? Dynamic statements come randomly typically to the Db2. So if you have a remote connection to Db2, let’s say from JDBC, or you can, even if you go to the standard SPUFI, those are all dynamic statements.

 

Denis Tronin
So whenever that comes to Db2, Db2 runs prepare, and then executes them. More reliable, more stable statements are static. Those, you know, access path for those established when we bind the package or rebind it. And in this case, access path, you know, is preserved in the package in the catalog. So anytime we need, I mean, Db2 sees the statement, it basically reads that package and executes that. So talking about the queries and the access path. What are the factors that influence? And no surprise, SQL text would be one of the most important things, right? What predicates you use in your statement, you know, do you have the subqueries, how you join the tables, do you use the host variables or not, if you use the functions and etc. Another one, the most common optimization mechanism for queries to access the data is through indexes. So see if there are indexes, and if you have multiple indexes, which indexes to use. This is what all, you know, influence the access path. Another one, optimizer needs to know how big the objects it works with, right? So statistics, you know, frequency of the state of the variable, of the values.

 

Denis Tronin
So all of that has an impact on the access path. The system setup itself, you know, what are the ZPARMs you use, how big your machine from the capacity standpoint, how many CPUs you have, how big your buffer pools. So all of that, you know, play into the access path selection. And the last but not least, you can also influence the access path selection by providing the hints to an optimizer. So this is something you can use, and we will talk quite a bit about that. Okay, going further. So the access pass itself, if you think of it, this is a program, right? Stored in Db2. But how we can understand what that program is doing? We need to externalize this access pass for analysis. It is done through an explain, right? Obviously it works for the DML statements only. So I know how much you’re familiar with Explain. Hopefully most of you are familiar. So Explain, ultimately what it does, it looks at the statement, talks to the optimizer, and externalizes it into db2_tables. So there are about 20 Explain tables, you know, that reflect different steps of the SQL execution. So, and Db2 populates those tables when it processes the statement.

 

Denis Tronin
Right? So you can do it, you know, when you just explicitly run explain statement. So it’s like an optimizer, give me the access path for that statement as if, you know, you would execute it now. If you talk about the static statements, when you bind or rebind the package, if you specify the explain yes on the bind cards, then, you know, you will capture the access paths. And if you’re running dynamic statement queries, you can set the special register current explain mode to yes or explain, and that would influence, you know, will tell Db2 to, you know, along with execution of the statement, just capture the access path. So while it’s, you know, that statement existed for quite some time, there were some changes and not everybody aware of some of the, you know, relatively new things to that. So the most classic one is explain plan. Where you rather specify the query number and the SQL text, which is a common thing. I used to call it future explain. It means optimizer decides how the statement will be executed if it comes into Db2. However, there is a set of parameters, what I call current explain.

 

Denis Tronin
In this case, it means the access path was defined earlier, it’s stored somewhere, and now it’s just about externalizing that into the explain tables. So good example of that, EXPLAIN STATEMENT CACHE. Means the dynamic statement got executed in Db2, the access path was selected, and Db2 cached that in the global cache. So through this command, you extract the content of the cache into EXPLAIN tables for analysis. Another option is EXPLAIN PACKAGE. So it’s, you know, quite underutilized, so you all should consider that. So if you have a package, that was bound early and there is no EXPLAIN YES parameter specified, means there is no access pass for that. You can still capture the access pass for that package if you run EXPLAIN PACKAGE and you provide the package details on them. It will extract it from the Db2 catalog and will make it available for you for analysis. And the last and not least, so if you have a stabilized dynamic statement, then you can get the access pass for that statement as well. So as I was saying, you know, there are 20 explain tables as of Db2 13. These tables are user-specific, so you need to create them.

 

Denis Tronin
So, and schema should match the SQL ID of explainer. I will not list all the tables, but I will talk about a few of them, actually 5 of them. So, so PLAN table, that’s probably the most important table, major one that contains information about the access path methods. And by the way, this is the only table populated for EXPLAIN PACKAGE. So if you have package that was bound without EXPLAIN, if you run the EXPLAIN PACKAGE command, that’s the only table that will get populated. But at least you will know some of the access path information. You’ll be able to figure out if it is the, you know, table scan or index scan. So very good input. The SAM statement table, that’s where you get the cost estimation per statement. So you will see what Db2 thinks how much it will cost. So function table, we’ll skip it, so information about the UDFs. The SAM statement cache table, that contains information that is extracted from the cache. So if you have the enabled traces for the dynamic statements 3.16, then you get the statement cache text, text for the statements from that into this table. So you can look what are the statements stored in the cache.

 

Denis Tronin
Predicate table, kind of information about the predicates, very important when you do the in-depth tuning. And one important, DSense stats feedback. We’ll talk more about that. It provides you information about what information is conflicting or missing around the statistics. And what you can do to fine-tune that. So, but before we go, you need to create those tables. There are multiple ways of doing that. The DDL for these tables is distributed with Db2 itself. So if you go to the SMP DSN SAMP library, you will find the DSN TESC member where the DDL is stored. I personally prefer running a stored procedure. So if you’re familiar with those, Db2 comes with about 60 stored procedures. So sysproc.admin_explain_main, explain main. And this is a very nice procedure that lets you create, drop, upgrade your EXPLAIN tables, all of them or subset of them. So this is relatively older snapshot that I was using back then with Data Studio where I could create those. Now I just have a small REST API wrapped around this stored procedure to do that. Always you can go to your tooling. So if you use tools like CC4DB2 or, you know, Plan Analyzer or, you know, any other vendor tool, typically they also provide you native support for creating the explain tables.

 

Denis Tronin
Okay, so, and really quickly walk you through the major tables. So a plan table, that major information about the access path. So you will see how many blocks constitute the access path, right? So query block 1, 2, 3, 4, basically building a tree for the statement execution. So you will see the blocks, you will see the steps, you will see most important access paths, you will see if it’s table scan, index scan, how many matching columns is used, whether there is join used, whether the sort involved, and you will see the objects participating in each of the blocks. So that’s the base path analysis that you will take from the plan table. Hopefully everybody is familiar with that and can interpret it. The cost is stored in the statement table, right? So this is very important. So first there is a credentials information to correlate you of the statement. And all of these explain tables are related, but you need to look how to correlate them. So it’s typically statement number, timestamp, plan, package, and et cetera. So in this table you will see what is the query type, if it is insert, select, encoding used, but very important, the cost estimation, right?

 

Denis Tronin
So you will see the cost itself in the milliseconds and service units and the cost category. So if you have A, which basically means that optimizer didn’t have to guess too much. It had enough statistics to give rather, you know, good estimate. If you see the category B, means it was not having enough information, so it was using some of the defaults like a filter factor, so you know how big the table is. If there is no information, it will, you know, look into that and give you the reason why the category B was selected, right? Whether kind of table cardinality was known, you know, host variables involved, and etc. Also, as we’re going to talk about the plan management, access path management, so it will tell you if the access path was determined by using, you know, compare or reuse, you know, functionality. So how you interpret the access path? Since information is stored in the table, you can— in tables— they can obviously use your own SQLs. So do SELECT, you know, FROM plan table, you know, JOIN, you know, statement table, JOIN predicate table, or just call them one by one. Of course, easier way, if you have any tools, then use the tooling.

 

Denis Tronin
So it could be textual, like example here, I think from sysu4db2, where I took my statement, tells me, you know, interpreting you have a SELECT, you know, it’s estimation. In this case, you see category B because it says using default values, etc. Or if you again have a tool that visualizes that, it’s even better. For complex statements, it is better to look at the visual representation. Okay, so far so good. And if any questions, if anything, you know, capture your attention, please speak up.

 

Amanda Hendley
There’s a quick question about, this is for Dynamic SQL only.

 

Denis Tronin
No, not at all. So if you have static statements that you store in the catalog, then you can still retrieve this information either directly reading the plan table and the rest of the tables, or if you run explain package, for example, that you’ll retrieve it and store it and then you interpret it. So it is both for dynamic and static fully. Okay, thank you for the question. If you know, if it is not sufficient, you know, put the follow-up question in the chat.

 

Amanda Hendley
And another question came up after that: is there a way to execute a stored procedure from RC Query?

 

Denis Tronin
From the RC Query? Not from the RC Kubernetes to my knowledge, but you can go to ISQL and I think you can run it from there, but I will need to double-check. So I can go back and see because my background really lays in the performance tools and now more in the utilities. So not too much familiar with our admin tools. But I can follow up.

 

Amanda Hendley
Okay. Another question popped up. Do you want to— Sure.

 

Denis Tronin
Yeah, go ahead.

 

Amanda Hendley
Take it?

 

Denis Tronin
Okay.

 

Amanda Hendley
Will there be any difference between giving host variables as— sorry, it’s cut off on my screen for some reason— as CWC value against the column or giving column name equals value in terms of performance?

 

Denis Tronin
Oh, I’m sorry, not CWC, it’s, okay, I will, I will need to see that. Hold on, give me a second. So I read the question because otherwise I’m bad at audio. Just a second. Will be any difference between giving host files From, you know, performance of what, the statement itself or the explain? So obviously if you have a literal, then optimizer will know what the statistic compare, while for the host variables it doesn’t know what the value might be. So in most cases for the host variables, it will be kind of guessing. So having the concrete value is better. From the access path selection. However, you know, you can also run— we have some, in case of static binds, you can use the reoptimization parameter. So I will cover it a little bit. Okay, and thank you for the questions. You know, all right, let’s go further. If anything, bring it. Okay, so we talked about the access path selection and, you know, how to interpret it. Oops, I’m trying to hide the chat now. Okay, now I see. So one of the major influences for the, you know, access path selection is statistics, right?

 

Denis Tronin
And up-to-date statistics typically help Db2 to choose an efficient access path. And the change in statistics obviously will impact the access path selection. But at the same time, excessive statistics or, you know, very complex statistics like histograms and so on, they might slow down the optimizer. It will also impact the binds and prepares. So as everything in Db2 depends, so if you collect too much of statistics, it would be, it could be a problem, especially if you have outer binds or, you know, when you have a Db2 startup and a lot of statements come into the Db2. So that’s where it might be impacting. But generally having the statistics is the good thing, right? So statistics is collected by running the runstats. That’s the statistic used for the access pass, right? Not the RTS, runstats. If you run the runstats, better not run it standalone. Preferably do it inline with the load and reorgs. And why so? Because at that moment when you reorg or you load replace, your object in its kind of perfect state, right? So you want to have the statistics collected at that time till your data got skewed. You can automate stats collection, so you can use either tools like Database Analyzer, or there are also admin procedures for that, or you can use the DSAnacox and etc.

 

Denis Tronin
Another important point about the run stats: don’t collect inline statistics as part of your index, do it as part of the table. Okay? And one more thing about the statistics, it is changeable. So if you go to the catalog, look at those tables, they’re updatable, right? So you can use this trick to preserve or migrate statistics as part of the tuning exercise. But please don’t use the— don’t change the statistics for the access path selection. Okay, so just because reason is obvious, since you change the statistics for an object, it impacts multiple objects. Okay, so be careful with that. Okay, so How do we know if there is enough or not enough statistics, if statistics are good or not? You know, look, look at the DSN stats feedback table. So this, this table contains information that Optimizer populates to tell you whether there are any conflicts. So you will see information about object columns, the type, you know, what the statistics is, is suspicious, and the reason. Right? So if you have some questions about it, just run explain and look at the descent statement feedback. You can also have it for everything. So there is a catalog table, sysibm.sys_stats_feedback table, and it is updated at the stats intervals, right?

 

Denis Tronin
You can enable it by having start of the zparms enabling it. So stats feedback scope enables it for the dynamic or static or all statements. Okay, and also on the table level you can control. So in the sys tables there is a column that says whether it is enabled or not for a table. Also you can automate some of the statistics processing. So there is a sys feedback profile. So if you enable creation of stats profiles then, you know, you set the interval and when those profiles get automatically created, then the run stats cleans up that, you know, feedback table. Just one please cautious, we just lately had a case where the customer used the run stats use profile. This is how you say, oh, for that object, when you run the statistics, you don’t need to guess what parameters need to set, right? You know, you take information from Sys feedback by creating profile. When you run it, it actually removes all non-profile statistics, so you should be careful with that. And I see there is a question from William. Let me see. Any question or— okay, in the chat. For new, what about the default Statistics for new objects.

 

Denis Tronin
I’m not sure I understand the question. So if you create an object, you know, by default there would be no statistics. So you better run the run stats as soon as, you know, there is a decent amount of data in those, if that was the question. If not, put it in the chat.

 

Viewer
Well, my question is, is it if you got at a table, right? Let’s say you’re in development and there’s no data, right?

 

Denis Tronin
Yeah.

 

Viewer
And you know, and it’s new, so you don’t know what the data is going to be like.

 

Denis Tronin
Okay.

 

Viewer
So, you know, all those stats would be negative 1. So it’s probably better to use those defaults. Statistics as opposed to running RUNC stats and have zero stats. What are your thoughts on that?

 

Denis Tronin
Yeah, I would agree. So if you expect the table will grow drastically, right, then it’s better to collect statistics when there is data. Alternatively, if you have the— if this table is basically cloned from your production environment, then migrate the statistics from prod to dev. That would be better. That’s where I talked about the migration statistics. You just move it as part of the tuning SQL exercise.

 

Viewer
Okay, thank you.

 

Denis Tronin
Yeah, you can also leverage system profiles to emulate the environment in test as in prod. You can emulate number of processors and speed of processors and the buffer pool sizes and etc. So it could be robust. But thank you for the question. Okay, going further. So we talk a little bit about statistics. So now going into the management, actually access pass management. So hopefully you know that, you know, you can have multiple package copies, right? That’s where the access pass is preserved. So there is a extended, basic, and auth values that you can set for the plan management. It is a rebind parameter plan management. The default is extended, so I hope most of you using the extended. Indeed. So extended means there are 3 package versions, package copies are preserved always. Original, that the first bind that happens, then the current. So every time you rebind you update the current version of a current copy of a package and the previous. So when you rebind, current moves into previous, previous is thrown away, and current is refreshed. So you have three. So you get the very first one and you basically switch between your current, previous, current, previous.

 

Denis Tronin
If you have basic, you only have current, previous, so not, no, no original preserved. And now you only have current. So most of you hopefully use the extended There are also additional parameters that you can use, like, you know, IP, you know, duplicates. So if you want to have the identical copy stored or not. Strongly recommend you have the extended, it’s for your safety, and you will see why. So as the very first and simple thing to deal with the access path changes, if you rebind the package and you ended up with a bad access path, if you have extended plan management policy, you can easily switch. Just switch to the previous or to the original copy of a package. So have it as a means in your pocket to switch between the package copies. Right, very simple. So say, you know, switch. If you specify previous, then current and previous is changed. If original, then current goes to previous, original goes to current. This is the only option that you can use if you want to use switch. It’s, you know, the only parameter you will use. You can get rid of the, you know, older or inactive copies if you want to.

 

Denis Tronin
So you can free if you feel like, you know, there are too many copies stored, then just, you can release it. But just be careful, you know, free what you didn’t want to free. So I’d guess having multiple copies and, you know, switch would be your first way how you can handle the, you know, access pass management. Okay, going further, how you can control it more intelligently. So imagine you have still a bunch of packages that you need to rebind, so, but you want to avoid, you know, drastic changes, or, you know, because typically you rebind either to get better access paths, or you rebind because of some major changes, or get, you know, run runtime structures to be refreshed, and etc. So you can apply two strategies with the bind-rebind. With this, you can use the IP compare and IP reuse. IP compare is your indicator to tell you whether there is a change in access path or not. That’s all it says. IP reuse saying, you know, try to make sure you get a very same access path as before, right? So IP compare is just a flag. IP reuse is a mechanism to have a similar access path.

 

Denis Tronin
And each of these, you know, rebind parameter stake and bind parameter stake, you know, warn or error. So warn means you get a notification in case of IP compare that there is a change. Here is, you know, this package access path has changed. Error, sorry, bind or rebind will fail if there is a change identified. No, doesn’t matter for good, for bad, just a change. IP reuse is more like, oh, it will notify you if it couldn’t establish very same access path as before. So it will notify you error, it just will fail. Interestingly enough, it can still generate the very same access path, but not through the mechanism, and it will warn you. So it’s better always to use these two in combination, and I will talk more about how. I’m just giving you a couple examples of messages that you would see when you have those, you know, APDU and compare in action. So the first screenshot, you know, about the APDU, and another one is AP compare, just tell you, you know, what’s happening, how many statements, you know, were analyzed. So it is always, as I was saying, better to use that in conjunction.

 

Denis Tronin
So if your strategy to get the changes to the access paths but know what has changed, right? 100 packages, I still need to rebind them, but I at least need to know where was the impact. So just run it with the ap compare warn and you will know what access path for what packages has been changed. And if there are other changes, you can use the switch to, you know, go back to the previous access path. However, if your strategy is, you know, more care, right? You know, not care, I would say more conservative. That’s the word. So get the access pass where possible, right?

 

Viewer
Old one.

 

Denis Tronin
But still, if you know you cannot get the old access pass, give me the new one. That’s still okay, right? So use the combination IP reuse warn and IP compare warn. When you set those two, you still get the changes, but you will reduce number of changes because it will imply that IP reuse force is getting the very same access pass. If you really want to avoid any change in your, you know, access pass for packages, run with error and to prevent any changes, right? It will rebind some of the packages, but, you know, the ones that cannot get the very same access pass, they will just not be bound. So think what is your strategy depending on the situation. You can use combination of these parameters. A few more words. You can also combine these parameters with explain only or explain yes to analyze the access pass changes. So you can look at the plan table. So there is a hint used column. You will see whether the, you know, IP reuse was used or not. If you get a failure in the plan table, the remark column, you will see the reason why..

 

Denis Tronin
And as I was mentioning in the statement table, also you will have, you know, note whether that was IP reuse or IP compare. So during the explain, you can capture that information as well. So hopefully you’re ready to start thinking about the plan, how we can use these two in order to, you know, apply some of the, you know, rebind and bind strategies with those.

 

Amanda Hendley
Okay.

 

Denis Tronin
So this works really well with static statements, with packages, right? But we all know the challenges and more complex situation is around the dynamic statements, and the rest will be very much about the dynamic. So I want to walk you through the dynamic SQL statement stabilization. This is the attempt to implement similar approach as with the plan management. For the dynamic statements though. I think it was introduced in Db2 12. So it is then, I guess you’re all on Db2 13 now. So this is definitely available for you and consider. So what it does, it will take the dynamic statements from the cache and basically stabilize that by placing its access path in the Db2 catalog as if you were creating packages for them. As if, right? So, and those statements, when you, you know, first time they get to the Db2 again and they’re not in the cache, rather than preparing them, Db2 will read the access path directly from the Db2 catalog and place it in the cache. So very same process with the package, read the package and here your access path, the same thing here. So Sysibmd says dynamic query table contains the access pass.

 

Denis Tronin
If you look at this table, you will see statements that were stabilized. It’s stabilized on the statement text level, so the statement text is the primary thing for you here. So we see the access pass, it’s also got the statement ID, some of the stabilization groups so you can manage them as a group, the Apple Compart SQL IDs and timestamp when it was used. Unfortunately, there is no plan management policy, so you will only work with the current copy. Only one copy of the access pass is preserved, so you cannot have, you know, switch between one to another, right? So just kind of one. But however, if your statement got invalidated, or you can always look back and just to look at that, you can explain, maybe you can do some regressional, etc. So let’s see how to work with that. It’s pretty, I would say, straightforward. There is one command, start dynamic query capture. So this is the way how you enable stabilization. You can do it for a specific statement. So if you look at the cache, here’s a statement. It’s a very important statement. I want to stabilize it. I want any change.

 

Denis Tronin
So you can really specify the statement ID. It will stabilize that one. It could be for the group of statements. So there is a threshold parameter and you say, okay, I want to stabilize all of the statements that run more than 1,000 times. And that would be your way. So to look, go through the cache, find all the statements with more than 1,000 executions, stabilize them. It could be a snapshot like right now, or you can run it with the monitor parameter. Say, you know, I start command with a monitor, I let it run for 1 hour. So all the statements that reach the threshold, like get to the thousands of executions, they will get stabilized. So that’s how you can do that. So then you need to stop obviously stabilization if you run it for some time. You can also limit to particular SQL ID and the scope. Of course, ideal state, stabilize the good access paths if you can, or if you just, you know, now you just need to do the thing, you stabilize that and then you can do the fine tuning. And I see there is a question. William, let me see.
Amanda Hendley
Okay.
Denis Tronin
What is the overhead for you turning this on? I don’t know. I don’t think it is big though, because you will run it, you know, depending if you want to have it with the monitor, right, for the longer time. Then probably it will eat a little bit more resources. But other than that, I think the overhead is pretty small. Just go through the statement, find them, extract the access path, store it. So it will be similar, you know, as if you basically not even bind, because bind do the analysis. In this case, just externalizing and storing it. So I guess it’s going to be more I/O. Read the access path from the cache, store it, read, store, read, store. So shouldn’t be big. I wouldn’t really, you know, bother with that, to be honest. Okay, all right, going forward. So, um, of course you need to look at the cache because that’s what being stabilized, right? So in order to look into the what are the statements stored in the cache, you have a couple ways. You can use the EXPLAIN STATEMENT CACHE ALL statement. In this case, it will take the content of the cache, all the dynamic statements, and just put their tags in the DSN cache table along with some of the statistics.
Denis Tronin
Or if you use, if you have your monitors like CC4DB2 or Amegamon, or main view, you would be able to look at the cache as well. So you will see the SQL tags and the executions and see whether the statement is stabilized or not. So if you are done, you don’t want to use the stabilization for a statement anymore, you can free it and then the access files will be removed from the catalog. So let me walk you through the actual exercise. So in this case, I wanted to stabilize a particular one statement ID. So I look at my statement cache, I see, okay, this statement is important, I want to avoid any other changes to this one, so let me just stabilize. So I run the command and then that’s captured. Then I can look into my monitor, for example, and see that this is stabilization ID. So any statement gets a new stabilization ID and the group. You can then free, for example, multiple statements using the group name. So if I look at the system, sysibm.sys.dynamic_query_table, I would see my statement there. You see stabilization ID, group, and the statement text. So then next time, let’s say I IPL the LPAR or restart Db2, statement gets into my flow, and rather than recalculating the access path first, basically SQL text, look into my catalog, find the statement, read the access path, and we go.
Denis Tronin
Okay, hopefully that’s technique that you might start considering for your dynamic queries. So the last part of the session is you can manage your access paths through the optimization hints. So generally speaking about the optimization overall, so there are some system parameters that influence access paths. If you start joins, you can enable it, how many tables need to be in order to be considered for the start join, some query parallelism parameters, parallel and maximum degree, right? Current and maximum degree. In the beginning, there was question about the host variables versus literals. So on the package level, there is a reopt bind parameter, which is default to none, means, you know, calculated once. But you, on the package level, for the host variables, can turn on the optimization. So it could be once, means once, like, you know, the first package is read, then access passes that are calculated, or the host variables statements. It could be always, every time statement is executed, Db2 tries to re-optimize, means going to be higher overhead. Or it could be auto, so Db2 will decide whether re-optimization is needed or not, right? And what I want to talk more about, the plan statement, plan level hints, and the statement level hints.

 

Denis Tronin
This is your way to really influence optimizer. Plan table hints, I think, were introduced as of version 6. I don’t want you to use them, but for the completeness of the picture, I want you to be familiar. And if you use them, just, you know, maybe, you know, good refreshment on how those work. So those statement hints apply both for a query, dynamic or or static, typically static. So it uses query number as the way to work with that. So query number, package name, version, collection must match. So when you create a plan level hint, plan table hint, these are the things that being compared in order to apply that hint. So in this case, there is no text involved of the query, query number only. So you want to make sure that you use the query number as part of your statement to avoid any ambiguity. And executing auth ID is used to determine which plan table is used. So it is rather old technique. Statement-level hints, better functionality provide. Because in this case, anytime statement plan access path hint needs to be applied, plan table must exist, right? During evaluation of the hint, plan table is being accessed.

 

Denis Tronin
So let’s see what it takes, because always better give an example than explain that. So to create a hint, you need to have the access path in the plan table. You will typically do some changes to that because maybe you have the similar statement that you get access path, so you will tweak it a little bit to try to enforce this new access path. Or maybe you preserve it somewhere, then next time when it happens you just want to have it. So kind of update or just basically have it there. The major thing you need to obviously change is just provide the hint name. Right, this is going to be a correlation value when you’re creating a hint. So then if you rebind the package, you use this hint name and that’s how you say use this. In case of dynamic statements, you will set the optimization hint special registers, special registers, and that’s how you enforce it. If you want to check whether the hint was applied or not, you can explain the statement and see at the plan table content and see the hint used column. That should have a hint name in that.

 

Denis Tronin
You can also look at the sys_package and the syspack_statement tables to see whether the statement is used for packages, right? So if you have a state package that was, you know, rebound, you can see it there. It’s always better to see an example, to be honest. So here’s my statement. I have very classic SELECT COUNT asterisk FROM sys_tables. I specify the query number. Just to make sure I’m not guessing, not relying on what Db2 gives you, my query number. So in this case, 123. And if you see, no surprise, it’s getting index-only access. But I want to enforce the table scan. So in this case, of course, I need to update my plan table where my access path is now stored. Major thing, I just specified the hint name. TSCAN, I called it. But I also enforcing the change. So I say, you know, index only, no, disabling it. Index names, access pass create and expire, set them to nothing. And the access type, I set it to R, which just says index scan. So when I do that, and I want to try it for the dynamic statement, I set my optimization hint special register to TSCAN.

 

Denis Tronin
And I actually run the statement again, or I re-explain it. This is how I will know that the access path has changed. You see, it’s now using the table scan, and the plan table hint use column contains the TSCAN value, which is my name. And I guess there was a question again. Let me have a look. In the chat. Is there a way to find old opt-ins?

 

Amanda Hendley
Old?

 

Denis Tronin
I don’t know if you can find the old ones, but you can obviously go and look into your— in case of the static packages, that would be easier, right? Because in case of the static packages, you can go back to the catalog table sys_package and you look at this opt_hint and that would contain the opt_hint values. If you have some meaningful values there like hint 1, hint 2, hint 3, that would be your indicator that those are opt hints. In case of the statement hints, it will, I think, have a number. We will see that. Does the op hint work the same for Dynamic SQL? No, because in case of Dynamic SQL, I don’t think you will have a package updated with that. Yeah, I doubt. I could have a look, but you know, I cannot see how it would work. Okay, so that’s why I would strongly recommend you rather than using plan table access path hints, use the more up-to-date techniques, which is statement-level hints. That is definitely something you want to consider. I think it was introduced in Db2 version 10, and since then it was getting better and better. And this is the mechanism that sits behind the statement stabilization, and Db2 uses it behind the AP reuse.

 

Denis Tronin
So it’s not only externalized method, but you can also use it as, you know, Db2 uses it on its own. So this is definitely the technique better to you. So you can use it for 3 purposes. You can— that’s what we’re going to look at— to select or enforce specific access paths. You can also use these hints to override predicate filter factors. Should be very careful. So if you have very weird and skewed data and you just really enforce some predicate filter factor selection, you can do that. We will not talk about it. And you can also set the reoptimization parameters. Like REOPT and some of the ZPAR values specific for that statement. And in comparison with the plan table hints, those apply for the SQL text. So there is no ambiguity with query numbers really on the text. So text is your selection criteria and can be applied for a particular package version or a specific package. Or for the whole subsystem, system-wide. Okay, so to create a hint, we will need to have a new table, input table, which is called DSN User Query Table. So that table where you will actually store your hint details, like text, right, when you’re creating a hint.

 

Denis Tronin
If you’re creating access pass hint, access pass obviously during the hint creation will have to be stored in the explain tables. So 3 tables are used. Plan table that specifies the access pass selection details. If you deal with the case of the filter factors, then the predicate and the predicate selectivity are used. We’ll not talk about those, we’ll talk about the access pass only. Selection. So it’s plan table. So you populate this table, you put your, you know, data into the design query table, you have the information of the plan tables, you correlate them together through the fields we will talk later, and you should bind query command. And at that moment, hints are created. Okay, if you want to see whether the hint got created or not, there is set of tables in the Catalog, sysibm, sysquery_table, and it’s already stored, right? So hints are stored in catalog. So after you created a hint, you don’t need to use the dsun_user_query or the explain tables like plan table, as in case of the previous version of the hint. So you basically just create a hint, you know, you’re done. You don’t need, you know, the rest of the, you know, input anymore.

 

Denis Tronin
For packages, you can similarly look at the sys_package_statement table. You will see As for the other type hint, you will have the access path set to H. If you run explain, the hint use column will contain the hint query ID. So it’s ID versus the tags, as in case of the Plantable hints. So, um, the descending user query table— this is our input. This is where we, uh, have the statement details. So what you will expect here is the statement text, right? That’s, that’s the, to what statements my hint will be applied that has the matching SQL text. And you also provide the query ID that you have on the value so you can basically later on refer. You also have columns that say whether you’re creating the system-level hint or package-level hint. Then you have 3 columns that says what type of hint you’re creating. We’re going to talk about the access pass hint, so in this column you’ll say yes there, and for other 2, selectivity and option column, optional write columns, you will say no. You also have the query number, and this is the only time you need to have this query number so you can match the— you can find the access pass for that SQL text hint, right?

 

Denis Tronin
So it’s only used during the creation. If you create the optimization option profile options here, then you use reopt and other columns. So I want to give you a particular example that hopefully will make it all into the structure for you. So again, my SQL text. So I have a statement, you see, that was dynamic statement. So I run explain statement, cache statement ID. This is my statement: select count asterisk from my plan table. And the access path is non-matching index count only, right? So it’s using an index. So, and as previous example, I want to turn it into the table scan. However, typically probably want to do it opposite, right? So what I need to do, I need to populate my DSN user query table, and I will populate it so that I need to get the statement text, and I would provide a statement ID, and I would say, you know, what kind of hint I’m creating. So in this case, I want to create an access pass hint. So this is the only column I set to yes. I wonder if I see it. Uh, hold on. So Access pass hint, right?

 

Denis Tronin
So I put yes here. For the skin scope, I put 0, which means it’s system-wide. SQL text, right? And SQL text, I never want to run the SQL text myself. Simply because that match of the SQL text might be, you know, very exact. You know, blanks also matter. So if I want to have a hint for a particular statement, I better get that text directly from my, you know, cache table. So I better populate the cache table first, and then when I’m creating a hint, I will take text of the statement from that table. So that’s what I’m doing here. And I put some statement ID. In this case, I would— I don’t know why I selected the same number. It could be like, you know, 1, 2, 3, 4. So it doesn’t matter because ultimately what I’m populating is query number. Because that query number, I’m not sure why I selected statement ID when I was doing that. I would better do like 1, 2, 3, 4. And then when I update my plan table where I refer the access path, I would have here 1, 2, 3, 4. So sorry for this, I’m being a little bit misleading.

 

Denis Tronin
So I update my plan table and I’m again trying to enforce the access path tablescan R. I’m blanking out the index names and I’m disabling the index owned access and put it to no. So we’re similar. So when I run these two statements, I updated my access path that I will be using. You see, this is, you know, 3711 because this is the value I put it in the query number, right? So the query number points to this row in my plan table. Query text, got it from the statement cache. So I should be good. When I do that, the next thing I will do is I need to run the bind query command. So when it does, it will go through my input table User query table, for each row it will create a hint. So in this case it sees, oh, here is this select count asterisk, you know, from blah blah blah, the plan table has the hint being created for this text. Access path in plan table on the row with the query number 3711. Boom, hint got created. And when next time I got the statement, I do the explain or I run it.

 

Denis Tronin
The access path enforced will be table-scan. Okay. Hopefully it’s easy enough. Few things for you to really consider when you work with those. First, you want to make sure you clean the DSN user query table after you’re done, because when you issue bind query command, it goes through all rows. So you don’t want to create hints that you didn’t want to create. So Put your input, run the bind query, clean when you’re done. Similarly for the EXPLAIN tables, just, you know, have a separate set of tables that you can use where you have those modifications, where you capture the access path that you want to use for hint creation. If you’re not happy, sorry, with the hint later on, issue the FREE QUERY command, right? That will delete the hint. And also keep in mind when, you know, hints are applied. So if you have similar SQL tags in different hints, then the more specific will apply first. So if you have a hint on the package level version, that’s the hint will apply. If it is on the similar on the package, then package, and then only after that the system-wide hint is applied, right?

 

Denis Tronin
So, and the access pass will be created first one, then, you know, statement-level hint, predicate selective rights will apply afterwards. So hopefully that gave you an idea how you can now enforce specific access paths or how you can use any, uh, the step-level hints for in your environment. This is basically it. So if I summarize it a little bit for you, uh, explain is your friend in order to understand how your statements are executed, right? If you have some questions, if you don’t know, if you have some difficulties, explain. You can get explain for statements you just typed in, or you can extract the access path for existing statements that stored in the package or in the cache. You better maintain the statistics up to date to get better results, best results, but also be cautious. Don’t over-generate the statistics. I would say run stats, table all, index all. That’s your best friend, and we’re rarely you have anything more detailed than that. If you feel like optimizer not smart enough, you can use the access pass schemes, use the explain, sorry, extended plan management. So you can switch between those. So if you’re happy with that, just preserve the access pass and then that will give you a stable environment that you can slowly adjust.

 

Denis Tronin
And I see one more question from William.

 

Viewer
So you can Dynamic SQL, use it when I’m here. Dynamic SQL, I think from the distributed environment, right?

 

Amanda Hendley
Yes.

 

Viewer
But if you was on the mainframe, you could have a program where you run dynamic SQL, correct? Yeah. Do you know typical examples? I would think like in dynamic SQL that where you build in the SQL statement based on input. If you’re in CICS, you can use dynamic SQL in that way?

 

Denis Tronin
Yeah, it doesn’t matter. Yeah, those statement-level hints apply, you know, in case of dynamic statements, most likely we’ll create a system-wide, right? Because how many packages you have like a— this null ID packages, there’s really few of them. So yeah, you will create and then it doesn’t matter what the— from where the statement comes, it’s just dynamic. Right? It could be JDBC, it could be, you know, CICS, it could be your spoof here, right? So, so it doesn’t matter, it just applies across the board. Okay, thank you for the question. That’s all I had. Anybody has any other questions? If not, Feel free to reach out to me, any question you have, we can talk more about that. Feel free to, you know, write me on the LinkedIn or email directly. Happy to talk. Just, you know, it was nice to be on this call.

 

Amanda Hendley
Is that a new question I see in chat?

 

Denis Tronin
Let me see. Uh, how do you do that?

 

Viewer
Okay, I got a quick question. You mentioned about some systems, uh, presentation. I didn’t see it out there. Has it not been put out there yet? You said your previous presentation. This was, uh, Amanda said previously.

 

Denis Tronin
Oh, a question to Amanda?

 

Viewer
Oh yeah, previous presentation was on us. Systems something.

 

Amanda Hendley
Okay, so presentation on systems.

 

Viewer
You talked about the previous presentation before this one, and I thought it was on Sysplex. I thought that’s what you said.

 

Amanda Hendley
No, no, but you could go to the website and get all the videos, or our YouTube and get all the videos. For past presentations, you might find something there. Okay, I don’t— I didn’t mention one specifically today.

 

Viewer
Oh, okay.

 

Denis Tronin
All right, and I will also share my presentation with Amanda, and I guess she will distribute or publish it where it should be published.

 

Amanda Hendley
Yeah, I’m happy to do that.

 

Denis Tronin
Okay, I have a question here also in the chat: can you please share your quick insight on materialized query tables? Will that be useful when dealing with huge SQLs. Like, I’m not exactly sure what the, what is supposed to mean. So I didn’t work much with the materialized query tables. I know that some of people use them actively as way to basically access huge amount of data or maybe building kind of warehouse analysis data. So you have your fact table and you create aggregation tables and store them as materialized query tables. And that then simplify, rather than you go after the fact table, you go to these smaller materialized query tables. But I’m not sure what the question about the huge SQLs, like huge, like a long SQL text. I’m not sure if, Rathans, if you can expand it on that. I’m just not sure. I mean, if the question about the SQL statement level hints, then doesn’t matter. Statements are statements, right? If you created some optimization and created a hint or you stabilize a statement, it doesn’t matter against what object it goes. As to materialized queries tables themselves, yeah, there could be a performance gain.

 

Denis Tronin
So if you run some analytics SQLs often and they’re similar aggregation, just store them into materialized query table. So the next time just goes directly to that table, then than recalculating that. Okay.

 

Amanda Hendley
And I saw William had raised his hand, and I don’t know at what point.

 

Denis Tronin
I think that was before.

 

Amanda Hendley
Okay. All right, great.

 

Denis Tronin
And guys, don’t hesitate. If you have any further questions, you know, feel free to reach out. Also, if any of you go to, you know, any of the conferences, like, I can, you know, stop by, happy to talk to you.

 

Viewer
Well, Db2, Amanda, how many of these do you do a year?

 

Denis Tronin
Couple?

 

Amanda Hendley
We do 4 to 6 a year.

 

Viewer
Oh, okay. Because so, and it’s planetmainframe.com. Yeah, what’s the best way to see a complete list of like the Db2 presentations?

 

Amanda Hendley
You could go to virtualusergroups.com, which we’ll link over. And then go to the Db2 page, or virtualusergroups.com/Db2 should do it as well.

 

Denis Tronin
Okay, thank you.

 

Amanda Hendley
We are also— I put up a QR code. We’re on LinkedIn. Sorry, we’re on LinkedIn. I meant to say we’re on YouTube, so you can find a lot on YouTube as well, and that’ll take you straight to the videos. The advantage on our site obviously is that we also have a PowerPoints, the PDFs posted. And, um, what we’ll do with this session, and we do with all the sessions, is in— within a couple weeks, we’ll have the, uh, presentation posted, the video, and a transcript for you. And if you’re not subscribed to our newsletters and messaging about the groups, uh, you can get recaps, um, to your email from the sessions. So rest assured we’ll get this one posted for you. And then I did want to let you know October is Security Month for Planet Mainframe. It’s one of our editorial themes and we have a security theme session coming up on October 20th. Registration might be open for it.

 

Denis Tronin
Yeah, this is, this is very good, but a little bit geeky session. So, you know, just be ready, you know, have a couple of coffees before that. Emil is very good at that.

 

Viewer
Okay.

 

Denis Tronin
And if you have any ideas for any other topics, you know, just reach out to Amanda, I guess.

 

Amanda Hendley
Right. Well, if there are no other questions, um, and of course, I’m— if you end up with a detailed question, Denis, I’ll, uh, people can email me and I will get those over.

 

Denis Tronin
Mhm. Okay, great.

 

Amanda Hendley
Well, Denis, thank you so much.

 

Denis Tronin
Thank you, everyone. Thank you for having me.

Virtual Db2 Sponsor

Planet Mainframe
Denis Tronin

Denis Tronin

Broadcom

Upcoming Db2 Session

Get the latest Virtual User Group Updates

This field is for validation purposes and should be left unchanged.
Select the Groups you'd like to Join(Required)