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.).
- Without Index: Calculate exact distance for ALL records (expensive)
- With H3 Index:
- Find hexagon containing given point
- Find hexagons fully contained within the searched area
- Include all points associated with those hexagons
- Find hexagons overlapping searched area
- Calculate exact distance for records in those hexagons
Query Plan Analysis
Using EXPLAIN PLAN FOR
The most important tool for geospatial performance optimization: Single-stage query engine (SSQE):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 Query Plan Example:
SSQE:MSQE:
FilterH3Index
in MSQE.
When: ST_Distance with range conditionsEXPLAIN PLAN Examples
Here are real examples of what you should see when H3 indexes are working: FILTER_H3_INDEX Example (ST_Distance):FILTER_H3_INDEX
for distance-based queriesINCLUSION_FILTER_H3_INDEX
for containment queriesDOC_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- Excellent for queries around the target resolution
- Suboptimal for very different search radii
Multi-Resolution Approach (Recommended)
When to use: Varied query patterns with different search radii- 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
Resolutions | Query Performance | Storage Overhead | Memory Usage | Use Case |
---|---|---|---|---|
[8] | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | Low | Uniform patterns |
[5, 8] | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | Medium | Most applications |
[5, 8, 11] | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | Medium-High | Varied patterns |
[3, 6, 9, 12] | ⭐⭐⭐⭐⭐ | ⭐⭐ | High | Complex analytics |
[1, 4, 7, 10, 13] | ⭐⭐⭐⭐ | ⭐ | Very High | Over-optimization |
Resolution Tuning Examples
Retail Store Locator:- Resolution 7: “Stores within 5km” queries
- Resolution 10: “Nearest store” precision queries
- Resolution 4: Regional route planning
- Resolution 7: City-wide delivery zones
- Resolution 10: Precise delivery locations
- 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:Containment Queries
ST_Within Optimization:Advanced Query Optimization
Multiple Spatial Conditions:Performance Monitoring
Key Performance Metrics
Monitor:
- Overall query response time
- Spatial filter execution time
- Index effectiveness ratio
Performance Benchmarking
Create Test Scenarios:Advanced Optimization Techniques
Query Rewriting for Performance
Distance Approximation:Memory Optimization
Column Selection:Troubleshooting Performance Issues
Common Performance Problems
Slow Query Performance
Slow Query Performance
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
Index Not Being Used
Index Not Being Used
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)
High Memory Usage
High Memory Usage
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
Poor Index Effectiveness
Poor Index Effectiveness
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