Filter selectivity is a statistical measure, expressed as a fraction or percentage, that estimates the proportion of records in a dataset that will satisfy a given filter predicate. Database query optimizers rely on this estimate to choose the most efficient execution plan, such as deciding whether to use an index or perform a full table scan. High selectivity indicates a filter that excludes most rows, making an index scan efficient, while low selectivity suggests a broad filter where a sequential scan may be faster.
Glossary
Filter Selectivity

What is Filter Selectivity?
Filter selectivity is a critical metric in database query optimization, quantifying the expected proportion of records that will pass a given filter condition.
In vector database infrastructure and hybrid search, understanding filter selectivity is essential for optimizing multi-stage retrieval pipelines. For operations like pre-filtering or post-filtering, the optimizer uses selectivity to decide the order of operations—applying a highly selective metadata filter before an expensive approximate nearest neighbor (ANN) search can drastically reduce latency. Accurate selectivity estimation directly impacts the performance of filtered search and the overall efficiency of query planning.
Key Characteristics of Filter Selectivity
Filter selectivity is a critical metric used by database query optimizers to estimate the efficiency of different execution plans. It quantifies the proportion of records expected to pass a given filter predicate.
Definition and Formula
Filter selectivity is a statistical measure, expressed as a value between 0.0 and 1.0 (or 0% to 100%), that estimates the fraction of rows in a table or index that will satisfy a specific filter condition. It is calculated as:
Selectivity = (Estimated Number of Matching Rows) / (Total Number of Rows)
- A selectivity of 0.01 (1%) indicates a highly selective filter, likely returning a small result set.
- A selectivity of 0.9 (90%) indicates a non-selective filter, returning most records. Optimizers use this value to choose between index scans, full table scans, and join algorithms.
Role in Query Planning
The query optimizer uses selectivity estimates to generate the lowest-cost execution plan. Key decisions influenced by selectivity include:
- Access Path Selection: Choosing between a full vector/index scan versus using a specific metadata index.
- Join Order: Determining the optimal sequence for joining multiple tables, typically processing the most selective filters first to reduce intermediate result sizes.
- Operator Choice: Deciding whether to use a nested-loop join (good for highly selective outer tables) or a hash join (better for larger, less filtered datasets). In vector databases, it critically informs the choice between pre-filtering and post-filtering strategies.
Factors Influencing Selectivity
Selectivity is not a fixed property; it depends on data distribution and the predicate itself. Key factors are:
- Data Cardinality: The number of distinct values in a column. High cardinality (e.g.,
user_id) typically leads to higher selectivity for equality filters. - Predicate Type: An equality filter (
category = 'sports') is generally more predictable than a range filter (price > 100). - Data Skew: Real-world data is often skewed. A filter on
country='US'might have low selectivity in a global dataset but high selectivity in a dataset for Japan. - Correlated Columns: Selectivity estimates for conjunctive filters (AND) assume independence, but if
cityandzip_codeare correlated, the actual selectivity may be much higher than the product of individual selectivities.
Estimation Techniques
Databases use various methods to estimate selectivity without scanning all data:
- Histograms: The most common technique. The system divides column value ranges into buckets and stores the frequency of values in each, enabling accurate estimates for equality and range predicates.
- HyperLogLog & Distinct Counts: Used to estimate the cardinality of a column, which is essential for equality filter estimates.
- Sampling: Running the filter on a small, random sample of pages to extrapolate the overall selectivity.
- Static Catalog Statistics: Pre-computed statistics like
n_distinct,most_common_vals, andcorrelationstored in the system catalog (e.g.,pg_statisticsin PostgreSQL).
Impact on Vector Search Performance
In hybrid search systems, filter selectivity directly dictates the optimal retrieval strategy:
- High-Selectivity Filters (e.g.,
user_id=123): Favor pre-filtering. Applying the strict filter first creates a very small candidate set, making the subsequent Approximate Nearest Neighbor (ANN) search over vectors cheap and accurate. - Low-Selectivity Filters (e.g.,
is_published=true): Favor post-filtering. Performing a broad ANN search first and then applying the weak filter avoids the overhead of integrating the filter into the graph traversal of indexes like HNSW. Poor selectivity estimation can lead the optimizer to choose a post-filtering plan for a highly selective query, causing massive unnecessary vector comparisons.
Related Optimization Concepts
Filter selectivity interacts with several core database optimization principles:
- Filter Pushdown: The optimizer strives to push high-selectivity filters down to the storage layer to minimize data movement. High selectivity makes pushdown highly beneficial.
- Bitmap Index Scans: For medium-selectivity filters on multiple columns, the database may perform bitmap index scans, combining bitmaps using AND/OR before fetching the rows.
- Conjunctive vs. Disjunctive Queries: The selectivity of a conjunctive query (AND) is the product of individual selectivities (assuming independence). A disjunctive query (OR) has selectivity calculated as
1 - product(1 - sel_i). - Cost-Based Optimization (CBO): Selectivity is a primary input into the cost formulas that compare potential execution plans.
How Filter Selectivity Drives Query Optimization
Filter selectivity is a foundational metric in database query optimization, quantifying the expected reduction in dataset size from applying a filter predicate.
Filter selectivity is a measure, expressed as a fraction or percentage, that estimates the proportion of records in a dataset that will satisfy a given filter predicate. This statistical estimate is used by a query optimizer to compare the efficiency of potential execution plans. A highly selective filter (e.g., user_id = 123) passes a tiny fraction of rows, making it a prime candidate for filter pushdown to minimize data processing. Conversely, a low-selectivity filter (e.g., status = 'active') is less effective at reducing the working set.
The optimizer uses selectivity to decide critical execution order, such as whether to pre-filter a dataset with metadata constraints before an expensive vector similarity search. For conjunctive queries (AND), selectivities are multiplied; for disjunctive queries (OR), they are combined. Accurate selectivity estimation, often derived from histograms or bitmap index statistics, is essential for the optimizer to choose a plan that minimizes latency and computational cost, directly impacting the performance of hybrid search systems.
Filter Selectivity Scenarios & Optimization Decisions
A decision matrix for choosing the optimal filtered search strategy based on filter selectivity and system constraints.
| Scenario & Metric | Pre-Filtering Strategy | Post-Filtering Strategy | ANN-with-Filters Strategy |
|---|---|---|---|
Primary Use Case | High-precision retrieval with strict constraints | Broad semantic recall with secondary filtering | Balanced performance for moderate constraints |
Optimal Filter Selectivity | < 1% (Highly Selective) |
| 1% - 30% (Moderately Selective) |
Index Architecture Requirement | Separate metadata index (e.g., B-tree, Bitmap) | Single vector index (e.g., HNSW, IVF) | Integrated filtered index (e.g., HNSW with Filters) |
Query Latency Profile | Fast filter, fast search on small set | Fast search, fast filter on large set | Moderate, single-pass search |
Memory & Compute Overhead | Low for search, high for index maintenance | Low for indexing, high for filtering large result sets | Moderate, integrated into core index |
Result Recall Guarantee | 100% for filtered set | May discard relevant items failing post-filter | 100% for filtered set (algorithm-dependent) |
Implementation Complexity | Medium (query planning & join logic) | Low (sequential operations) | High (custom index modification) |
System Example | PostgreSQL with pgvector (bitmap scan -> IVF) | Pinecone (vector search -> client-side filter) | Weaviate (HNSW with filtered graph traversal) |
Frequently Asked Questions
Filter selectivity is a critical metric for optimizing search performance in vector databases and hybrid retrieval systems. These questions address its definition, calculation, and practical impact on query execution.
Filter selectivity is a statistical measure, expressed as a fraction or percentage, that estimates the proportion of records in a dataset that will satisfy a given filter predicate (e.g., category = 'news' AND date > '2024-01-01'). It is a foundational input used by database query optimizers to choose the most efficient execution plan by predicting the cardinality, or size, of intermediate result sets. A high-selectivity filter (e.g., 0.01 or 1%) is very restrictive, returning few records, while a low-selectivity filter (e.g., 0.8 or 80%) is broad, returning most records.
In the context of hybrid and filtered search, accurately estimating selectivity is paramount for deciding between strategies like pre-filtering (applying metadata constraints first) and post-filtering (applying them after a vector search). An optimizer might choose pre-filtering for a high-selectivity filter to drastically reduce the candidate set for an expensive approximate nearest neighbor (ANN) search. Selectivity estimates are derived from database statistics, such as histograms on column value distributions.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Filter selectivity is a core metric for query optimization. Understanding related concepts is crucial for designing efficient retrieval systems.
Query Planning
The process by which a database system's optimizer analyzes a search query and its metadata filters to generate an efficient execution plan. The optimizer uses estimated filter selectivity to decide the order of operations, such as whether to apply a filter before or after a vector search, to minimize computational cost and latency.
Filter Pushdown
A critical query optimization technique where filtering predicates are evaluated as early as possible in the execution pipeline, ideally within the storage engine. High-selectivity filters are prime candidates for pushdown. This minimizes the amount of data that must be loaded and processed by subsequent stages (like vector search), dramatically improving performance.
- Example: A filter for
user_id = 123is executed directly on the database nodes holding the data, rather than on a central coordinator.
Pre-Filtering vs. Post-Filtering
Two fundamental strategies for applying metadata constraints in vector search, directly governed by filter selectivity estimates.
- Pre-Filtering: Apply high-selectivity filters first to create a small candidate set, then perform the expensive vector search. Efficient when filters eliminate most records.
- Post-Filtering: Perform a broad vector search first, then apply filters to the results. Used when filters have low selectivity or when the unfiltered vector search is already fast.
The choice between these strategies is a key decision informed by filter selectivity.
Bitmap Index
A specialized database index structure that enables extremely fast filtering operations, which are essential for estimating and leveraging filter selectivity. It represents the set of records containing a specific attribute value using a compact array of bits (a bitmap).
- How it helps: Allows for rapid set intersection (AND) and union (OR) operations. A query optimizer can quickly scan these bitmaps to estimate the selectivity of a filter (e.g., how many bits are set in the
category='electronics'bitmap) before executing the full query.
ANN with Filters
Refers to Approximate Nearest Neighbor (ANN) search algorithms that have been modified to natively respect hard metadata constraints during the graph or tree traversal. This is a complex extension where the index structure itself is aware of filters.
- Challenge: Maintaining search speed and recall while skipping over nodes that don't match the filter predicates.
- Implementation: Algorithms like HNSW with Filters or DiskANN with tags integrate filtering logic directly into the graph traversal, using selectivity estimates to guide the search path.
Conjunctive & Disjunctive Queries
The two primary logical structures for combining multiple filters, where selectivity estimation becomes combinatorial.
- Conjunctive Query (AND):
category='books' AND price < 20. The overall selectivity is the product of individual selectivities (assuming independence), typically resulting in a very high-selectivity filter. - Disjunctive Query (OR):
category='books' OR author='Smith'. The overall selectivity is the sum of individual selectivities minus the overlap, often resulting in a lower-selectivity (broader) filter.
Accurately modeling the selectivity of these compound predicates is essential for the optimizer to choose the correct table scan or index access method.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us