Db2 Tools for zOS

 View Only

 SQL Performance Analyzer - How can I create a virtual Expression-based index?

Soledad Martinez's profile image
Soledad Martinez IBM Champions posted 10/13/26 03:04 AM

Good Day,

I cannot find the way to do it or any reference at the manual, but would like to confirm it.

  • Is there any way to create a virtual Expression-based index/Index on expression with the SQL PA?

Thanks!

Michael Hannan's profile image
Michael Hannan

Although SQL PA supports Virtual Indexes for a "what if",  standard Virtual Indexes implementation is a bit crude (at least in DB2 for z/OS), and not covering "Indexes on Expression".  So if you can't find any doco that explicitly says SQL PA supports Index on Expression Creation, then likely it has nothing special for it.  I create Indexes on Expression all the time, just using normal DDL and my own analysis.  As a virtual index does not work you could create it on a test copy of the table with no data but all the Access Path stats info in the catalog copied across. In fact I think I recall some 3rd party product does that in its Clone What if function.  Its not that hard to have stats migrate automated by your self, and generate test clone DDLs.

So I do manage to create Index on Expression in test env, populate some stats and check that target SQLs explained can use the new index successfully. All this without using SQL PA.

Generally we want Index on expression column to show up in explain as either a matching column or at least doing strong index screening.  Otherwise it might be little value. I don't recall if I ever managed to use it purely to get index only or to be usable for GROUP BY and sort avoidance.

Hope I am not too far on a tangent to what you really look for.

 

Soledad Martinez's profile image
Soledad Martinez

Hello Michael, 

thanks for this, really interesting how you are doing it. My goal is the same than you, yes.

But I would like to make it with a tool, in this case with the SQL PA. I think it should work, as the virtual indexes have a catalog table for storing them: DSN_VIRTUAL_KEYTARGETS - IBM Documentation

I think I would give a go to your method but using inserting at these tables, although it's not recommended by IBM :-)

                   Recommendation: Do not manually insert data into system-maintained EXPLAIN tables

Thank you!

Aliaksei Zakharevich's profile image
Aliaksei Zakharevich

Hi Soledad,

This is actually a capability we're currently working on. Support for virtual Expression-Based Indexes in SQL Performance Analyzer is planned for a future release, with availability targeted for late this year or early next year.

Thanks for the suggestion and for highlighting this use case.
 

Michael Hannan's profile image
Michael Hannan

In relation to DSN_VIRTUAL_KEYTARGETS, indeed this maybe be workable in the modern day.  It's too long ago since I last tried to make that work and struggled.   One of the issues with Virtual Indexes and Keytargets before, was the lack of possibility to populate a full set of DB2 Catalog Stats, in particular the very important KEYCARD stats (SYSCOLDIST Type C and SYSKEYTGTDIST).  So that could inhibit the ability of Optimizer to make the best index choice.    So I don't really use Virtual indexes these days. O.K. for very quick first cut tests. I have the ability to create indexes in a test env at will and to populate what stats I desire, to be realistic.  So we copy the Prod table stats firstly.  I ignore IBM advice not to mess with stats, since I know what I am doing  and which stats are safe to amend.  Having a test env use ALL the Prod Stats does not cause us any issues.   It's always unwise to fiddle with some stats to try to make a test index look more desirable than it really is, better to be realistic.  Instead we can make DB2 understand how undesirable other indexes are, and let it choose the next best.   We have SQL stabilisation Hints if we get desperate, and Predicate Selectivity Hints, runtime Reopt, and degree ANY, or of course DB2zAI  which understands runtime reality better.   We use NPGTHRESH zparm  all the time, to make DB2 choose an index when it can at all.  This is based on past Terry Purcell advice how NPGTHRESH is much better than marking tables as Volatile for getting good access path selection.

I am a DB2 person who does not like to use a lot of tools where we lose control over what is generated.  I have my own automation of various basic things like explain, since I like fine detail but in a compact (not verbose) format.  

I do use CQM Query Monitor heavily. 

Soledad Martinez's profile image
Soledad Martinez

Hello Michael, 

great, I can see your method is perfectly set and you are controlling everything. Sure I will give it a go.

Anyway, truth is that I am more a Db2 tools person. I prefer using tools because you can be sure that they are well maintened with any of the RSU you apply to them, and also because if for some reason you need to leave the company or start in a new company, a tool is more standard and easy to inhereit. 

About SQL PA and the index expression support, I just searched at the AHA and found one asking for the same in 2025, in "Planned for future release" status.

IBM Ideas

Thanks for sharing all the details with me, really appreciate it. I didn't know "Terry Purcell advice how NPGTHRESH ...", I searched for it and found an entry related to this at sswug-org. I will request joining the group and review, seems very interesting.

Thanks again, really helpful talking with you!

Tom Glaser's profile image
Tom Glaser IBM Champions

Hi Soledad,

This is actually a capability we're currently working on. Support for virtual Expression-Based Indexes in SQL Performance Analyzer is planned for a future release, with availability targeted for late this year or early next year.

Until then, creating the index in a test environment and evaluating it through EXPLAIN remains the best alternative.

Thanks for the suggestion and for highlighting this use case.

Tom Glaser's profile image
Tom Glaser IBM Champions

Hi Soledad,

This is actually a capability we're currently working on. Support for virtual Expression-Based Indexes in SQL Performance Analyzer is planned for a future release, with availability targeted for late this year or early next year.

Until then, creating the index in a test environment and evaluating it through EXPLAIN remains the best alternative.

Thanks for the suggestion and for highlighting this use case.

Soledad Martinez's profile image
Soledad Martinez

Hello Tom,

perfect, thanks for the feedback. I am looking forward this feature, so happy to know that will be available in a short.

Thank you!

Jørn Thyssen's profile image
Jørn Thyssen IBM Champions

You can track the enhancement here https://ideas.ibm.com/ideas/DB2ZSQLPA-I-20