How to Implement a Filtered Index in Oracle

Previously on my blog post (Sometimes a histogram existence may mislead to a suboptimal plan), I analyzed a poorly performing query in detail and detected that sometimes a histogram existence may mislead to a suboptimal plan. I have listed some possible solutions. But what i applied as a solution was to emulate a partial/filtered index in Oracle. 

I know partial indexes concept from Postgresql database, it is also available on MS SQL and some others. 

Emulated partial index

What is Partial Index?

...

A partial index is an index built over a subset of a table; the subset is defined by a conditional expression (called the predicate of the partial index). The index contains entries only for those table rows that satisfy the predicate. Partial indexes are a specialized feature, but there are several situations in which they are useful.

One major reason for using a partial index is to avoid indexing common values. Since a query searching for a common value (one that accounts for more than a few percent of all the table rows) will not use the index anyway, there is no point in keeping those rows in the index at all. This reduces the size of the index, which will speed up those queries that do use the index. It will also speed up many table update operations because the index does not need to be updated in all cases.  

... More of it available on Postgresql Official Documentation.

Basically, Index is constructed over a subsection of a table according to the query filter predicates.

In Oracle, Partial Index term differs a little bit. My friend Meftun has a nice post series(Have you ever need to index only SOME partition of a table?) about it.

I will implement a filtered index solution by creating a functional index for the problematic query i mentioned in previous post and show how a real performance boost gained.

When Full table scan is done, total block gets was 1352052. When composite index (IN_ACCDOC_DCTYPRLTDDDTRLTD)  is used, 90813 block gets done. But when the partial/filtered index solution applied, total block gets decreased heavily to 33662. %98 performance boost observed. Its size is only 2MB. 1000 times smaller than the composite index applied on my previous post.

Hope it helps.


Comments

Popular posts from this blog

Using table stats hint to force a direct path read but with a rownum predicate surprise

Oracle Grid Release Update by using Ansible Playbooks

Oracle Database Release Update by Using Ansible Playbooks