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.

39 lines
4.5KB

  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>9.27. Trigger Functions</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="functions-admin.html" title="9.26. System Administration Functions" /><link rel="next" href="functions-event-triggers.html" title="9.28. Event Trigger Functions" /></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">9.27. Trigger Functions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-admin.html" title="9.26. System Administration Functions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</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="functions-event-triggers.html" title="9.28. Event Trigger Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-TRIGGER"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.27. Trigger Functions</h2></div></div></div><a id="id-1.5.8.32.2" class="indexterm"></a><p>
  3. Currently <span class="productname">PostgreSQL</span> provides one built in trigger
  4. function, <code class="function">suppress_redundant_updates_trigger</code>,
  5. which will prevent any update
  6. that does not actually change the data in the row from taking place, in
  7. contrast to the normal behavior which always performs the update
  8. regardless of whether or not the data has changed. (This normal behavior
  9. makes updates run faster, since no checking is required, and is also
  10. useful in certain cases.)
  11. </p><p>
  12. Ideally, you should normally avoid running updates that don't actually
  13. change the data in the record. Redundant updates can cost considerable
  14. unnecessary time, especially if there are lots of indexes to alter,
  15. and space in dead rows that will eventually have to be vacuumed.
  16. However, detecting such situations in client code is not
  17. always easy, or even possible, and writing expressions to detect
  18. them can be error-prone. An alternative is to use
  19. <code class="function">suppress_redundant_updates_trigger</code>, which will skip
  20. updates that don't change the data. You should use this with care,
  21. however. The trigger takes a small but non-trivial time for each record,
  22. so if most of the records affected by an update are actually changed,
  23. use of this trigger will actually make the update run slower.
  24. </p><p>
  25. The <code class="function">suppress_redundant_updates_trigger</code> function can be
  26. added to a table like this:
  27. </p><pre class="programlisting">
  28. CREATE TRIGGER z_min_update
  29. BEFORE UPDATE ON tablename
  30. FOR EACH ROW EXECUTE FUNCTION suppress_redundant_updates_trigger();
  31. </pre><p>
  32. In most cases, you would want to fire this trigger last for each row.
  33. Bearing in mind that triggers fire in name order, you would then
  34. choose a trigger name that comes after the name of any other trigger
  35. you might have on the table.
  36. </p><p>
  37. For more information about creating triggers, see
  38. <a class="xref" href="sql-createtrigger.html" title="CREATE TRIGGER"><span class="refentrytitle">CREATE TRIGGER</span></a>.
  39. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-admin.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-event-triggers.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.26. System Administration Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.28. Event Trigger Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1