Optimizer Plans for Local HNSW Vector Indexes

Oracle AI Database uses partition pruning to narrow the search and search only the local HNSW graphs for qualifying partitions or sub partitions. Partition pruning narrows the set of local HNSW graphs that need to be searched, and the optimizer plan determines the most efficient execution plan for accessing narrowed graph set during similarity search. When using local HNSW vector indexes, you may see different optimizer plans for similarity searches.

Local HNSW indexes use the same general HNSW vector indexes optimizer plan concepts described in Optimizer Plans for HNSW Vector Indexes topic, such as pre-filtering, in-filtering, and join-back. However, a local HNSW index adds partition pruning to the optimizer decision.

A pre-filter plan evaluates the filter before the local HNSW index scan. Like post-filter plans, pre-filter plans are generally useful for expensive filters. Unlike post-filter plans, pre-filter plans can still return the requested approximate nearest rows because filtering happens before vector index evaluation. The tradeoff is that the filter evaluation cost can be higher than with a post-filter plan. A post-filter plan evaluates the filter only for candidate rows returned by the local HNSW index scan, while a pre-filter plan may need to evaluate the filter earlier in the execution process.

Comparison of In-Filter, Pre-filter, and Post-Filter Plans:

Plan type When the optimizer typically chooses it How filtering is applied TOP N behavior Filter evaluation cost Partition-wise processing
In-filter (with or with join back) Typically chosen when filters are inexpensive or the filters are not highly selective (many rows pass the filters). The filter is evaluated as part of the local HNSW partition graph scan. Can return TOP N rows during local HNSW index evaluation. Usually lower when the filter is inexpensive to evaluate. The optimizer first determines which partitions to access, then evaluates the filter during each selected partition’s local HNSW graph scan.
Pre-filter (with or with join back) Typically chosen for expensive filters where preserving TOP N results is important. The filter is evaluated before the local HNSW partition graph scan. Can return the requested TOP N rows because filtering happens before vector index evaluation. Can be higher than a post-filter plan because filtering may occur before candidate rows are reduced by the HNSW scan. The optimizer first determines which partitions to access, then evaluates the filter before scanning each selected partition’s local HNSW graph.
Post-filter Typically chosen for expensive filters when evaluating the filter only on candidate rows is more efficient. The filter is evaluated after the local HNSW partition graph scan. May not return the requested TOP N rows if the filter removes too many candidate rows returned by the HNSW scan. Usually lower than a pre-filter plan because the filter is evaluated only for candidate rows returned by the local HNSW index scan. The optimizer first determines which partitions to access, then applies the filter after each selected partition’s local HNSW graph scan.