Re: Pluggable Storage - Andres's take

Haribabu Kommi <kommi.haribabu@gmail.com>

From: Haribabu Kommi <kommi.haribabu@gmail.com>
To: Andres Freund <andres@anarazel.de>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Alvaro Herrera <alvherre@2ndquadrant.com>, Alexander Korotkov <a.korotkov@postgrespro.ru>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2018-12-15T08:16:25Z
Lists: pgsql-hackers
On Tue, Dec 11, 2018 at 12:47 PM Andres Freund <andres@anarazel.de> wrote:

> Hi,
>
> Thanks for these changes. I've merged a good chunk of them.
>

Thanks.


> On 2018-11-16 12:05:26 +1100, Haribabu Kommi wrote:
> > diff --git a/src/backend/access/heap/heapam_handler.c
> b/src/backend/access/heap/heapam_handler.c
> > index c3960dc91f..3254e30a45 100644
> > --- a/src/backend/access/heap/heapam_handler.c
> > +++ b/src/backend/access/heap/heapam_handler.c
> > @@ -1741,7 +1741,7 @@ heapam_scan_analyze_next_tuple(TableScanDesc
> sscan, TransactionId OldestXmin, do
> >  {
> >       HeapScanDesc scan = (HeapScanDesc) sscan;
> >       Page            targpage;
> > -     OffsetNumber targoffset = scan->rs_cindex;
> > +     OffsetNumber targoffset;
> >       OffsetNumber maxoffset;
> >       BufferHeapTupleTableSlot *hslot;
> >
> > @@ -1751,7 +1751,9 @@ heapam_scan_analyze_next_tuple(TableScanDesc
> sscan, TransactionId OldestXmin, do
> >       maxoffset = PageGetMaxOffsetNumber(targpage);
> >
> >       /* Inner loop over all tuples on the selected page */
> > -     for (targoffset = scan->rs_cindex; targoffset <= maxoffset;
> targoffset++)
> > +     for (targoffset = scan->rs_cindex ? scan->rs_cindex :
> FirstOffsetNumber;
> > +                     targoffset <= maxoffset;
> > +                     targoffset++)
> >       {
> >               ItemId          itemid;
> >               HeapTuple       targtuple = &hslot->base.tupdata;
>
> I thought it was better to fix the initialization for rs_cindex - any
> reason you didn't go for that?
>

No specific reason. Thanks for the correction.


>
> > diff --git a/src/backend/access/heap/heapam_visibility.c
> b/src/backend/access/heap/heapam_visibility.c
> > index 8233475aa0..7bad246f55 100644
> > --- a/src/backend/access/heap/heapam_visibility.c
> > +++ b/src/backend/access/heap/heapam_visibility.c
> > @@ -1838,8 +1838,10 @@ HeapTupleSatisfies(HeapTuple stup, Snapshot
> snapshot, Buffer buffer)
> >               case NON_VACUUMABLE_VISIBILTY:
> >                       return HeapTupleSatisfiesNonVacuumable(stup,
> snapshot, buffer);
> >                       break;
> > -             default:
> > +             case END_OF_VISIBILITY:
> >                       Assert(0);
> >                       break;
> >       }
> > +
> > +     return false; /* keep compiler quiet */
>
> I don't understand why END_OF_VISIBILITY is good idea?  I now removed
> END_OF_VISIBILITY, and the default case.
>

OK.


> > @@ -593,6 +594,10 @@ intorel_receive(TupleTableSlot *slot, DestReceiver
> *self)
> >       if (myState->rel->rd_rel->relhasoids)
> >               slot->tts_tupleOid = InvalidOid;
> >
> > +     /* Materialize the slot */
> > +     if (!TTS_IS_VIRTUAL(slot))
> > +             ExecMaterializeSlot(slot);
> > +
> >       table_insert(myState->rel,
> >                                slot,
> >                                myState->output_cid,
>
> What's the point of adding materialization here?
>

In earlier testing i observed as the slot that is received is a buffered
slot
and it points to the original tuple, but when it inserts it into the new
table,
the transaction id changes and it leads to invisible tuple, because of that
reason I added the materialize here.




> > @@ -570,6 +563,9 @@ ExecInterpExpr(ExprState *state, ExprContext
> *econtext, bool *isnull)
> >                               Assert(TTS_IS_HEAPTUPLE(scanslot) ||
> >                                          TTS_IS_BUFFERTUPLE(scanslot));
> >
> > +                             if (hslot->tuple == NULL)
> > +                                     ExecMaterializeSlot(scanslot);
> > +
> >                               d = heap_getsysattr(hslot->tuple, attnum,
> >
>  scanslot->tts_tupleDescriptor,
> >
>  op->resnull);
>
> Same?
>
>
> > diff --git a/src/backend/executor/execMain.c
> b/src/backend/executor/execMain.c
> > index e055c0a7c6..34ef86a5bd 100644
> > --- a/src/backend/executor/execMain.c
> > +++ b/src/backend/executor/execMain.c
> > @@ -2594,7 +2594,7 @@ EvalPlanQual(EState *estate, EPQState *epqstate,
> >        * datums that may be present in copyTuple).  As with the next
> step, this
> >        * is to guard against early re-use of the EPQ query.
> >        */
> > -     if (!TupIsNull(slot))
> > +     if (!TupIsNull(slot) && !TTS_IS_VIRTUAL(slot))
> >               ExecMaterializeSlot(slot);
>
>
> Same?
>

Earlier virtual tuple materialize was throwing error, because of that
reason I added
that check.

> index 56880e3d16..36ca07beb2 100644

> > --- a/src/backend/executor/nodeBitmapHeapscan.c
> > +++ b/src/backend/executor/nodeBitmapHeapscan.c
> > @@ -224,6 +224,18 @@ BitmapHeapNext(BitmapHeapScanState *node)
> >
> >                       BitmapAdjustPrefetchIterator(node, tbmres);
> >
> > +                     /*
> > +                      * Ignore any claimed entries past what we think
> is the end of the
> > +                      * relation.  (This is probably not necessary
> given that we got at
> > +                      * least AccessShareLock on the table before
> performing any of the
> > +                      * indexscans, but let's be safe.)
> > +                      */
> > +                     if (tbmres->blockno >= scan->rs_nblocks)
> > +                     {
> > +                             node->tbmres = tbmres = NULL;
> > +                             continue;
> > +                     }
> > +
>
> I moved this into the storage engine, there just was a minor bug
> preventing the already existing check from taking effect. I don't think
> we should expose this kind of thing to the outside of the storage
> engine.
>

OK.


>
> > diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
> > index 54382aba88..ea48e1d6e8 100644
> > --- a/src/backend/parser/gram.y
> > +++ b/src/backend/parser/gram.y
> > @@ -4037,7 +4037,6 @@ CreateStatsStmt:
> >   *
> >
>  *****************************************************************************/
> >
> > -// PBORKED: storage option
> >  CreateAsStmt:
> >               CREATE OptTemp TABLE create_as_target AS SelectStmt
> opt_with_data
> >                               {
> > @@ -4068,14 +4067,16 @@ CreateAsStmt:
> >               ;
> >
> >  create_as_target:
> > -                     qualified_name opt_column_list OptWith
> OnCommitOption OptTableSpace
> > +                     qualified_name opt_column_list
> table_access_method_clause
> > +                     OptWith OnCommitOption OptTableSpace
> >                               {
> >                                       $$ = makeNode(IntoClause);
> >                                       $$->rel = $1;
> >                                       $$->colNames = $2;
> > -                                     $$->options = $3;
> > -                                     $$->onCommit = $4;
> > -                                     $$->tableSpaceName = $5;
> > +                                     $$->accessMethod = $3;
> > +                                     $$->options = $4;
> > +                                     $$->onCommit = $5;
> > +                                     $$->tableSpaceName = $6;
> >                                       $$->viewQuery = NULL;
> >                                       $$->skipData = false;           /*
> might get changed later */
> >                               }
> > @@ -4125,14 +4126,15 @@ CreateMatViewStmt:
> >               ;
> >
> >  create_mv_target:
> > -                     qualified_name opt_column_list opt_reloptions
> OptTableSpace
> > +                     qualified_name opt_column_list
> table_access_method_clause opt_reloptions OptTableSpace
> >                               {
> >                                       $$ = makeNode(IntoClause);
> >                                       $$->rel = $1;
> >                                       $$->colNames = $2;
> > -                                     $$->options = $3;
> > +                                     $$->accessMethod = $3;
> > +                                     $$->options = $4;
> >                                       $$->onCommit = ONCOMMIT_NOOP;
> > -                                     $$->tableSpaceName = $4;
> > +                                     $$->tableSpaceName = $5;
> >                                       $$->viewQuery = NULL;           /*
> filled at analysis time */
> >                                       $$->skipData = false;           /*
> might get changed later */
> >                               }
>
> Cool. I wonder if we should also somehow support SELECT INTO w/ USING?
> You've apparently started to do so with?
>

I thought the same, but SELECT INTO is deprecated syntax, is it fine to add
the new syntax?

Regards,
Haribabu Kommi
Fujitsu Australia

Commits

  1. Add default_table_access_method to postgresql.conf.sample.

  2. tableam: Avoid relying on relation size to determine validity of tids.

  3. tableam: Don't assume that every AM uses md.c style storage.

  4. Allow pg_class xid & multixid horizons to not be set.

  5. Fix slot type issue for fuzzy distance index scan over out-of-core table AM.

  6. tableam: comment and formatting fixes.

  7. table: docs: fix typos and grammar.

  8. tableam: basic documentation.

  9. Only allow heap in a number of contrib modules.

  10. tableam: Add table_finish_bulk_insert().

  11. tableam: sample scan.

  12. tableam: bitmap table scan.

  13. tableam: Move heap specific logic from estimate_rel_size below tableam.

  14. tableam: VACUUM and ANALYZE support.

  15. tableam: relation creation, VACUUM FULL/CLUSTER, SET TABLESPACE.

  16. tableam: Support for an index build's initial table scan(s).

  17. tableam: Add table_get_latest_tid, to wrap heap_get_latest_tid.

  18. tableam: Add helper for indexes to check if a corresponding table tuples exist.

  19. tableam: Add and use table_fetch_row_version().

  20. tableam: Use in CREATE TABLE AS and CREATE MATERIALIZED VIEW.

  21. Ensure sufficient alignment for ParallelTableScanDescData in BTShared.

  22. Don't reuse slots between root and partition in ON CONFLICT ... UPDATE.

  23. Use a virtual rather than a heap slot in two places where that suffices.

  24. Store tuples for EvalPlanQual in slots, rather than as HeapTuples.

  25. Use slots in trigger infrastructure, except for the actual invocation.

  26. Store table oid and tuple's tid in tuple slots directly.

  27. Allow to use HeapTupleData embedded in [Buffer]HeapTupleTableSlot.

  28. Add ExecStorePinnedBufferHeapTuple.

  29. Add ArchiveOpts to pass options to ArchiveEntry

  30. Rename RelationData.rd_amroutine to rd_indam.

  31. Rephrase references to "time qualification".

  32. Move remaining code from tqual.[ch] to heapam.h / heapam_visibility.c.

  33. Move generic snapshot related code from tqual.h to snapmgr.h.

  34. Remove superfluous tqual.h includes.

  35. Don't duplicate parallel seqscan shmem sizing logic in nbtree.

  36. Move vacuumlazy.c into access/heap.

  37. Support parallel bitmap heap scans.