@@ -3192,7 +3192,7 @@ SELECT plainto_tsquery('supernovae stars');
3192
3192
</sect1>
3193
3193
3194
3194
<sect1 id="textsearch-indexes">
3195
- <title>GiST and GIN Index Types</title>
3195
+ <title>GIN and GiST Index Types</title>
3196
3196
3197
3197
<indexterm zone="textsearch-indexes">
3198
3198
<primary>text search</primary>
@@ -3213,18 +3213,17 @@ SELECT plainto_tsquery('supernovae stars');
3213
3213
<term>
3214
3214
<indexterm zone="textsearch-indexes">
3215
3215
<primary>index</primary>
3216
- <secondary>GiST </secondary>
3216
+ <secondary>GIN </secondary>
3217
3217
<tertiary>text search</tertiary>
3218
3218
</indexterm>
3219
3219
3220
- <literal>CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING GIST (<replaceable>column</replaceable>);</literal>
3220
+ <literal>CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING GIN (<replaceable>column</replaceable>);</literal>
3221
3221
</term>
3222
3222
3223
3223
<listitem>
3224
3224
<para>
3225
- Creates a GiST (Generalized Search Tree)-based index.
3226
- The <replaceable>column</replaceable> can be of <type>tsvector</> or
3227
- <type>tsquery</> type.
3225
+ Creates a GIN (Generalized Inverted Index)-based index.
3226
+ The <replaceable>column</replaceable> must be of <type>tsvector</> type.
3228
3227
</para>
3229
3228
</listitem>
3230
3229
</varlistentry>
@@ -3234,17 +3233,18 @@ SELECT plainto_tsquery('supernovae stars');
3234
3233
<term>
3235
3234
<indexterm zone="textsearch-indexes">
3236
3235
<primary>index</primary>
3237
- <secondary>GIN </secondary>
3236
+ <secondary>GiST </secondary>
3238
3237
<tertiary>text search</tertiary>
3239
3238
</indexterm>
3240
3239
3241
- <literal>CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING GIN (<replaceable>column</replaceable>);</literal>
3240
+ <literal>CREATE INDEX <replaceable>name</replaceable> ON <replaceable>table</replaceable> USING GIST (<replaceable>column</replaceable>);</literal>
3242
3241
</term>
3243
3242
3244
3243
<listitem>
3245
3244
<para>
3246
- Creates a GIN (Generalized Inverted Index)-based index.
3247
- The <replaceable>column</replaceable> must be of <type>tsvector</> type.
3245
+ Creates a GiST (Generalized Search Tree)-based index.
3246
+ The <replaceable>column</replaceable> can be of <type>tsvector</> or
3247
+ <type>tsquery</> type.
3248
3248
</para>
3249
3249
</listitem>
3250
3250
</varlistentry>
@@ -3253,13 +3253,18 @@ SELECT plainto_tsquery('supernovae stars');
3253
3253
</para>
3254
3254
3255
3255
<para>
3256
- There are substantial performance differences between the two index types,
3257
- so it is important to understand their characteristics.
3256
+ GIN indexes are the preferred text search index type. As inverted
3257
+ indexes, they contain an index entry for each word (lexeme), with a
3258
+ compressed list of matching locations. Multi-word searches can find
3259
+ the first match, then use the index to remove rows that are lacking
3260
+ additional words. GIN indexes store only the words (lexemes) of
3261
+ <type>tsvector</> values, and not their weight labels. Thus a table
3262
+ row recheck is needed when using a query that involves weights.
3258
3263
</para>
3259
3264
3260
3265
<para>
3261
3266
A GiST index is <firstterm>lossy</firstterm>, meaning that the index
3262
- may produce false matches, and it is necessary
3267
+ might produce false matches, and it is necessary
3263
3268
to check the actual table row to eliminate such false matches.
3264
3269
(<productname>PostgreSQL</productname> does this automatically when needed.)
3265
3270
GiST indexes are lossy because each document is represented in the
@@ -3280,53 +3285,6 @@ SELECT plainto_tsquery('supernovae stars');
3280
3285
recommended.
3281
3286
</para>
3282
3287
3283
- <para>
3284
- GIN indexes are not lossy for standard queries, but their performance
3285
- depends logarithmically on the number of unique words.
3286
- (However, GIN indexes store only the words (lexemes) of <type>tsvector</>
3287
- values, and not their weight labels. Thus a table row recheck is needed
3288
- when using a query that involves weights.)
3289
- </para>
3290
-
3291
- <para>
3292
- In choosing which index type to use, GiST or GIN, consider these
3293
- performance differences:
3294
-
3295
- <itemizedlist spacing="compact" mark="bullet">
3296
- <listitem>
3297
- <para>
3298
- GIN index lookups are about three times faster than GiST
3299
- </para>
3300
- </listitem>
3301
- <listitem>
3302
- <para>
3303
- GIN indexes take about three times longer to build than GiST
3304
- </para>
3305
- </listitem>
3306
- <listitem>
3307
- <para>
3308
- GIN indexes are moderately slower to update than GiST indexes, but
3309
- about 10 times slower if fast-update support was disabled
3310
- (see <xref linkend="gin-fast-update"> for details)
3311
- </para>
3312
- </listitem>
3313
- <listitem>
3314
- <para>
3315
- GIN indexes are two-to-three times larger than GiST indexes
3316
- </para>
3317
- </listitem>
3318
- </itemizedlist>
3319
- </para>
3320
-
3321
- <para>
3322
- As a rule of thumb, <acronym>GIN</acronym> indexes are best for static data
3323
- because lookups are faster. For dynamic data, GiST indexes are
3324
- faster to update. Specifically, <acronym>GiST</acronym> indexes are very
3325
- good for dynamic data and fast if the number of unique words (lexemes) is
3326
- under 100,000, while <acronym>GIN</acronym> indexes will handle 100,000+
3327
- lexemes better but are slower to update.
3328
- </para>
3329
-
3330
3288
<para>
3331
3289
Note that <acronym>GIN</acronym> index build time can often be improved
3332
3290
by increasing <xref linkend="guc-maintenance-work-mem">, while
@@ -3335,7 +3293,7 @@ SELECT plainto_tsquery('supernovae stars');
3335
3293
</para>
3336
3294
3337
3295
<para>
3338
- Partitioning of big collections and the proper use of GiST and GIN indexes
3296
+ Partitioning of big collections and the proper use of GIN and GiST indexes
3339
3297
allows the implementation of very fast searches with online update.
3340
3298
Partitioning can be done at the database level using table inheritance,
3341
3299
or by distributing documents over
0 commit comments