Inferensys

Glossary

Disjunctive Query

A disjunctive query is a database query that uses the logical OR operator to combine filter conditions, requiring at least one of the specified predicates to be true for a record to be included.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
DATABASE QUERY

What is a Disjunctive Query?

A disjunctive query is a fundamental logical operation in database and search systems that retrieves records matching at least one of several specified conditions.

A disjunctive query is a database query that uses the logical OR operator to combine multiple filter conditions, requiring at least one of the specified predicates to be true for a record to be included in the result set. In the context of hybrid search within a vector database, it is commonly used to apply flexible metadata constraints, such as finding documents that are either from a specific category or published within a certain date range, before or during a semantic search operation.

This contrasts with a conjunctive query, which uses the AND operator and requires all conditions to be met. Efficient execution of disjunctive queries, especially over large-scale vector indexes, often involves optimization techniques like filter pushdown and the use of bitmap indexes to perform fast set unions. Understanding filter selectivity is crucial for query planners to determine the most efficient order of operations when disjunctive filters are combined with expensive approximate nearest neighbor (ANN) searches.

LOGICAL OPERATIONS

Key Characteristics of Disjunctive Queries

A disjunctive query uses the logical OR operator to combine filter conditions, requiring at least one predicate to be true for a record to match. This is a fundamental operation for broadening search results and modeling real-world 'any-of' scenarios.

01

Logical OR Semantics

The core of a disjunctive query is the logical OR operator. It combines multiple filter predicates such that a document is included in the result set if at least one of the conditions evaluates to true. This is formally expressed as predicate_A OR predicate_B OR .... For example, a query for documents where category = 'news' OR author = 'Jane Doe' returns all news articles plus all articles written by Jane Doe, including any that satisfy both conditions.

02

Broadens Result Sets

Disjunctive queries inherently increase recall by expanding the candidate pool. Unlike a conjunctive query (AND) which narrows results, an OR condition aggregates matches from multiple criteria. This is essential for exploratory search, faceted navigation where users select multiple options within a facet (e.g., 'show me shirts in red OR blue'), or building inclusive candidate sets for downstream reranking stages. The cardinality of the result set is at least as large as the largest individual predicate's result and at most the union of all.

03

Implementation in Query DSLs

Disjunctive logic is a first-class citizen in search and database Query Domain-Specific Languages (DSLs). It is expressed using explicit operators:

  • Elasticsearch / OpenSearch: {"bool": {"should": [ {...}, {...} ]}}
  • SQL: WHERE category = 'A' OR tag = 'B'
  • Pinecone / Weaviate: Nested filter objects with an "Or" operator at the root. These DSLs allow nesting disjunctions within conjunctions (e.g., (A OR B) AND C) to create complex, precise logical trees for retrieval.
04

Interaction with Vector Search

In hybrid search systems, disjunctive filters are typically applied to the metadata before or during the vector similarity search. A query like (vector_similarity(query)) FILTER BY (department = 'Sales' OR department = 'Marketing') ensures results are semantically relevant and belong to either department. Efficient execution requires index structures like HNSW with filters or IVF with IDSelector that can prune graph traversal or cluster probing based on OR conditions, avoiding a full post-filter that could discard all vector results.

05

Performance Considerations

Disjunctive queries can be computationally more expensive than conjunctive ones for filtering systems. Key performance factors include:

  • Index Support: Systems use bitmap indexes or inverted indexes to perform fast union operations for OR clauses.
  • Selectivity: Low-selectivity (broad) OR predicates can generate large intermediate result sets, stressing memory. Optimizers may reorder predicates or choose different index access paths.
  • Pushdown Efficiency: For ANN with filters, the ability to 'push' the OR condition into the vector index traversal is critical for performance. A naive post-filter after a vector search may yield zero results if the filter is too restrictive, wasting the initial ANN computation.
06

Contrast with Conjunctive Query

Disjunctive (OR) and conjunctive (AND) queries are logical duals. Their core difference is in result set inclusion:

  • Disjunctive (OR): A OR B → Includes union of sets satisfying A and B.
  • Conjunctive (AND): A AND B → Includes intersection of sets satisfying A and B. A conjunctive query narrows and specifies ('this AND that'), while a disjunctive query broadens and aggregates ('this OR that'). Most complex business logic queries, expressed in a Query DSL, are compositions of both AND and OR operators within a single execution plan.
LOGICAL FILTER COMPARISON

Disjunctive Query vs. Conjunctive Query

A comparison of the two fundamental logical operators used to combine filter predicates in database queries, particularly relevant for filtered vector search.

Feature / CharacteristicDisjunctive Query (OR)Conjunctive Query (AND)

Logical Operator

OR

AND

Result Set Inclusion Rule

A record is included if AT LEAST ONE of the specified conditions is true.

A record is included ONLY IF ALL of the specified conditions are true.

Effect on Result Set Size

Tends to INCREASE the result set size (union of sets).

Tends to DECREASE the result set size (intersection of sets).

Typical Use Case

Broadening search to capture diverse criteria (e.g., category='electronics' OR price<100).

Narrowing search with precise, cumulative constraints (e.g., category='electronics' AND price<100 AND brand='Acme').

Filter Selectivity

Low selectivity; fewer records are filtered out.

High selectivity; more records are filtered out.

Performance Consideration

Can be less efficient if filters have low individual selectivity, as many records may qualify.

Can be highly efficient with selective filters, quickly narrowing the candidate pool.

Implementation in Vector Search

Often requires specialized index support (e.g., filtered HNSW) or post-filtering to avoid missing relevant vectors.

Easier to optimize via pre-filtering; a common pattern for scoping vector search to a relevant subset.

Example Boolean Expression

category = 'news' OR publish_date > '2024-01-01'

category = 'news' AND publish_date > '2024-01-01' AND language = 'en'

DISJUNCTIVE QUERY

Frequently Asked Questions

A disjunctive query uses the logical OR operator to combine filter conditions, requiring at least one predicate to be true for a record to match. This glossary addresses common technical questions about its implementation and optimization in vector search systems.

A disjunctive query is a database query that uses the logical OR operator to combine multiple filter conditions, requiring that at least one of the specified predicates be true for a record to be included in the result set. This contrasts with a conjunctive query (using AND), which requires all conditions to be true. In the context of vector databases and hybrid search, disjunctive queries are commonly applied to metadata fields to broaden the search scope. For example, a query for documents that are tagged as "finance" OR have a category of "annual-report" will return all records satisfying either condition, creating a union of the two filtered sets.

Prasad Kumkar

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.