Skip to main content
Optimize geospatial query performance with Apache Pinot. This guide covers everything from basic performance principles to tuning techniques.

Query Plan Analysis

Use EXPLAIN PLAN to understand and verify index usage

Index Optimization

Configure H3 resolutions for optimal performance

Query Patterns

Structure queries to use geospatial indexes effectively

Performance Monitoring

Monitor and measure geospatial query performance

Performance Fundamentals

How H3 Index Acceleration Works

Understanding the two-phase optimization approach is key to writing efficient queries:
1

Coarse Filtering (H3 Index)

The H3 index quickly identifies candidate records within nearby hexagons, eliminating the vast majority of data from consideration.
2

Precise Filtering (Geospatial Functions)

Only records in candidate hexagons undergo expensive precise geospatial calculations (ST_Distance, ST_Within, etc.).
Example: Finding locations within 5km
  • Without Index: Calculate exact distance for ALL records (expensive)
  • With H3 Index:
    1. Find hexagon containing given point
    2. Find hexagons fully contained within the searched area
    3. Include all points associated with those hexagons
    4. Find hexagons overlapping searched area
    5. Calculate exact distance for records in those hexagons
Important: If query distance is >100x the hexagon size, the index is automatically bypassed and falls back to full scan for performance reasons.

Query Plan Analysis

Using EXPLAIN PLAN FOR

The most important tool for geospatial performance optimization: Single-stage query engine (SSQE):
Multi-stage query engine MSQE:
Setting explainAskingServers query option is necessary for MSQE to show usage of segment-level indexes.

Index Usage Operators

Look for these operators in your query plans:
Shows as FilterH3Index in MSQE. When: ST_Distance with range conditions
Query Plan Example: SSQE:
MSQE:

EXPLAIN PLAN Examples

Here are real examples of what you should see when H3 indexes are working: FILTER_H3_INDEX Example (ST_Distance):
Output:
INCLUSION_FILTER_H3_INDEX Example (ST_Contains):
Output:
Key Indicators:
  • FILTER_H3_INDEX for distance-based queries
  • INCLUSION_FILTER_H3_INDEX for containment queries
  • DOC_ID_SET showing efficient document filtering
  • No FILTER operator (which would indicate full scan)

Index Optimization

Resolution Selection Strategy

Choose H3 resolutions based on your query patterns and performance requirements:

Single Resolution Approach

When to use: Uniform query patterns with consistent search radius
Query Performance:
  • Excellent for queries around the target resolution
  • Suboptimal for very different search radii
When to use: Varied query patterns with different search radii
Resolution Selection Algorithm:
  • Resolution 5 (8km): For queries >20km radius
  • Resolution 8 (500m): For queries 1-20km radius
  • Resolution 11 (25m): For queries <1km radius

Performance vs Storage Analysis

Resolution Tuning Examples

Retail Store Locator:
  • Resolution 7: “Stores within 5km” queries
  • Resolution 10: “Nearest store” precision queries
Logistics & Delivery:
  • Resolution 4: Regional route planning
  • Resolution 7: City-wide delivery zones
  • Resolution 10: Precise delivery locations
Global IoT Network:
  • Resolution 2: Country/region analysis
  • Resolution 5: City-level aggregation
  • Resolution 8: Local area monitoring
  • Resolution 11: Device-level precision

Optimized Query Patterns

Distance-Based Queries

Index-Optimized Patterns:
Non-Optimized Patterns:

Containment Queries

ST_Within Optimization:
ST_Contains Optimization:

Advanced Query Optimization

Multiple Spatial Conditions:
Subquery Optimization:
Spatial Aggregations:

Performance Monitoring

Key Performance Metrics

Monitor:
  • Overall query response time
  • Spatial filter execution time
  • Index effectiveness ratio
Tools:

Performance Benchmarking

Create Test Scenarios:
Performance Comparison:

Advanced Optimization Techniques

Query Rewriting for Performance

Distance Approximation:
Batch Spatial Operations:

Memory Optimization

Column Selection:
Result Set Limiting:

Troubleshooting Performance Issues

Common Performance Problems

Symptoms: Queries taking >1 second, high CPU usageDiagnosis:
Solutions:
  • Verify H3 index operators are present
  • Check argument order in spatial functions
  • Ensure resolutions match query patterns
  • Add additional non-spatial filters
Symptoms: EXPLAIN PLAN shows FILTER instead of FILTER_H3_INDEXDiagnosis Checklist:
  • Column configured with encodingType: "RAW"
  • Column in noDictionaryColumns array
  • H3 index configured with appropriate resolution
  • Query uses correct argument order
  • Spatial function is supported (ST_Distance, ST_Within, ST_Contains)
  • Query distance is not >100x the hexagon size (auto-reverts to full scan)
Distance vs Resolution Check: If your query distance is much larger than hexagon size, the H3IndexFilterOperator automatically reverts to non-indexed expression for performance reasons.Fix Example:
Symptoms: Out of memory errors, slow ingestionSolutions:
  • Reduce number of H3 resolutions (keep 2-3 max)
  • Remove very high resolutions (13-15) if not needed
  • Optimize query to select fewer columns
  • Use LIMIT in interactive queries
Memory-Optimized Config:
Symptoms: High filteredDocs/totalDocs ratio in query plansAnalysis:
Solutions:
  • Adjust H3 resolutions to better match query radius
  • Add complementary non-spatial filters
  • Consider table partitioning strategies

Performance Tuning Workflow

1

Baseline Measurement

Measure current performance and identify bottlenecks using EXPLAIN PLAN and query timing.
2

Index Configuration

Optimize H3 resolutions based on query patterns and test different configurations.
3

Query Optimization

Rewrite queries to use indexes effectively and add non-spatial filters where possible.
4

Validation

Verify improvements using query plans and performance benchmarks.
5

Monitoring

Set up ongoing monitoring of query performance and index effectiveness.

Best Practices Summary

Configuration Best Practices

  • Use 2-3 H3 resolutions for most applications
  • Choose resolutions based on typical query radius
  • Always disable dictionary encoding (encodingType: "RAW")
  • Test resolution configurations with real query patterns

Query Best Practices

  • Use correct argument order in spatial functions
  • Combine spatial and non-spatial filters efficiently
  • Use EXPLAIN PLAN to verify index usage
  • Limit result sets in interactive applications

Performance Monitoring

  • Monitor query execution times regularly
  • Check index effectiveness ratios
  • Benchmark different query patterns
  • Set up alerts for performance degradation