8000 Pass down "logically unchanged index" hint. · postgrespro/postgres@9dc718b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9dc718b

Browse files
Pass down "logically unchanged index" hint.
Add an executor aminsert() hint mechanism that informs index AMs that the incoming index tuple (the tuple that accompanies the hint) is not being inserted by execution of an SQL statement that logically modifies a 8000 ny of the index's key columns. The hint is received by indexes when an UPDATE takes place that does not apply an optimization like heapam's HOT (though only for indexes where all key columns are logically unchanged). Any index tuple that receives the hint on insert is expected to be a duplicate of at least one existing older version that is needed for the same logical row. Related versions will typically be stored on the same index page, at least within index AMs that apply the hint. Recognizing the difference between MVCC version churn duplicates and true logical row duplicates at the index AM level can help with cleanup of garbage index tuples. Cleanup can intelligently target tuples that are likely to be garbage, without wasting too many cycles on less promising tuples/pages (index pages with little or no version churn). This is infrastructure for an upcoming commit that will teach nbtree to perform bottom-up index deletion. No index AM actually applies the hint just yet. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Victor Yegorov <vyegorov@gmail.com> Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
1 parent 39b0369 commit 9dc718b

File tree

31 files changed

+214
-25
lines changed
  • common
  • gin
  • gist
  • hash
  • heap
  • index
  • nbtree
  • spgist
  • catalog
  • commands
  • executor
  • replication/logical
  • include
  • test/modules/dummy_index_am
  • 31 files changed

    +214
    -25
    lines changed

    contrib/bloom/blinsert.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -198,6 +198,7 @@ bool
    198198
    blinsert(Relation index, Datum *values, bool *isnull,
    199199
    ItemPointer ht_ctid, Relation heapRel,
    200200
    IndexUniqueCheck checkUnique,
    201+
    bool indexUnchanged,
    201202
    IndexInfo *indexInfo)
    202203
    {
    203204
    BloomState blstate;

    contrib/bloom/bloom.h

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -192,6 +192,7 @@ extern bool blvalidate(Oid opclassoid);
    192192
    extern bool blinsert(Relation index, Datum *values, bool *isnull,
    193193
    ItemPointer ht_ctid, Relation heapRel,
    194194
    IndexUniqueCheck checkUnique,
    195+
    bool indexUnchanged,
    195196
    struct IndexInfo *indexInfo);
    196197
    extern IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys);
    197198
    extern int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);

    doc/src/sgml/indexam.sgml

    Lines changed: 15 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -293,6 +293,7 @@ aminsert (Relation indexRelation,
    293293
    ItemPointer heap_tid,
    294294
    Relation heapRelation,
    295295
    IndexUniqueCheck checkUnique,
    296+
    bool indexUnchanged,
    296297
    IndexInfo *indexInfo);
    297298
    </programlisting>
    298299
    Insert a new tuple into an existing index. The <literal>values</literal> and
    @@ -308,6 +309,20 @@ aminsert (Relation indexRelation,
    308309
    look into the heap to verify tuple liveness).
    309310
    </para>
    310311

    312+
    <para>
    313+
    The <literal>indexUnchanged</literal> boolean value gives a hint
    314+
    about the nature of the tuple to be indexed. When it is true,
    315+
    the tuple is a duplicate of some existing tuple in the index. The
    316+
    new tuple is a logically unchanged successor MVCC tuple version. This
    317+
    happens when an <command>UPDATE</command> takes place that does not
    318+
    modify any columns covered by the index, but nevertheless requires a
    319+
    new version in the index. The index AM may use this hint to decide
    320+
    to apply bottom-up index deletion in parts of the index where many
    321+
    versions of the same logical row accumulate. Note that updating a
    322+
    non-key column does not affect the value of
    323+
    <literal>indexUnchanged</literal>.
    324+
    </para>
    325+
    311326
    <para>
    312327
    The function's Boolean result value is significant only when
    313328
    <literal>checkUnique</literal> is <literal>UNIQUE_CHECK_PARTIAL</literal>.

    src/backend/access/brin/brin.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -151,6 +151,7 @@ bool
    151151
    brininsert(Relation idxRel, Datum *values, bool *nulls,
    152152
    ItemPointer heaptid, Relation heapRel,
    153153
    IndexUniqueCheck checkUnique,
    154+
    bool indexUnchanged,
    154155
    IndexInfo *indexInfo)
    155156
    {
    156157
    BlockNumber pagesPerRange;

    src/backend/access/common/toast_internals.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -328,7 +328,7 @@ toast_save_datum(Relation rel, Datum value,
    328328
    toastrel,
    329329
    toastidxs[i]->rd_index->indisunique ?
    330330
    UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
    331-
    NULL);
    331+
    false, NULL);
    332332
    }
    333333

    334334
    /*

    src/backend/access/gin/gininsert.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -488,6 +488,7 @@ bool
    488488
    gininsert(Relation index, Datum *values, bool *isnull,
    489489
    ItemPointer ht_ctid, Relation heapRel,
    490490
    IndexUniqueCheck checkUnique,
    491+
    bool indexUnchanged,
    491492
    IndexInfo *indexInfo)
    492493
    {
    493494
    GinState *ginstate = (GinState *) indexInfo->ii_AmCache;

    src/backend/access/gist/gist.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -156,6 +156,7 @@ bool
    156156
    gistinsert(Relation r, Datum *values, bool *isnull,
    157157
    ItemPointer ht_ctid, Relation heapRel,
    158158
    IndexUniqueCheck checkUnique,
    159+
    bool indexUnchanged,
    159160
    IndexInfo *indexInfo)
    160161
    {
    161162
    GISTSTATE *giststate = (GISTSTATE *) indexInfo->ii_AmCache;

    src/backend/access/hash/hash.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -247,6 +247,7 @@ bool
    247247
    hashinsert(Relation rel, Datum *values, bool *isnull,
    248248
    ItemPointer ht_ctid, Relation heapRel,
    249249
    IndexUniqueCheck checkUnique,
    250+
    bool indexUnchanged,
    250251
    IndexInfo *indexInfo)
    251252
    {
    252253
    Datum index_values[1];

    src/backend/access/heap/heapam_handler.c

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1956,6 +1956,7 @@ heapam_index_validate_scan(Relation heapRelation,
    19561956
    heapRelation,
    19571957
    indexInfo->ii_Unique ?
    19581958
    UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
    1959+
    false,
    19591960
    indexInfo);
    19601961

    19611962
    state->tups_inserted += 1;

    src/backend/access/index/indexam.c

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -179,6 +179,7 @@ index_insert(Relation indexRelation,
    179179
    ItemPointer heap_t_ctid,
    180180
    Relation heapRelation,
    181181
    IndexUniqueCheck checkUnique,
    182+
    bool indexUnchanged,
    182183
    IndexInfo *indexInfo)
    183184
    {
    184185
    RELATION_CHECKS;
    @@ -191,7 +192,8 @@ index_insert(Relation indexRelation,
    191192

    192193
    return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
    193194
    heap_t_ctid, heapRelation,
    194-
    checkUnique, indexInfo);
    195+
    checkUnique, indexUnchanged,
    196+
    indexInfo);
    195197
    }
    196198

    197199
    /*

    0 commit comments

    Comments
     (0)
    0