这些 Postgres 子查询子查询 InitPlans 运行 是并行的吗?

Are these Postgres Subquery Subselect InitPlans Run in Parallel?

我正在尝试了解 Postgres 的工作原理。读完后,https://www.postgresql.org/message-id/4572.1280671706%40sss.pgh.pa.us 这些子查询是子查询,因为它们不引用外部查询中的任何内容,对吧?所以如果它们是独立的,那是否意味着它们自然 运行 concurrently/parallel?

我在想这些可以 运行 与工作人员并行,但听起来只有一个单独的查询可能 运行 并行?比如,它会用并行工作者分解顺序扫描或索引扫描?

Nested Loop Left Join  (cost=20.40..28.41 rows=1 width=2547) (actual time=0.086..0.087 rows=1 loops=1)
  Join Filter: (load_profiles.project_id = projects.id)
  InitPlan 1 (returns [=11=])
    ->  Index Scan using index_designs_on_project_id_and_tenant_id on designs  (cost=0.11..4.12 rows=1 width=16) (actual time=0.010..0.013 rows=2 loops=1)
          Index Cond: ((project_id = '10821ae7-2867-46b5-a3ac-6b4cb709f7c0'::uuid) AND (tenant_id = '5189ea23-726f-4115-991d-959d09e3b858'::uuid))
  InitPlan 2 (returns )
    ->  Index Scan using index_design_requests_on_project_id_and_tenant_id on design_requests  (cost=0.08..4.09 rows=1 width=16) (actual time=0.006..0.006 rows=0 loops=1)
          Index Cond: ((project_id = '10821ae7-2867-46b5-a3ac-6b4cb709f7c0'::uuid) AND (tenant_id = '5189ea23-726f-4115-991d-959d09e3b858'::uuid))
  InitPlan 3 (returns )
    ->  Index Scan using index_ortho_images_on_parent_type_and_parent_id on ortho_images  (cost=0.11..7.90 rows=1 width=16) (actual time=0.013..0.015 rows=2 loops=1)
          Index Cond: (((parent_type)::text = 'Project'::text) AND (parent_id = '10821ae7-2867-46b5-a3ac-6b4cb709f7c0'::uuid))
          Filter: (tenant_id = '5189ea23-726f-4115-991d-959d09e3b858'::uuid)
  InitPlan 4 (returns )
    ->  Index Scan using index_elevation_sources_on_parent_type_and_parent_id on elevation_sources  (cost=0.08..4.09 rows=1 width=16) (actual time=0.010..0.010 rows=1 loops=1)
          Index Cond: (((parent_type)::text = 'Project'::text) AND (parent_id = '10821ae7-2867-46b5-a3ac-6b4cb709f7c0'::uuid))
          Filter: (tenant_id = '5189ea23-726f-4115-991d-959d09e3b858'::uuid)
  ->  Index Scan using installations_pkey on projects  (cost=0.09..4.09 rows=1 width=2403) (actual time=0.020..0.021 rows=1 loops=1)
        Index Cond: (id = '10821ae7-2867-46b5-a3ac-6b4cb709f7c0'::uuid)
        Filter: (tenant_id = '5189ea23-726f-4115-991d-959d09e3b858'::uuid)
  ->  Index Scan using index_load_profiles_on_project_id_and_tenant_id on load_profiles  (cost=0.11..4.12 rows=1 width=32) (actual time=0.011..0.011 rows=1 loops=1)
        Index Cond: (project_id = '10821ae7-2867-46b5-a3ac-6b4cb709f7c0'::uuid)
Planning time: 0.576 ms
Execution time: 0.167 ms

执行计划仅在计划中某处存在 Gather 节点(从并行工作程序收集结果)时才使用并行查询。所以这些节点将不会并行执行。

PostgreSQL 尚不支持并行化此类任务,而且将来也不大可能,因为所有并行工作人员可能都需要这些结果中的每一个。