Legacy Knowledge Base
Published Sep. 10, 2025

Poor Performance in DB2 When Executing SQL Queries Over Big Tables Filtering by a Column With a Non-Unique Index

Written By

Daniel Couso

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Liferay Support does not recommend or endorse specific third-party products over others. Liferay is not responsible for any instructions herein or referenced regarding these products. Any implementation of these principles is the responsibility of the subscriber.

This article documents a known issue with DB2 when executing SQL queries like SELECT * FROM table_ WHERE column_ = ? whose:

  1. column column_ has a non-unique index, that isin the Service Builder definition there is a non-unique, non-collection finder which generates a non-unique index
  2. table table_ has hundreds of thousands of records
  3. column column_ has all its values set to the default value (in case of numeric type, this default value is 0)

A concrete example of this type of query is SELECT Group_.* FROM Group_ WHERE Group_.liveGroupId = ? with a huge amount of sites and none of them are not under local Staging.

The reason behind this behavior is that DB2 planner is making the decision of doing a full table scan without taking into account the size of the table despite the fact that using the non-unique index would perform better.

Running the command db2 runstats on table table_ does not make any difference on the query's execution plan.

Resolution

Status: Won't Fix / Workaround Available

This issue is very specific to the DB2 planner, being only reproducible under the particular scenario described above and it will not be fixed.

The available workaround is to set the attribute VOLATILE of the affected table to true in order to force the use of the non-unique index.

This does not have any impact in current queries which already use indexes, although it might penalize the performance of some other queries which do not use any index slightly.

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base