SQL Optimizations
Leverage predicate pushdown
Predicate pushdown allows filtering operations (predicates) to be applied as early as possible in the query pipeline. This means that instead of retrieving all data and then filtering it, RisingWave filters the data at the storage level. Examples:Use indexes to accelerate your queries
Indexes in RisingWave are used to accelerate batch queries. They are incrementally maintained, similar to materialized views but with minimal computation. Therefore, they are cost-effective to create. We encourage users to detect the patterns in batch queries and create indexes if the pattern occurs frequently or/and a batch query is slow. You can check the Indexes page for more details on how to create and use indexes.Memory management for batch queries
Spilling to disk
When batch queries process large amounts of data that exceed available memory, RisingWave automatically spills intermediate results to disk to prevent out-of-memory errors. This spilling behavior applies to memory-intensive operations like:- Large hash joins
- Hash aggregations with high cardinality
- Sorting operations on large datasets
RW_BATCH_SPILL_DIR environment variable (default: /tmp/). Spilling trades memory for disk I/O, so queries may slow down when spilling occurs.
Compute memory limits
On serving-only Compute Nodes, the available memory for query execution (compute memory) is calculated as:- Reduce block cache and meta cache sizes in node configuration
- Use query modes (
SET QUERY_MODE TO distributed) to distribute memory load - Break complex queries into smaller steps using materialized views
- Add appropriate indexes to reduce data scanned