Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

0 votes
0 answers
31 views
is it possible to make the CTE parallel in PostgreSQL 14
I have an analyse query in PostgreSQL 14 that use many CTEs, like this: with a0 as (select count(*) from ccc0) , a1 as (select count(*) from ccc1) , a2 as (select count(*) from ccc2) , a3 as (select count(*) from ccc3) , a4 as (select count(*) from ccc4) , a5 as (select count(*) from ccc5) , a6 as (...
I have an analyse query in PostgreSQL 14 that use many CTEs, like this: with a0 as (select count(*) from ccc0) , a1 as (select count(*) from ccc1) , a2 as (select count(*) from ccc2) , a3 as (select count(*) from ccc3) , a4 as (select count(*) from ccc4) , a5 as (select count(*) from ccc5) , a6 as (select count(*) from ccc6) , a7 as (select count(*) from ccc7) , a8 as (select count(*) from ccc8) , a9 as (select count(*) from ccc9) , a10 as (select count(*) from ccc10) , a11 as (select count(*) from ccc11) , a12 as (select count(*) from ccc12) , a13 as (select count(*) from ccc13) , a14 as (select count(*) from ccc14) , a15 as (select count(*) from ccc15) , a16 as (select count(*) from ccc16) , a17 as (select count(*) from ccc17) , a18 as (select count(*) from ccc18) , a19 as (select count(*) from ccc19) , a20 as (select count(*) from ccc20) , a21 as (select count(*) from ccc21) , a22 as (select count(*) from ccc22) , a23 as (select count(*) from ccc23) select * from a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23; I read some docs that tell set max_parallel_workers_per_gather can make the CTE parallel https://github.com/digoal/blog/blob/master/201903/20190317_17.md , and the https://www.postgresql.org/docs/current/parallel-safety.html docs told: > The following operations are always parallel restricted: > > Scans of common table expressions (CTEs). > > Scans of temporary tables. > > Scans of foreign tables, unless the foreign data wrapper has an > IsForeignScanParallelSafe API that indicates otherwise. > > Plan nodes that reference a correlated SubPlan. is it possible to make the CTE parallel? now each CTE takes more than 7s make the query so slow. I have tried to add index and the result of each CTE more than 100m rows(the data could not filter anymore). if the parallel works, the result can be fetched 7s, if not, the result will take minites to fetch the result.
Dolphin (939 rep)
May 10, 2025, 04:06 AM
Showing page 1 of 1 total questions