codekingpro/portable-devtools
115k
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>70.5. GIN Tips and Tricks</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 Vsnapshot" /><link rel="prev" href="gin-implementation.html" title="70.4. Implementation" /><link rel="next" href="gin-limit.html" title="70.6. Limitations" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">70.5. GIN Tips and Tricks</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="gin-implementation.html" title="70.4. Implementation">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="gin.html" title="Chapter 70. GIN Indexes">Up</a></td><th width="60%" align="center">Chapter 70. GIN Indexes</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="gin-limit.html" title="70.6. Limitations">Next</a></td></tr></table><hr /></div><div class="sect1" id="GIN-TIPS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">70.5. GIN Tips and Tricks <a href="#GIN-TIPS" class="id_link">#</a></h2></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">Create vs. insert</span></dt><dd><p>3 Insertion into a <acronym class="acronym">GIN</acronym> index can be slow4 due to the likelihood of many keys being inserted for each item.5 So, for bulk insertions into a table it is advisable to drop the GIN6 index and recreate it after finishing bulk insertion.7 </p><p>8 When <code class="literal">fastupdate</code> is enabled for <acronym class="acronym">GIN</acronym>9 (see <a class="xref" href="gin-implementation.html#GIN-FAST-UPDATE" title="70.4.1. GIN Fast Update Technique">Section 70.4.1</a> for details), the penalty is10 less than when it is not. But for very large updates it may still be11 best to drop and recreate the index.12 </p></dd><dt><span class="term"><a class="xref" href="runtime-config-resource.html#GUC-MAINTENANCE-WORK-MEM">maintenance_work_mem</a></span></dt><dd><p>13 Build time for a <acronym class="acronym">GIN</acronym> index is very sensitive to14 the <code class="varname">maintenance_work_mem</code> setting; it doesn't pay to15 skimp on work memory during index creation.16 </p></dd><dt><span class="term"><a class="xref" href="runtime-config-client.html#GUC-GIN-PENDING-LIST-LIMIT">gin_pending_list_limit</a></span></dt><dd><p>17 During a series of insertions into an existing <acronym class="acronym">GIN</acronym>18 index that has <code class="literal">fastupdate</code> enabled, the system will clean up19 the pending-entry list whenever the list grows larger than20 <code class="varname">gin_pending_list_limit</code>. To avoid fluctuations in observed21 response time, it's desirable to have pending-list cleanup occur in the22 background (i.e., via autovacuum). Foreground cleanup operations23 can be avoided by increasing <code class="varname">gin_pending_list_limit</code>24 or making autovacuum more aggressive.25 However, enlarging the threshold of the cleanup operation means that26 if a foreground cleanup does occur, it will take even longer.27 </p><p>28 <code class="varname">gin_pending_list_limit</code> can be overridden for individual29 GIN indexes by changing storage parameters, which allows each30 GIN index to have its own cleanup threshold.31 For example, it's possible to increase the threshold only for the GIN32 index which can be updated heavily, and decrease it otherwise.33 </p></dd><dt><span class="term"><a class="xref" href="runtime-config-client.html#GUC-GIN-FUZZY-SEARCH-LIMIT">gin_fuzzy_search_limit</a></span></dt><dd><p>34 The primary goal of developing <acronym class="acronym">GIN</acronym> indexes was35 to create support for highly scalable full-text search in36 <span class="productname">PostgreSQL</span>, and there are often situations when37 a full-text search returns a very large set of results. Moreover, this38 often happens when the query contains very frequent words, so that the39 large result set is not even useful. Since reading many40 tuples from the disk and sorting them could take a lot of time, this is41 unacceptable for production. (Note that the index search itself is very42 fast.)43 </p><p>44 To facilitate controlled execution of such queries,45 <acronym class="acronym">GIN</acronym> has a configurable soft upper limit on the46 number of rows returned: the47 <code class="varname">gin_fuzzy_search_limit</code> configuration parameter.48 It is set to 0 (meaning no limit) by default.49 If a non-zero limit is set, then the returned set is a subset of50 the whole result set, chosen at random.51 </p><p>52 <span class="quote">“<span class="quote">Soft</span>”</span> means that the actual number of returned results53 could differ somewhat from the specified limit, depending on the query54 and the quality of the system's random number generator.55 </p><p>56 From experience, values in the thousands (e.g., 5000 — 20000)57 work well.58 </p></dd></dl></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="gin-implementation.html" title="70.4. Implementation">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="gin.html" title="Chapter 70. GIN Indexes">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="gin-limit.html" title="70.6. Limitations">Next</a></td></tr><tr><td width="40%" align="left" valign="top">70.4. Implementation </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 70.6. Limitations</td></tr></table></div></body></html>