Friday, 1 August 2025

Range Index in Apache Pinot

The Range Index in Apache Pinot divides numeric values into predefined ranges (buckets). These ranges are created during segment creation, and helps Pinot quickly filter queries like price > 500 or age BETWEEN 20 AND 30 kinds of queries efficiently.

 

Let’s take a sample dataset:

product_id

name

price

timestamp

1

Laptop

1000

1700000000

2

Phone

700

1700005000

3

Tablet

500

1700010000

4

Keyboard

50

1700020000

5

Monitor

300

1700030000

 

Let's a Range Index on:

·      price (INT)

·      timestamp (LONG)

 

Range Index for price

Range

Records in this range

0-250

[]

251-500

[3, 5]

501-750

[2]

751-1000

[1]

 

Range Index for timestamp

Range

Records in this range

1699999000-1700005000

[1, 2]

1700005001-1700015000

[3]

1700015001-1700025000

[4]

1700025001-1700035000

[5]

 

For example, when you execute following query

SELECT * FROM products WHERE price > 500;

 

How Pinot Uses the Range Index?

·      Pinot finds relevant ranges:

o   It skips 0-250 and 251-500 ranges.

o   It directly looks up 501-750 and 751-1000, and get the records {2, 1}

·      It retrieves rows 2 and 1 (Phone and Laptop).

·      No full table scan is needed in this case

 

In summary,

·      Range Indexes are optimized for BETWEEN, >, < queries.

·      Best for analytics on numeric/timestamp columns.

 

Previous                                                    Next                                                    Home

Wednesday, 30 July 2025

Sorted Inverted Index in Apache Pinot

A Sorted Inverted Index is a specialized version of the inverted index that maintains both the inverted mapping (value to document IDs) and a sorted order of the values within each index. This index is ideal for scenarios where you want to perform quick lookups as well as efficient range queries or ordering on the indexed column.

 

The key difference between a standard Bitmap Inverted Index and a Sorted Inverted Index is the ordering of the values. In a Sorted Inverted Index, the document IDs are maintained in a sorted order for each indexed value, which helps to optimize range queries.

 

How Does a Sorted Inverted Index Work?

Let’s consider the dataset with documents that have a Category and Price columns.

 

Document Id

Category

Price

d1

Electronics   

1000

d2

Furniture

700

d3

Electronics   

1200

d4

Clothing 

500

 

When creating a Sorted Inverted Index for the Category and Price columns, Pinot does the following:

 

·      Category Column: Maps each unique category to a list of document IDs that contain that category. These lists are sorted based on document ID or another internal ordering.

 

·      Price Column: Maps each unique price to a list of document IDs that contain that price. These lists are sorted based on price values, enabling efficient range queries.

 

Example of a Sorted Inverted Index

Let’s see how Pinot would create a Sorted Inverted Index for the Category and Price columns:

 

Category Column (Sorted Inverted Index):

Category

Document IDs (Sorted)

Electronics   

d1, d3

Furniture

d2

Clothing 

d4

 

In the Sorted Inverted Index, the document IDs for Electronics (d1 and d3) are already sorted in ascending order. Similarly, the other categories (Furniture and Clothing) also have their document IDs sorted.

 

Price Column (Sorted Inverted Index):

Price

Document IDs (Sorted)

500

d4

700

d2

1000

d1

1200

d3

 

Here, the document IDs are sorted according to the price values. For example, Price = 500 maps to document d4, and Price = 1200 maps to document d3, both stored in a sorted list.

 

Querying with Sorted Inverted Index

The Sorted Inverted Index improves query performance not only for point queries (looking for exact matches) but also for range queries and ordering operations.

 

Query 1: Find documents with Category = 'Electronics'

SELECT * FROM Documents WHERE Category = 'Electronics';

How Pinot Retrieves Data?

·      Looks up Category = 'Electronics' in the index, which maps to d1, d3.

·      Retrieves documents d1 and d3 directly.

 

 Query 2: Find documents with Price BETWEEN 700 AND 1200

 

SELECT * FROM Documents WHERE Price BETWEEN 700 AND 1200;

How Pinot Retrieves Data?

·      Looks up Price values in the index. The list for Price values between 700 and 1200 includes d1, d2, d3.

·      Pinot quickly retrieves documents d1, d2, and d3.

·      The index's sorted order makes it easy to identify which documents lie within the specified range.

 

Query 3: Find documents sorted by Price in descending order?

SELECT * FROM Documents ORDER BY Price DESC;

 

How Pinot Retrieves Data?

The index for Price is already sorted. Pinot can quickly return the documents in descending order by simply reversing the sorted list.

 

Advantages of Sorted Inverted Index

·      Efficient Range Queries: The sorted order of values makes range queries very efficient. You don’t need to scan the entire dataset to find values that fall within a given range.

 

