We help IT Professionals succeed at work.

DB2 Explain Plan takes forever

DB2 10.5 on Windows Server 2012

I can have a query that takes 3 seconds to run and then when I look at the explain plan, it takes 2-5 minutes to generate.  And it seems to be getting slower.  

How can I speed this up?  In my QA environment the same operation takes like 20 seconds to generate.

Watch Question

Kent OlsenData Warehouse / Database Architect


That seems pretty weird, Jim.  It sounds like a resource conflict (perhaps a lock?) is getting in the way.  An explain plan should generate quite quickly.

Jim YoumansSr Database Administrator


On my QA and Stage servers it does, but on the busy prod server can take up to 5 minutes.  I thought maybe some of the tables that explain uses needed to be cleared or something.
Data Warehouse / Database Architect

Typically those tables don't contain much data so I wouldn't expect that to be an issue.

But the data in those tables isn't used by the optimizer, either.  You should be able to delete the contents of the explain tables.  Just to be sure, check the row counts in the tables in production, QA, and dev.