gooderp18绿色标准版
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

71 linhas
7.0KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>15.1. How Parallel Query Works</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="parallel-query.html" title="Chapter 15. Parallel Query" /><link rel="next" href="when-can-parallel-query-be-used.html" title="15.2. When Can Parallel Query Be Used?" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">15.1. How Parallel Query Works</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="parallel-query.html" title="Chapter 15. Parallel Query">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="parallel-query.html" title="Chapter 15. Parallel Query">Up</a></td><th width="60%" align="center">Chapter 15. Parallel Query</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="when-can-parallel-query-be-used.html" title="15.2. When Can Parallel Query Be Used?">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="HOW-PARALLEL-QUERY-WORKS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">15.1. How Parallel Query Works</h2></div></div></div><p>
  3. When the optimizer determines that parallel query is the fastest execution
  4. strategy for a particular query, it will create a query plan which includes
  5. a <em class="firstterm">Gather</em> or <em class="firstterm">Gather Merge</em>
  6. node. Here is a simple example:
  7. </p><pre class="screen">
  8. EXPLAIN SELECT * FROM pgbench_accounts WHERE filler LIKE '%x%';
  9. QUERY PLAN
  10. -------------------------------------------------------------------------------------
  11. Gather (cost=1000.00..217018.43 rows=1 width=97)
  12. Workers Planned: 2
  13. -&gt; Parallel Seq Scan on pgbench_accounts (cost=0.00..216018.33 rows=1 width=97)
  14. Filter: (filler ~~ '%x%'::text)
  15. (4 rows)
  16. </pre><p>
  17. </p><p>
  18. In all cases, the <code class="literal">Gather</code> or
  19. <code class="literal">Gather Merge</code> node will have exactly one
  20. child plan, which is the portion of the plan that will be executed in
  21. parallel. If the <code class="literal">Gather</code> or <code class="literal">Gather Merge</code> node is
  22. at the very top of the plan tree, then the entire query will execute in
  23. parallel. If it is somewhere else in the plan tree, then only the portion
  24. of the plan below it will run in parallel. In the example above, the
  25. query accesses only one table, so there is only one plan node other than
  26. the <code class="literal">Gather</code> node itself; since that plan node is a child of the
  27. <code class="literal">Gather</code> node, it will run in parallel.
  28. </p><p>
  29. <a class="link" href="using-explain.html" title="14.1. Using EXPLAIN">Using EXPLAIN</a>, you can see the number of
  30. workers chosen by the planner. When the <code class="literal">Gather</code> node is reached
  31. during query execution, the process which is implementing the user's
  32. session will request a number of <a class="link" href="bgworker.html" title="Chapter 47. Background Worker Processes">background
  33. worker processes</a> equal to the number
  34. of workers chosen by the planner. The number of background workers that
  35. the planner will consider using is limited to at most
  36. <a class="xref" href="runtime-config-resource.html#GUC-MAX-PARALLEL-WORKERS-PER-GATHER">max_parallel_workers_per_gather</a>. The total number
  37. of background workers that can exist at any one time is limited by both
  38. <a class="xref" href="runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES">max_worker_processes</a> and
  39. <a class="xref" href="runtime-config-resource.html#GUC-MAX-PARALLEL-WORKERS">max_parallel_workers</a>. Therefore, it is possible for a
  40. parallel query to run with fewer workers than planned, or even with
  41. no workers at all. The optimal plan may depend on the number of workers
  42. that are available, so this can result in poor query performance. If this
  43. occurrence is frequent, consider increasing
  44. <code class="varname">max_worker_processes</code> and <code class="varname">max_parallel_workers</code>
  45. so that more workers can be run simultaneously or alternatively reducing
  46. <code class="varname">max_parallel_workers_per_gather</code> so that the planner
  47. requests fewer workers.
  48. </p><p>
  49. Every background worker process which is successfully started for a given
  50. parallel query will execute the parallel portion of the plan. The leader
  51. will also execute that portion of the plan, but it has an additional
  52. responsibility: it must also read all of the tuples generated by the
  53. workers. When the parallel portion of the plan generates only a small
  54. number of tuples, the leader will often behave very much like an additional
  55. worker, speeding up query execution. Conversely, when the parallel portion
  56. of the plan generates a large number of tuples, the leader may be almost
  57. entirely occupied with reading the tuples generated by the workers and
  58. performing any further processing steps which are required by plan nodes
  59. above the level of the <code class="literal">Gather</code> node or
  60. <code class="literal">Gather Merge</code> node. In such cases, the leader will
  61. do very little of the work of executing the parallel portion of the plan.
  62. </p><p>
  63. When the node at the top of the parallel portion of the plan is
  64. <code class="literal">Gather Merge</code> rather than <code class="literal">Gather</code>, it indicates that
  65. each process executing the parallel portion of the plan is producing
  66. tuples in sorted order, and that the leader is performing an
  67. order-preserving merge. In contrast, <code class="literal">Gather</code> reads tuples
  68. from the workers in whatever order is convenient, destroying any sort
  69. order that may have existed.
  70. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="parallel-query.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="parallel-query.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="when-can-parallel-query-be-used.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 15. Parallel Query </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 15.2. When Can Parallel Query Be Used?</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1