·      Fast Sorting: Queries that require sorting (e.g., ORDER BY clauses) can take advantage of the sorted order in the index, eliminating the need for a full sort operation.

 

·      Lower Disk I/O: By maintaining a sorted list of document IDs for each indexed value, Pinot can avoid performing expensive disk scans when retrieving documents.

 

When to Use Sorted Inverted Index

·      Range Queries: Use the Sorted Inverted Index for columns that are frequently queried with range filters (e.g., BETWEEN, >=, <=).

 

·      Ordering Queries: If you often need to retrieve data sorted by a particular column, the Sorted Inverted Index is perfect for optimizing these queries.

 

·      High Cardinality Columns: For columns with high cardinality (many unique values), such as Price, Timestamp, etc., a Sorted Inverted Index can offer significant performance improvements.

 

In summary, the Sorted Inverted Index in Apache Pinot is an excellent tool for optimizing queries on columns that require fast lookups, range queries, and sorting operations. By maintaining sorted lists of document IDs for each unique value, it ensures that queries run efficiently without the need for full scans or expensive sorting operations.

 

 

 

Previous                                                    Next                                                    Home

Bitmap Inverted Index in Apache Pinot

In modern data processing systems, fast query performance is crucial, especially when handling large datasets. One of the key ways to achieve fast filtering and retrieval of data is by using indexes. Apache Pinot, a distributed columnar store designed for real-time analytics, uses several types of indexes to enhance query speed. One of the most effective types of indexes is the Bitmap Inverted Index.

 

What is a Bitmap Inverted Index?

A Bitmap Inverted Index is an efficient data structure used to index a column with low cardinality. It stores a bitmap (or list of document IDs) for each unique value in a column. Instead of storing a separate record for each row, a bitmap or list of row IDs is used to identify which rows contain the specific value. This enables extremely fast lookups when filtering data.

 

Unlike traditional row-based indexes, where each index entry maps to specific values, a bitmap index maps each unique value to a list of documents (rows) where the value occurs.

 

How Does Bitmap Inverted Index Work?

Let's consider a simple dataset of documents with a Category and Price column.

 

Document ID   

Category 

Price

d1

Electronics   

1000

d2

Furniture

700

d3

Electronics   

1200

d4

Clothing 

500

 

Now, the Bitmap Inverted Index for the Category and Price columns would look like this:

 

Category Column Index:

Category

Document IDs

Electronics   

d1, d3

Furniture

d2

Clothing 

d4

 

Price Column Index:

Price

Document IDs

1000

d1

700

d2

1200

d3

500

d4

 

How Queries Work with Bitmap Inverted Index?

When a query is executed, Apache Pinot can quickly access the Bitmap Inverted Index to filter documents.

 

For example:

 

Query 1: Find documents with Category = 'Electronics'

SELECT * FROM Documents WHERE Category = 'Electronics';

How Pinot Retrieves Data?

·      Looks up the Category = 'Electronics' entry in the index, which maps to d1, d3.

·      Retrieves documents d1 and d3 directly.

 

Query 2: Find documents with Price = 700

SELECT * FROM Documents WHERE Price = 700;

How Pinot Retrieves Data?

·      Looks up the Price = 700 entry in the index, which maps to d2.

·      Retrieves document d2 directly.

 

Advantages of Bitmap Inverted Index

·      Efficient for Low Cardinality Columns: Bitmap indexes are particularly useful when columns contain a limited number of unique values (such as Category, Price, etc.).

·      Fast Filtering: Bitmap indexes allow for quick filtering by directly referencing document IDs where the value exists.

·      Space Efficient: Instead of storing values repeatedly, the index stores only the document IDs where the value appears. This leads to smaller storage requirements.

·      Multi-condition Queries: Bitmap indexes can easily combine results from multiple conditions (using logical operations like AND, OR), making them excellent for complex filtering.

 

When to Use Bitmap Inverted Index?

·      Low Cardinality Columns: When a column has a small number of unique values (e.g., Category, Gender, Region), Bitmap Inverted Index can be highly efficient.

·      Frequent Filters: If certain columns are frequently used for filtering in queries, such as in analytics dashboards, using a Bitmap Inverted Index will greatly improve performance.

·      Real-time Analytics: Bitmap Inverted Indexes are ideal for real-time analytics systems where quick response times are essential, especially for filtering large volumes of data.

 

 

In summary, Bitmap Inverted Indexes in Apache Pinot offer a powerful way to optimize query performance, especially for columns with low cardinality. By mapping unique values to document IDs, Bitmap Inverted Indexes allow fast, space-efficient filtering that can greatly enhance the performance of real-time analytical queries.

 

 

 

Previous                                                    Next                                                    Home