gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 line
7.6KB

  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.2. When Can Parallel Query Be Used?</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="how-parallel-query-works.html" title="15.1. How Parallel Query Works" /><link rel="next" href="parallel-plans.html" title="15.3. Parallel Plans" /></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.2. When Can Parallel Query Be Used?</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="how-parallel-query-works.html" title="15.1. How Parallel Query Works">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="parallel-plans.html" title="15.3. Parallel Plans">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="WHEN-CAN-PARALLEL-QUERY-BE-USED"><div class="titlepage"><div><div><h2 class="title" style="clear: both">15.2. When Can Parallel Query Be Used?</h2></div></div></div><p>
  3. There are several settings which can cause the query planner not to
  4. generate a parallel query plan under any circumstances. In order for
  5. any parallel query plans whatsoever to be generated, the following
  6. settings must be configured as indicated.
  7. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  8. <a class="xref" href="runtime-config-resource.html#GUC-MAX-PARALLEL-WORKERS-PER-GATHER">max_parallel_workers_per_gather</a> must be set to a
  9. value which is greater than zero. This is a special case of the more
  10. general principle that no more workers should be used than the number
  11. configured via <code class="varname">max_parallel_workers_per_gather</code>.
  12. </p></li></ul></div><p>
  13. In addition, the system must not be running in single-user mode. Since
  14. the entire database system is running in single process in this situation,
  15. no background workers will be available.
  16. </p><p>
  17. Even when it is in general possible for parallel query plans to be
  18. generated, the planner will not generate them for a given query
  19. if any of the following are true:
  20. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  21. The query writes any data or locks any database rows. If a query
  22. contains a data-modifying operation either at the top level or within
  23. a CTE, no parallel plans for that query will be generated. As an
  24. exception, the commands <code class="literal">CREATE TABLE ... AS</code>, <code class="literal">SELECT
  25. INTO</code>, and <code class="literal">CREATE MATERIALIZED VIEW</code> which create a new
  26. table and populate it can use a parallel plan.
  27. </p></li><li class="listitem"><p>
  28. The query might be suspended during execution. In any situation in
  29. which the system thinks that partial or incremental execution might
  30. occur, no parallel plan is generated. For example, a cursor created
  31. using <a class="link" href="sql-declare.html" title="DECLARE">DECLARE CURSOR</a> will never use
  32. a parallel plan. Similarly, a PL/pgSQL loop of the form
  33. <code class="literal">FOR x IN query LOOP .. END LOOP</code> will never use a
  34. parallel plan, because the parallel query system is unable to verify
  35. that the code in the loop is safe to execute while parallel query is
  36. active.
  37. </p></li><li class="listitem"><p>
  38. The query uses any function marked <code class="literal">PARALLEL UNSAFE</code>.
  39. Most system-defined functions are <code class="literal">PARALLEL SAFE</code>,
  40. but user-defined functions are marked <code class="literal">PARALLEL
  41. UNSAFE</code> by default. See the discussion of
  42. <a class="xref" href="parallel-safety.html" title="15.4. Parallel Safety">Section 15.4</a>.
  43. </p></li><li class="listitem"><p>
  44. The query is running inside of another query that is already parallel.
  45. For example, if a function called by a parallel query issues an SQL
  46. query itself, that query will never use a parallel plan. This is a
  47. limitation of the current implementation, but it may not be desirable
  48. to remove this limitation, since it could result in a single query
  49. using a very large number of processes.
  50. </p></li></ul></div><p>
  51. Even when parallel query plan is generated for a particular query, there
  52. are several circumstances under which it will be impossible to execute
  53. that plan in parallel at execution time. If this occurs, the leader
  54. will execute the portion of the plan below the <code class="literal">Gather</code>
  55. node entirely by itself, almost as if the <code class="literal">Gather</code> node were
  56. not present. This will happen if any of the following conditions are met:
  57. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  58. No background workers can be obtained because of the limitation that
  59. the total number of background workers cannot exceed
  60. <a class="xref" href="runtime-config-resource.html#GUC-MAX-WORKER-PROCESSES">max_worker_processes</a>.
  61. </p></li><li class="listitem"><p>
  62. No background workers can be obtained because of the limitation that
  63. the total number of background workers launched for purposes of
  64. parallel query cannot exceed <a class="xref" href="runtime-config-resource.html#GUC-MAX-PARALLEL-WORKERS">max_parallel_workers</a>.
  65. </p></li><li class="listitem"><p>
  66. The client sends an Execute message with a non-zero fetch count.
  67. See the discussion of the
  68. <a class="link" href="protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY" title="52.2.3. Extended Query">extended query protocol</a>.
  69. Since <a class="link" href="libpq.html" title="Chapter 33. libpq - C Library">libpq</a> currently provides no way to
  70. send such a message, this can only occur when using a client that
  71. does not rely on libpq. If this is a frequent
  72. occurrence, it may be a good idea to set
  73. <a class="xref" href="runtime-config-resource.html#GUC-MAX-PARALLEL-WORKERS-PER-GATHER">max_parallel_workers_per_gather</a> to zero in
  74. sessions where it is likely, so as to avoid generating query plans
  75. that may be suboptimal when run serially.
  76. </p></li></ul></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="how-parallel-query-works.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="parallel-plans.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">15.1. How Parallel Query Works </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 15.3. Parallel Plans</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1