Is it possible to execute parallel query in Postgres which queries partitioned table by using union all?

1.3k Views Asked by At

Hello I'm playing around with postgres as a search engine by using GIN indexes with trigram module and partitioned table and I'm trying to parallelize the query but no matter what I set the query is always sequential any ideas are welcome. Check out the image for more info. Here is an query (test_trgm_x those are partitions which each holds around 550k rows)

SELECT * FROM test_trgm_1 WHERE n = 1 AND t ~ '(ulpa)'
UNION ALL
SELECT * FROM test_trgm_2 WHERE n = 2 AND t ~ '(piente)';

enter image description here

1

There are 1 best solutions below

2
jjanes On

The default setting of parallel_tuple_cost is quite high. This discourages use of parallel query in cases like yours, where nearly every row found in the parallel worker needs to be shoved up to the leader. If you set parallel_tuple_cost=0, it will really encourage use of parallel query (even when it doesn't make sense to use it).