All Products
Search
Document Center

PolarDB:Enable the spatio-temporal parallel query feature

Last Updated:Mar 28, 2026

Spatio-temporal queries over large datasets are CPU-intensive and can be slow with a single worker. GanosBase leverages PostgreSQL's parallel query engine to distribute these queries across multiple workers, reducing query time significantly for compute-intensive spatio-temporal functions.

How parallel query works

When the query planner decides parallel execution is worthwhile, it creates a plan where a Gather node launches worker processes, each scanning a portion of the table in parallel, then merges the results. Parallel query runs at the table level.

For GanosBase functions, the planner also weighs the estimated function cost against the overhead of parallel setup. If the data size of the table is small, the planner treats parallel execution as not worth the overhead and disables it by default — this is why Step 2 (raising the function cost) is required for compute-intensive functions.

Usage notes

  • High CPU load: Running many parallel workers increases CPU usage. If CPU load is a concern, set max_parallel_workers_per_gather to 2.

  • High-concurrency environments: When parallel query runs under heavy concurrent load on a memory-constrained server, size work_mem carefully. The following constraint must hold:

    concurrent_requests x parallel_workers x work_mem <= 60% of server memory

    The minimum value for work_mem is 64 KB.

Enable parallel query

Step 1: Configure parallel query parameters

Set the following parameters in postgresql.conf:

ParameterDescriptionRange / values
max_parallel_workersTotal number of parallel workers available across all queries8–32; must be less than max_worker_processes
max_parallel_workers_per_gatherMaximum workers for a single Gather node2–4; must be less than max_parallel_workers
force_parallel_modeForce the planner to use parallel execution regardless of cost estimateson to enable

To override the planner's worker estimate for a specific table — useful when the planner underestimates the benefit of parallelism — run:

ALTER TABLE table_name SET (parallel_workers = n);

where n is the target number of parallel workers. Choose a value consistent with max_parallel_workers_per_gather.

Step 2: Increase the cost of GanosBase functions

After installing a GanosBase module extension, its functions are assigned a default cost. If the data size of the associated table is small, the planner treats parallel execution as not worth the overhead and disables it by default.

For compute-intensive spatio-temporal functions where parallel execution provides a clear benefit, raise the function cost so the planner considers parallel plans.