docs: update guidelines on when to use GIN and GiST indexes
authorBruce Momjian
Mon, 5 Oct 2015 17:38:36 +0000 (13:38 -0400)
committerBruce Momjian
Mon, 5 Oct 2015 17:38:36 +0000 (13:38 -0400)
Report by Tomas Vondra

Backpatch through 9.5

doc/src/sgml/textsearch.sgml

index ab08eb912ff5ec25a9ea35005b1b3e0812f756eb..d66b4d5d5f98c4f8bd02b6a87a328317c59d022f 100644 (file)
@@ -3192,7 +3192,7 @@ SELECT plainto_tsquery('supernovae stars');
  
 
  
-  G<span class="marked">iST and GIN</span> Index Types
+  G<span class="marked">IN and GiST</span> Index Types
 
   
    text search
@@ -3213,18 +3213,17 @@ SELECT plainto_tsquery('supernovae stars');
      
      
       index
-      GiST
+      GIN
       text search
      
 
-      CREATE INDEX name ON table USING GIST (column);
+      CREATE INDEX name ON table USING GIN (column);
      
 
      
       
-       Creates a GiST (Generalized Search Tree)-based index.
-       The column can be of tsvector or
-       tsquery type.
+       Creates a GIN (Generalized Inverted Index)-based index.
+       The column must be of tsvector type.
       
      
     
@@ -3234,17 +3233,18 @@ SELECT plainto_tsquery('supernovae stars');
      
      
       index
-      GIN
+      GiST
       text search
      
 
-      CREATE INDEX name ON table USING GIN (column);
+      CREATE INDEX name ON table USING GIST (column);
      
 
      
       
-       Creates a GIN (Generalized Inverted Index)-based index.
-       The column must be of tsvector type.
+       Creates a GiST (Generalized Search Tree)-based index.
+       The column can be of tsvector or
+       tsquery type.
       
      
     
@@ -3253,13 +3253,18 @@ SELECT plainto_tsquery('supernovae stars');
   
 
   
-   There are substantial performance differences between the two index types,
-   so it is important to understand their characteristics.
+   GIN indexes are the preferred text search index type.  As inverted
+   indexes, they contain an index entry for each word (lexeme), with a
+   compressed list of matching locations.  Multi-word searches can find
+   the first match, then use the index to remove rows that are lacking
+   additional words.  GIN indexes store only the words (lexemes) of
+   tsvector values, and not their weight labels.  Thus a table
+   row recheck is needed when using a query that involves weights.
   
 
   
    A GiST index is lossy, meaning that the index
-   may produce false matches, and it is necessary
+   might produce false matches, and it is necessary
    to check the actual table row to eliminate such false matches.
    (PostgreSQL does this automatically when needed.)
    GiST indexes are lossy because each document is represented in the
@@ -3280,53 +3285,6 @@ SELECT plainto_tsquery('supernovae stars');
    recommended.
   
 
-  
-   GIN indexes are not lossy for standard queries, but their performance
-   depends logarithmically on the number of unique words.
-   (However, GIN indexes store only the words (lexemes) of tsvector
-   values, and not their weight labels.  Thus a table row recheck is needed
-   when using a query that involves weights.)
-  
-
-  
-   In choosing which index type to use, GiST or GIN, consider these
-   performance differences:
-
-   
-    
-     
-      GIN index lookups are about three times faster than GiST
-     
-    
-    
-     
-      GIN indexes take about three times longer to build than GiST
-     
-    
-    
-     
-      GIN indexes are moderately slower to update than GiST indexes, but
-      about 10 times slower if fast-update support was disabled
-      (see  for details)
-     
-    
-    
-     
-      GIN indexes are two-to-three times larger than GiST indexes
-     
-    
-   
-  
-
-  
-   As a rule of thumb, GIN indexes are best for static data
-   because lookups are faster.  For dynamic data, GiST indexes are
-   faster to update.  Specifically, GiST indexes are very
-   good for dynamic data and fast if the number of unique words (lexemes) is
-   under 100,000, while GIN indexes will handle 100,000+
-   lexemes better but are slower to update.
-  
-
   
    Note that GIN index build time can often be improved
    by increasing , while
@@ -3335,7 +3293,7 @@ SELECT plainto_tsquery('supernovae stars');
   
 
   
-   Partitioning of big collections and the proper use of GiST and GIN indexes
+   Partitioning of big collections and the proper use of GIN and GiST indexes
    allows the implementation of very fast searches with online update.
    Partitioning can be done at the database level using table inheritance,
    or by distributing documents over