users/andresfreund/postgres.git
6 years agoregression differerences pluggable-zheap
Andres Freund [Wed, 5 Dec 2018 19:15:38 +0000 (11:15 -0800)]
regression differerences

6 years agozheap: Also increment tuples_updates for inplace updates.
Andres Freund [Tue, 11 Dec 2018 01:31:46 +0000 (17:31 -0800)]
zheap: Also increment tuples_updates for inplace updates.

That's more in line with HOT treatment, and avoids breaking newer
tests in stats.sql.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agozheap: Properly adjust for metapage in estimate_rel_size().
Andres Freund [Tue, 11 Dec 2018 00:45:59 +0000 (16:45 -0800)]
zheap: Properly adjust for metapage in estimate_rel_size().

Previously *pages wasn't adapted for the metapage, leading to
superflous plan changes. Also, avoid multiple checks.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoZHEAP on Pluggable V1.
Andres Freund [Thu, 6 Dec 2018 04:28:24 +0000 (20:28 -0800)]
ZHEAP on Pluggable V1.

Squashed commit of the following:

Pluggable Storage Integration +

commit 309145fb8ab59c993e26855cf0bf51d37902773f (zheap/master)
Author: mahendra <[email protected]>
Date:   2018-12-10 11:14:44 +0530

    Fix WAL logging for tpd map update during Rollback

    We were not WAL logging tpd map update in few cases, fix that.

    By Mahendra Singh Thalor and Amit Kapila

commit deda887629ca8bba859c0fa2a2e459e2c922c2bd
Author: mahendra <[email protected]>
Date:   2018-12-10 10:45:04 +0530

    BugFix : Correcting block number read in tpd_xlog_free_page

    In tpd_xlog_free_page function, we were trying to read from
    block 3 the data written in block 2. Hence correcting the
    block number.

    Patch by me, reviewed by Amit Kapila

commit 79738e7038e267c2c685cc5a5221153269317eeb
Author: Dilip Kumar <[email protected]>
Date:   2018-12-07 10:54:33 +0530

    Revert "For slots marked as invalid xact, skip fetching undo for some cases"

    This reverts commit 796299af2ca14800f8d69560d33f89ac293c1d15.

commit 796299af2ca14800f8d69560d33f89ac293c1d15
Author: Kuntal Ghosh <[email protected]>
Date:   2018-12-05 17:27:18 +0530

    For slots marked as invalid xact, skip fetching undo for some cases

    For a slot marked as invalid xact, if the corresponding xid preceds
    oldest xid having undo or the corresponding undo record is already
    discarded, we can consider the slot as frozen.

    Patch by me. Investigated by Amit Kapila, Dilip Kumar and me.

commit e26c804789fdcf24fc588a734b2196a81a51eef4
Author: Dilip Kumar <[email protected]>
Date:   2018-12-05 13:09:06 +0530

    Merged review comment fixes from pg hackers patch

    Dilip Kumar and Amit Kapila

commit 1fee88b7ec5d9aed7e1c0429292906e30f457f0d
Author: Mithun CY <[email protected]>
Date:   2018-12-04 02:11:08 -0800

    Fix CLANG's warnings.

    By Mithun C Y, review by Amit Kaplia.

commit 5b48c0c175dabfaf34099f0cc7feefe0b2367a0c
Author: Mithun CY <[email protected]>
Date:   2018-12-04 01:35:40 -0800

    Fix thinkos, caught by CLANG compilers.

    By Mithun C Y and Review by Dilip Kumar.

commit a1e1859d6910f49bb6eec8d04113dbba78deee3a
Author: Dilip Kumar <[email protected]>
Date:   2018-12-03 14:54:38 +0530

    Improve comments and code for previous commit.

commit 132fefaf953e632e07ddc53f8e0198e655cf0896
Author: Dilip Kumar <[email protected]>
Date:   2018-12-02 16:35:02 +0530

    In ZGetMultiLockMembers we fetch the undo record without a buffer lock
    so it's possible that a transaction in the slot can rollback and rewind
    the undo record pointer.  To prevent that we acquire the rewind lock
    before rewinding the undo record pointer and the same lock will be
    acquire by ZGetMultiLockMembers lock in shared mode.  Other places
    where we fetch the undo record we don't need this lock as we are doing
    that under the buffer lock.  So remember to acquire the rewind lock in
    shared mode wherever we are fetching the undo record of non commited
    transaction without buffer lock.

    Mahendra Thalor Reviewed and modified by Dilip Kumar

commit c200352aa6917b8c3d4a0e771a1f19d6f4eec6d9
Author: Rafia Sabih <[email protected]>
Date:   2018-11-30 14:06:07 +0530

    Bugfix in TPD recovery

    Patch by me, reviewed by Dilip Kumar

commit fd9152fa3ecfe1d0d8e6d06571d91f082d0f4ee9
Author: Dilip Kumar <[email protected]>
Date:   2018-11-29 07:17:27 -0800

    Remove multilocker flags for the cases for unwanted cases

    Currently, we are setting multilocker flag whenever lock is acquired
    on the tuple which has some performance penalty.  As part of this patch
    we have avoided setting multilocker flag for the case when a updater is
    taking a lock through eval plan qual mechanishm.

    Amit Kapila and Dilip Kumar

commit 79882e67fe4572081fc65a0dc28c20a773ef0533
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-29 18:26:12 +0530

    Fix issue in TPD allocate entry

    While allocating an entry for TPD, we traverse all the tuples in the
    page and check for tuples the correspond to the last slot and update the
    corresponding offset map in TPD with the actual transaction slot.

commit 8a6d050f121d2e588defee48d4a3ad9e43ac6136
Author: Rafia Sabih <[email protected]>
Date:   2018-11-29 16:57:02 +0530

    Bugfix in recovery of TPD free page

    Patch by me, reviewed by Amit Kapila

commit 47b86637a3d1ae71102c1a7a7704aaf7e95feffc
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-28 14:10:10 +0530

    Fix issues in TPD

    1. If previous and next block number is invalid for a TPD page, then
    that is the only TPD page in the same relation. We should handle the
    case correctly in TPDFreePage.
    2. While allocating a new TPD page, we ask a new page from FSM. It's
    possible that FSM returns a zheap page on which the current backend already
    holds a lock in exclusive mode. Hence, try for a conditional lock. If it
    can't get the lock immediately, extend the relation and allocate a new
    TPD block.
    3. In TPDPageLock, if a TPD buffer is already pruned, we don't take a
    lock on the same. Here, we should take the opportunity to clear the TPD
    location from the corresponding zheap buffer.
    4. In lazy vacuum, we don't vacuum a TPD page. Instead, we try to prune
    the page. But, if it's already pruned, we should skip it.
    5. There are several places in the code where we lock a TPD page before
    entering critical section. For non-inplace updates on different buffers,
    it is possible that both old and new zheap buffer corresponding to the
    same TPD buffer. Hence, we should be careful that we don't try to lock
    the TPD page two times. Else, we'll be waiting on self.

    Patch by me. Reviewed by Amit Kapila.

commit 8c31fef78166e7df53470f43c6bd1d53d18341e7
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-28 14:31:09 +0530

    Skip using tuple if corresponding item is deleted

    If item id is marked as deleted, we can't check the tuple. Else, it'll
    lead to segmentation fault.

    Patch by me. Reviewed by Amit Kapila.

commit c66b03f50c074236882fb0370a87dad8df4a597c
Author: Amit Kapila <[email protected]>
Date:   2018-11-27 09:10:44 +0530

    Fix windows build.

commit 35e2e1b5907d85ee02d74b728a23ab7865405e64
Author: Rafia Sabih <[email protected]>
Date:   2018-11-26 14:34:16 +0530

    Forget Local buffers

    For zheap, forget the local buffers whenever used.

    Patch by me, reviewed by Amit Kapila

commit 3a1f846c48cea443478478622c12b6df28fe15a6
Author: Amit Kapila <[email protected]>
Date:   2018-11-25 10:12:13 +0530

    Fetch CID from undo only when required.

    If the current command doesn't need to modify any tuple and the snapshot
    used is not of any previous command, then it can see all the modifications
    made by current transactions till now.  So, we don't even attempt to fetch
    CID from undo in such cases.

    Patch by Amit Kapila, reviewed and verified by Dilip Kumar

commit e48be86489daf6bc78071d7fe7fe5e1eb5b2a705
Author: Mithun CY <[email protected]>
Date:   2018-11-23 07:58:01 -0800

    Bug Fix, correct an invalid Assert.

    slot_xid is uninitialized and Assert condition is invalid.

    Patch By Mahendra Thalor Review by Amit Kapila.

commit 12bf9650d247c64d96868ada87fcda07a2ff46b5
Author: Dilip Kumar <[email protected]>
Date:   2018-11-23 03:31:06 -0800

    Merge review comments fixed on community patch

    Dilip Kumar

commit d06ab949c8774f6989ffefc65a100b7208516a06
Author: Amit Kapila <[email protected]>
Date:   2018-11-22 15:53:22 +0530

    Fix the modification of TPD map during rollback.

    If the previous transaction slot points to a TPD slot then we need to
    update the slot in the offset map of the TPD entry.  This is the case where
    during DO operation the previous updater belongs to a non-TPD slot whereas
    now the same slot has become a TPD slot.  In such cases, we need to update
    offset-map.

    Patch Mahendra Singh, reviewed by Amit Kapila

commit 9f1fd917e954b6b430b2575e84bd669166ee8cdf
Author: Mithun CY <[email protected]>
Date:   2018-11-21 22:09:16 -0800

    Make the expected file to be generated by a source file.

    Patch By Mahendra Thalor Review by Mithun C Y.

commit 3e255b05d87a65183adc8cac204529937c978e13
Author: Beena Emerson <[email protected]>
Date:   2018-11-20 11:47:49 +0530

    Fix crash in pg_stat_* functions

    commit b04aeb0a05 added Assets to ensure that we hold some relevant
    lock during relation_open. This commit corrects the locks used in
    relation_open for the zheap pg_stat functions to avoid Assertion
    failure.

    Patch by me, reviewed by Dilip Kumar

commit 0e2f8eb102744121d7203213c87c124f75578665
Author: Rafia Sabih <[email protected]>
Date:   2018-11-19 13:07:25 +0530

    Reset undo buffers in case of abort

    In case of errors, when the transaction aborts, the undo buffers and
    the buffer index are now reset.

    Patch by me, reviewed by Dilip Kumar and Amit Kapila

commit 88f9e6e42d0c769158b283b378c4c0d19af91139
Author: Dilip Kumar <[email protected]>
Date:   2018-11-18 04:43:36 -0800

    Fix trailing space in previous commit

commit b925c7ab4df48f42951b9690216d9c9e78f25ba3
Author: Dilip Kumar <[email protected]>
Date:   2018-11-18 04:18:04 -0800

    Only try to lock the TPD page if the zheap page has the TPD slots in it.

    Path by Mahendra Thalor reviewed by Dilip Kumar

commit 257e8e7990e9d85a373a41d0dce17f7f56ed5c61
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-15 17:46:14 +0530

    Add expected file for multiple-row-versions isolation test

    In this test, we get a serialization failure due to in-place updates in
    zheap. But, this is an expected behavior.

    Discussions: https://postgr.es/m/CAGz5QCJzreUqJqHeXrbEs6xb0zCNKBHhOj6D9Tjd3btJTzydxg@mail.gmail.com

commit 1b44ba6c5154fa6eed3e56bfb97285a78aa58003
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-02 12:00:41 +0530

    Implement ALTER TABLE SET TABLESPACE for zheap

    To alter the tablespace for a zheap table, we copy the pages one-by-one
    to the new tablespace. Following is the algorithm to perform the same:

    For each zheap page,
        a. If it's a meta page, copy it as it is.
        b. If it's a TPD page, copy it as it is.
        c. If it's a zheap data page, apply pending aborts, copy the page
        and corresponding TPD page if we've rolled back any transaction from
        the TPD.

    Patch by me. Reviewed by Amit Kapila.

commit 2b5f6aa07e8d705f238bf8b1a308e6f761e05a98
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-14 11:35:00 +0530

    Create a wrapper function for fetching transaction slots for a page

    We've created a  wrapper function GetTransactionsSlotsForPage for
    fetching all transaction information for a zheap page and its
    corresponding TPD page.

    Patch by me. Reviewed by Amit Kapila.

commit 0931d56b34aaf5c9c2b665da751aec051aa7d90a
Author: Dilip Kumar <[email protected]>
Date:   2018-11-15 01:50:11 -0800

    Fix assert

    It must be in critical section only if it's not in recovery

commit 96ede480d229e874e204895856bcded0fb33f68b
Author: Dilip Kumar <[email protected]>
Date:   2018-11-15 01:41:43 -0800

    Remove relfilenode and tablespace id from the undo record and store reloid

    There was no reason why we stored relfilenode and tablespaceid in undo record,
    instead we could just store reloid.  Earlier, we might have kept it thinking
    that we will perform rollback without database connection but that's not the
    case now.  This will save the space as well as it will be useful when we need
    to transfer the undo records across the relfilenodes e.g ALTER TABLE SET TABLESPACE.

    Dilip Kumar reviewed by Amit Kapila

commit 842e9e36821e2ad1ce2f557631a2af8bb96f2d23
Author: Dilip Kumar <[email protected]>
Date:   2018-11-15 01:28:07 -0800

    Fix cosmetic review comments in undoinsert

    Dilip Kumar review by Amit Kapila

commit 01f981fdeddad6eff83f1a12c8751a373df56a1c
Author: Rafia Sabih <[email protected]>
Date:   2018-11-14 20:48:14 +0530

    Discard undo logs in single-user mode

    For zheap, discard the undo logs at commit time when in single user mode.

    Patch by me, reviewed by Dilip Kumar and Amit Kapila

commit 1bcef1bf35738b060e5c412428aac502245abe2b
Author: Rafia Sabih <[email protected]>
Date:   2018-11-14 17:03:47 +0530

    Bugfix for visibility map buffer

    In case the page is newly extended, the vmbuffer will not be valid.
    Hence avoid checking the status for it in zheap insert and update.

    Reported by Neha, patch by me, reviewed by Amit Kapila

commit 1b1cace0bb7195025ea5bd19848953f10fe5cd30
Author: Dilip Kumar <[email protected]>
Date:   2018-11-13 05:14:26 -0800

    Removed invalid assert in extend_undo_log

    It is possible that while we try to extend the undo log it's already
    extended by discard (recycle old undo log) so this situation is
    possible.

    Patch by Mahindra reviewed by Dilip Kumar and Amit Kapila

commit aa25f816c637f9123f67a4c7e1fa14f64c15d72c
Author: Dilip Kumar <[email protected]>
Date:   2018-11-11 19:35:32 -0800

    Fix compiler error

commit 48d8236385a8894f17e642bb182e6be01b5fcfb7
Author: Amit Kapila <[email protected]>
Date:   2018-11-12 08:33:05 +0530

    Fix warning.

commit 0495698cb6e1e6d29ddb146332ddc61299c99aeb
Author: Amit Kapila <[email protected]>
Date:   2018-11-10 16:15:45 +0530

    Prune entire TPD page at one-shot if possible.

    We have used tpd_latest_xid_epoch stored in page to prune the entire TPD page.
    Basically, if tpd_latest_xid_epoch precedes oldestXidhaving undo, then we
    can assume all the entries in the page can be pruned.

    Apart from that, I have changed the logic so that page is freed during
    pruning if all the entries are removed from the page. this will ensure that
    pages will be reclaimed whenever they are empty, not only during vacuum.

    In the passing, I have fixed another related issue which is after we get
    the new page from fsm, we need to ensure that it is a tpd page before
    using it.

    Patch by Amit Kapila, reviewed and verified by Dilip Kumar

commit 2c0af615df41867e26fd80900f0e38f032750752
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-09 15:22:26 +0530

    While computing infomask for updating a tuple, don't copy update flags

    When we compute infomask during updating a tuple, we don't have to copy
    update flags. We compute it later in zheap_update.

commit 48f1a2d2973ae25b33adfeac4129769fadfea134
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-09 13:27:35 +0530

    Small bugfix in UndoDiscardOneLog

    We can't compare log->meta.insert directly with the undo_ptr. We need to
    create a undo pointer first.

commit 0b374e91021b49795d2ec05243e3c9c24363d7d5
Author: Mithun CY <[email protected]>
Date:   2018-11-08 22:09:05 -0800

    Bugfix in TPDPageGetTransactionSlots to handle truncated pages.

    Block number starts from zero, when compared with the total number of
    blocks in relation, we need to adjust the block number accordingly.

    Fix by Mithun C Y, review by Amit Kapila.

commit 38e5a0cee902dae0c18961d91699ba254ea0fcb3
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-08 15:16:02 +0530

    In zheap_update, clear the in-place update flag for non-inplace updates

    Reported by Gunjan Kumar.

commit 05c36ee9f886c9feb274360d9b523ea0d9e4dac7
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-08 11:51:20 +0530

    Fix a testcase in expected file for trigger.sql regression test

commit f52a281728a425df027d4a201c09730c5a8f0c42
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-08 11:14:55 +0530

    While locking the tuple, set cid as FirstCommandId

     While locking the tuple, we set the command id as FirstCommandId since
     it doesn't modify the tuple, just updates the infomask.

commit 2595ad4d099abf21d59017f8cebfa416fe454d2d
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-07 15:07:49 +0530

    Fix a bug for projecting table oid

    There are certain places in the code where we form a heap tuple using
    ExecCopyTuple and store it in slot along with the zheap tuple. In that
    case, we don't copy the tableOid to heap tuple. Hence, for fetching
    tableOid, we should prefer a zheap tuple instead of a heap tuple.

commit a3d175ba1b4a089b74a9f68be4b035695d57d698
Author: Mithun CY <[email protected]>
Date:   2018-11-07 21:11:32 -0800

    Post push compilation error fix for 903ce21849

    By Mithun C Y

commit fdd2e03c972269b4a0fe95b13433ce55ac1f8bd7
Author: Dilip Kumar <[email protected]>
Date:   2018-11-06 02:11:35 -0800

    Bugfix in recovery of invalid_xact and freeze

    TPD page slot information was not set if BLK_NEED_REDO is false for
    the heap page.  Also, during recovery relation descriptor is used
    to take the pruning decision which is wrong because during recovery
    it should be done automatically by a seperate WAL.

    Dilip Kumar and Amit Kapila

commit 0fc2cb13d810d7979b51c2b6ea44fa4f9119f7a4
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-05 16:31:38 +0530

    Fix shared memory size for rollback hash table

    While creating shared memory segment for rollback hash table, we should
    set the size of the segment correctly.

    Patch by me. Investigated by Dilip Kumar and me.

commit 62c4099af465e7f739aa0f391724eb4efb02ba08
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-05 13:52:25 +0530

    Fix warnings in tpd.c

commit 9e203e16ffd03867bda789c33f0bdeece04df7a0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-04 21:57:23 +0530

    Assign OID correctly while converting tuple

commit b8bcb9891a1fc24e1c02933ee84eba1a017af692
Author: Rafia Sabih <[email protected]>
Date:   2018-11-05 13:46:47 +0530

    Handling rollbacks in single user mode for zheap

    Never push rollback requests to worker when in single user mode.

    Patch by me, reviewed by Amit Kapila

commit a95fc28e9073d6e7815f3772e1255efe2967c847
Author: Amit Kapila <[email protected]>
Date:   2018-11-05 11:03:54 +0530

    Add empty TPD pages to FSM.

    The empty TPD pages are added to FSM by vacuum which prune such pages as
    well. The empty pages from FSM can be used either by zheap or TPD when
    required. We need to ensure that when we access TPD pages, such a page can
    be pruned or truncated away by vacuum. After pruning the TPD page, it can
    be freed by removing it from the chain of TPD pages.

    As of now, only vacumm can add TPD pages into FSM, but we might want to
    improve it someday that backends can also do the same.

    Patch by me with help from Dilip Kumar who also tested and verified the
    patch.

commit 49a60ee0c3bbb844621bc8167f8e04ca0c032509
Author: Rafia Sabih <[email protected]>
Date:   2018-11-05 10:14:13 +0530

    Adding new output files for regress-suite

    Some system attributes are not supported for zheap tuples, hence,
    for combocid and transactions new .out files are added for zheap.

    Patch by me, reviewed by Kuntal Ghosh

commit 3d8d5f45b4b928fbcc9d1ff29c3f8fc822009a4f
Author: Amit Kapila <[email protected]>
Date:   2018-11-05 08:09:29 +0530

    Fix valgrind error.

    Reported by Tomas Vondra, patch by me, verified by Mithun

commit 8e3a8679dfb0248699155eec8f07098df7d7f3ad
Author: Rafia Sabih <[email protected]>
Date:   2018-11-02 16:44:26 +0530

    Change case in one error message

    Pointed out by Kuntal Ghosh, patch by me.

commit 1bcb9489f3077ef03616ff19ff46b0e3a2980aa6
Author: Amit Kapila <[email protected]>
Date:   2018-11-02 16:36:32 +0530

    Fix the errors reported by valgrind.

    In the passing, I have noticed the xidepoch was not assigned properly,
    so fixed that as well.

    Reported by Tomas Vondra, Patch by me, verified by Mithun C Y.

commit f69fa9edc361c374cb7ce8780b5e63b6412c9d08
Author: Rafia Sabih <[email protected]>
Date:   2018-11-02 16:26:04 +0530

    Bugfix in heap_truncate for zheap relations

    Initialize meta page for zheap relations only when the complete
    relation is truncated.

    Patch by Amit Kapila, tested by me

commit 704e3b777c385e319ded0b0fa317409fc41dc7a1
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-02 15:40:19 +0530

    Add expected file for rowsecurity regression test

    In rowsecurity test, there is a test case that uses table sample scan
    with bernoulli distribution. The output of tablesample scan partially
    depends on the block number of the relpage from which the tuples are
    fetched. For zheap, blocknumber 0 is meta page. Hence, tuples are stored
    from block 1. Hence, the output of table sample scan can be different.

commit 153ea5c17e65144382c8c68a22d46527f0f7de2d
Author: Mithun CY <[email protected]>
Date:   2018-11-01 08:09:35 -0700

    Release Undo buffer locks after wal replay of XLOG_UNDO_APPLY_PROGRESS

    By Mithun C Y And Mahendra Thalor.

commit 5fed5fe9eaa00c1196dc47d18b91c9e2bb336aab
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-01 15:33:47 +0530

    Add expected file for stats.sql regression test

    In zheap, we increase pgstat_info->trans->tuples_updated only for
    non-inplace updates, otherwise vacuum will be triggered for in-place
    updates as well. But for heap, we always increase tuples_updated since
    heap always creates a new version of the tuple during updates. Hence, we
    need to fix the output in expected file for zheap.

commit 987049f5b11351ee6b985ddc76e978e2d77fa403
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-01 14:52:39 +0530

    Add expected file for strings.sql regression test

    There is a test case in strings.sql that counts the number of pages for
    toast table. In zheap, toast tables are also created in zheap format
    which always includes a zheap meta page. We should count that in the
    expected file.

commit 3ef3b9b67ae27d9568ce9380c9f646bd894b8bd0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-11-01 12:00:50 +0530

    Add storage_engine in reloptions regression test

commit 94777e98221cf49e42f9a7bddf5947072424e368
Author: Mithun CY <[email protected]>
Date:   2018-10-31 22:23:28 -0700

    Add alternative expected files for zheap regression.

    Order of zheap tuples in pages will be diffrent form heap. Hence
    zheap specific expected files are needed.

    By Mithun C Y

commit 7570b3bed887531f31dcc25ea602233c8d56ee6d
Author: Dilip Kumar <[email protected]>
Date:   2018-10-31 22:06:56 -0700

    Fix warning of hash seq scan leak and also removed unwanted assert
    from the zheap mask.

    Dilip Kumar Reviewed by Amit Kapila and Kuntal Ghosh

commit 14fdcc4b9eda81577d81ba3c7b040f86850e78eb
Author: Rafia Sabih <[email protected]>
Date:   2018-11-01 09:54:26 +0530

    System attributes for Zheap

    For zheap tuples, Xmin is given as the xid which last modified the
    tuple. The other system attributes Xmax, Cmin, and Cmax are not
    supported for zheap, for now.

    Patch by me, reviewed by Amit Kapila

commit 794b8f4df739d3565663f51ca7117dbe855980c2
Author: Amit Kapila <[email protected]>
Date:   2018-11-01 09:11:31 +0530

    Update README.md.

commit 6ce786252d5ddaac6fdb07506f6cde3d66e093cd
Author: Amit Kapila <[email protected]>
Date:   2018-10-31 19:11:40 +0530

    Updated readme to match latest status.

commit 8c780e8474aed4c38ae482d94683cba1be0e9a29
Author: Dilip Kumar <[email protected]>
Date:   2018-10-31 06:34:45 -0700

    Fix assert in RollbackFromHT

    Ideally number of entries should be <= ROLLBACK_HT_SIZE

commit 3017c86cdaba643d61f32eab351b63acfa381720
Author: Dilip Kumar <[email protected]>
Date:   2018-10-31 06:18:52 -0700

    Merge additional test in zheap expected file

commit 8bf58ba522c27429d0da0260a35abc5d519feece
Author: Dilip Kumar <[email protected]>
Date:   2018-10-31 05:58:00 -0700

    Fix defect in undo worker connection

    Take a database object lock before connecting to the database so that
    the database does not get dropped concurrently.

    Dilip Kumar Reviewed by Amit Kapila

commit 007af507d94b992f0a37caa10015d134a0782b07
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-31 14:35:02 +0530

    Skip aborting rewinded undo records

    Before discarding undo records, the undo discard worker checks whether it
    has to issue a rollback request for the corresponding aborted transaction.
    It's possible that the transaction got aborted by some other backend at
    the same time and the undo records got rewinded. Hence, the undo worker
    should recheck to detect whether the undo records got rewinded. In that
    case, there is no need to issue a rollback request.

    Reviewed by Amit Kapila

commit 28bae62a6745f223e99e1af27328ed6218752bb4
Author: Amit Kapila <[email protected]>
Date:   2018-10-31 16:01:02 +0530

    Eliminate alignment padding whereever possible.

    We omit all alignment padding for pass-by-value types. Even in the current
    heap, we never point directly to such values, so the alignment padding
    doesn't help much; it lets us fetch the value using a single instruction,
    but that is all.  Pass-by-reference types will work as they do in the heap.
    Many pass-by-reference data types will be varlena data types (typlen = -1)
    with short varlena headers so no alignment padding will be introduced in that
    case anyway, but if we have varlenas with 4-byte headers or if we have
    fixed-length pass-by-reference types (e.g. interval, box) then we'll still end
    up with padding.  We can't directly access unaligned values; instead, we need to
    use memcpy.  We believe that the space savings will more than pay for the
    additional CPU costs.

    We don't need alignment padding between the tuple header and the tuple
    data as we always make a copy of the tuple to support in-place updates.
    Likewise, we ideally don't need any alignment padding between tuples.
    However, there are places in zheap code where we access tuple header
    directly from page (ex. zheap_delete, zheap_update, etc.) for which we
    them to be aligned at two-byte boundary).

    Amit Kapila and Kuntal Ghosh

commit 580dcc4fc69e57dac919d1ac1068f876505f6c17
Author: Rafia Sabih <[email protected]>
Date:   2018-10-31 14:59:31 +0530

    Fix for a compiler warning

    Reported by Neha Sharma

commit 7f2397b0b87a9941a34998ffc63990eab32f09f1
Author: Mithun CY <[email protected]>
Date:   2018-10-31 00:43:06 -0700

    Wal log page extension if it was not done previously.

    Patch by Amit Kapila, Review by Mithun C Y.

commit 9ffbe108474a898e76302bb834d040f288b78e67
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-30 13:17:34 +0530

    Fix bug in registering TPD buffers for WAL

    While creating a WAL record, if a concurrent checkpoint occurs, WAL
    insertion may fail. In that case, we need to prepare the WAL record
    again. At the same time, we should clear the registered TPD buffer
    array. Else, it'll not be registered in WAL in next try.

    Patch by me. Investigated by Amit Kapila, Dilip Kumar and me. Reviewed
    by Amit Kapila and Dilip Kumar.

commit b30e67a310db0bd75a44094c8acd9e87c1f5c51e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-31 11:51:01 +0530

    Fix eval-plan-qual isolation test

    After rebasing the zheap branch with latest PG HEAD, there are some
    additional testcases in eval-plan-qual isolation test. Add those changes
    in regression out file targeted for zheap.

commit 799ca622b624f0b13916ea8ce4ea1afad51d5f1c
Author: Amit Kapila <[email protected]>
Date:   2018-10-31 11:50:49 +0530

    Return error on trying to update a row moved to another partition.

    The approach used here is to set the ZHEAP_MOVED (ZHEAP_DELETED |
    ZHEAP_UPDATED) flag when the tuple is moved to different partition.
    All the cases that are handled in heap needs to be handled for zheap as
    well.

    Amit Kapila, based on earlier patch by Amit Khandekar which has used a
    different approach.

commit d9918b8ec386619a3cd2ac28d8f2ea8698aeec99
Author: Dilip Kumar <[email protected]>
Date:   2018-10-31 11:22:29 +0530

    Defect fix post rebase

commit 10492266c5789bbec1fdbfd13220dcacbea633c6
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-30 10:16:43 +0530

    TPD fix by Dilip RM43761

commit 7524cd8cf9f7a20bfb44aefe32f0085bec1ce385
Author: Dilip Kumar <[email protected]>
Date:   2018-10-30 18:36:32 +0530

    During recovery restore dbid from WAL

    Patch by Mahendra Thalor Reviewed by Dilip Kumar and Kuntal Ghosh

commit e73d2bf79db041177d35c9f3333e126318460f8c
Author: Dilip Kumar <[email protected]>
Date:   2018-10-30 17:57:00 +0530

    Bug fix after rebase

    Dilip Kumar and Kuntal Ghosh

commit 5340d395c5d63e56f0398fee816393a613e385fb
Author: Mithun CY <[email protected]>
Date:   2018-10-25 05:32:50 -0700

    Avoid page compaction if the tuple is marked updated, deleted or
    inplace updated by an open transaction.

    By Mithun C Y

commit ed9356efb9f5ad9622beef61ce75cfb9b8c5ea39
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-24 10:35:11 +0530

    Fix an isolation test case for zheap

    In zheap, when a transaction rolls back, it needs to perforfm undo
    actions on the modfied relation. For that, it needs a lock on that
    relation. If any concurrent transaction holds an exclusive lock on the
    relation, the rollback operation will wait untill the lock is available.

commit 5711aac11e6443d16e6b0aeb2219c9ce0ac6f3b7
Author: Amit Kapila <[email protected]>
Date:   2018-10-23 21:24:07 +0530

    Fix compiler warning.

    Reported by Thomas Munro.

commit 407f6350335597bb2029109df3c0a4d090410a4f
Author: Amit Kapila <[email protected]>
Date:   2018-10-23 14:12:58 +0530

    Move functions that can allocate memory or allow locking outside critical
    section.

    At few places in the code, TPDPageGetTransactionSlotInfo was being called
    from critical section which leads to assertion failure.  Lock the TPD page
    whereever required before entring critical section.

commit 390416aa17bc215e541c3cf83acd5e336bb6e350
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-23 12:13:23 +0530

    Bugfix in tpdxlog.c

commit a68d7ef43e07849bd75bd5e39634e3ab29efbe0b
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-23 12:11:07 +0530

    Fix a variable initialization

commit 09a0518389ccce88b381b3f44b4d88769feb7634
Author: Mithun CY <[email protected]>
Date:   2018-10-22 18:10:00 -0700

    Fix orderering issues in regression tests.

    With zheap we have inplace updates so order of tuples in zheap page
    will be different from heap.  Adding order by clause to test to get
    consistent results for both heap and zheap.

    By Mithun C Y

commit b5f1649f55aa366f239fe37dc2e06c9b2cecdf17
Author: Rafia Sabih <[email protected]>
Date:   2018-10-18 16:37:00 +0530

    Bug fix in zheap_lock_tuple

    Added a code-path in zheap_lock_tuple to check for the latest copy
    of the tuple in case it is modified by some aborted transaction.

    Issue reported by Neha Sharma, patch by me, and reviewed by Amit Kapila

commit f9a00ee12997bc0ac823ac4419b8aa3f7024aee6
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-18 11:06:04 +0530

    Add expected file for eval-plan-qual isolation test

    Include metapages in ctid for zheap tuples. Also, Updated a test case
    related to self join. Basically, when performing a self join if it needs
    to pass through EvalPlanQualFetch path, it's possible that both sides of
    the join see the same value due to in-place update. This behaviour is
    different from heap, but similar to other undo-based storage.

commit 804d6edc03cc8aa9b5bb0428bccda27a48c1c8fb
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-18 10:09:54 +0530

    Include meta page in isolation test results

    In vacuum-reltuples isolation test, include zheap metapage in relpages.

commit c0f90396dd27d28c27d0b59e682680289fcba669
Author: Amit Kapila <[email protected]>
Date:   2018-10-17 18:28:05 +0530

    Bump the number of initial TPD entries.

    By mistake, commit 1400d8f84b has changed the number, it was added just for
    testing purpose, but it should have been removed before commit.

commit 14d67f52665110d64666e1addc255df15015dc6b
Author: Amit Kapila <[email protected]>
Date:   2018-10-17 16:49:10 +0530

    Support inplace update of TPD entries.

    Whenever TPD entry needs to be extended, we call Call TPDPagePrune to
    ensure that it will create a space adjacent to current offset for the new
    (bigger) TPD entry, if possible. We use compactify_ztuples to ensure that
    space adjacent to existing entry can be created. For inplace update of TPD
    entry, we just replace the old entry with new entry at the same location
    similar to inplace updates of tuples. We also write WAL record this
    operation.

    Amit Kapila and Kuntal Ghosh, reviewed and verified by Dilip Kumar

commit 83c27f9fae800fb73eff68f1987136adaf7965ab
Author: Rafia Sabih <[email protected]>
Date:   2018-10-17 06:26:24 +0530

    Bugfixes in zheap update, delete, and lock

    - Modify the infomask only after writing the corresponding undo.
    - Always be in inside critical section when modifying tuple.
    - Check if the current member is the only locker with multilockers,
      then no need to lock tuple again.

    Issue reported by Neha Sharma. Patch by me, reviewed by Amit Kapila
    and Kuntal Ghosh

commit 69b6b791ffaa0d04cc10bc0603c8bbc39f58dfa8
Author: Amit Khandekar <[email protected]>
Date:   2018-10-15 14:31:43 +0530

    Improve test coverage of update.sql.

    Commit 521461cfd91b9b44f0ecc392b3470922e78246b0 had removed
    some redundant RETURNING clauses in some statements, in order to
    make the output consistent. This commit reverts back those changes
    and instead uses WITH clause over the update statements, so that
    we could use ORDER BY for consistent ordering . This helps retain
    the RETURNING clauses, which also makes sure we don't reduce the test
    coverage that we may have got for the update-partition-key feature.

    Patch by me; idea suggested and changes reviewed by Mithun Cy.

commit 0a261c3bae670e9b3748a9eeb82706a96a2b4f32
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-15 11:27:51 +0530

    Fix payload length in standby

commit dac8323bfc43f7c0dec9c02dd53ca761b3c098b8
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-15 10:15:32 +0530

    After fetching xid recheck for frozen xid

commit abdd14af03e32e9abfe7b7ed0c6bb88a0a6184af
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-15 09:53:14 +0530

    Clear TPD entry only in exclusive lock

    When we clear TPD entry from a TPD page, we should have a exclusive lock
    on the TPD buffer. Hence, perform a check for the same before clearing
    the entry.

commit 52b84f9fb21468080c8ea252336a1994f915ca8b
Author: Dilip Kumar <[email protected]>
Date:   2018-10-15 10:55:07 +0530

    Bug fix in recovery

    Multiple bug fix in recovery of the TPD and undo action WAL

    Dilip Kumar reviewed by Amit Kapila

commit 6ebf7d2e1f12fcd92bb5c7ebe11e83eda3824c32
Author: Dilip Kumar <[email protected]>
Date:   2018-10-15 10:51:17 +0530

    Bug fix in tpd

    If the tpd entry is pruned then we can directly use the last slot
    for the transaction and no need to try for extending the tpd entry

    Amit Kapila reviewed by Dilip Kumar

commit aa09e789b0b40f9593f97135c6c9af4c74464023
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-10 13:47:25 +0530

    Skip calling zheap_fetchinsertxid for non-serializable xacts

    For non-serializable xacts, we can skip calling zheap_fetchinsertxid to
    fetch the targetxmin that is passed to PredicateLockTid. A call to
    zheap_fetchinsertxid is costly since it has to fetch undorecords.

commit 2b2963b37cb1316de21ed65e8c859b76467616ca
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-10 11:07:35 +0530

    Fix compiler warnings

commit 0a82317f0378b35122df6bef1d473826f149c121
Author: Dilip Kumar <[email protected]>
Date:   2018-10-08 11:58:38 +0530

    Bugfix in undoworker commit.

    Shared memory size was not calculated for undo launcher
    and removing one unwanted hunk.

commit c77321a0364149c3831844f02082579a070d47f0
Author: Mithun CY <[email protected]>
Date:   2018-10-07 14:47:06 -0700

    Fix regression tests and output for row order changes.

    With the introduction of inplace updates in zheap, order of rows
    within a page has changed. This fix changes the queries whose output
    depend on stored row order. Those queries are rewritten to have an
    order by clause to get consistent result for both heap and zheap.

    By Mithun C Y

commit e5a37a151fc52b0bc10b2dd6af13af3b71136360
Author: Amit Khandekar <[email protected]>
Date:   2018-10-05 22:20:44 +0530

    Fix a concurrency issue with UPDATEs and triggers.

    In GetZTupleForTrigger(), after it calls zheap_lock_tuple(), a check
    for hufd.in_place_updated_or_locked was missing. So if there was a
    concurrent in-place update, it used to conclude that the tuple was
    deleted. Add the missing check.

    Patch by me, reviewed by Dilip Kumar.

commit f5c0d3dd3cbab42628d311fbb50614f1bce93ec1
Author: Amit Khandekar <[email protected]>
Date:   2018-10-05 22:01:36 +0530

    Regression test changes for update.sql

    update.sql had to undergo some modifications because the RETURNING
    clause was returning in different order. Also some UPDATE statements
    that updated multiple rows had to be modified such that they update
    only single row, because the erroring row was different in case of
    zheap. There were two erroring rows, and out of them whichever is the
    first in the update scan result got displayed in the error message.
    This test also has some more ORDER BY clauses.

commit bbd7a64c3495b77bf77406511afa4f1183a7fcc4
Author: Amit Khandekar <[email protected]>
Date:   2018-10-05 21:37:18 +0530

    Fix tuple handling with trigger functions and transition capture.

    In ExecUpdate(), for zheap tables, ExecARUpdateTriggers() was called
    only if resultRelInfo->ri_TrigDesc is true, which is incorrect. This
    function also needs to be called for transition capture even when
    trigdesc is false. Due to this, transition table rows were not getting
    generated.

    Furthermore, in ExecInsert(), for zheap tables, ExecARUpdateTriggers()
    was getting called using tuple when it should be called using ztuple.

    Fixed both these by making the newtuple parameter of
    ExecARUpdateTriggers() a void * type and renaming it to
    newtuple_abstract, so that we can pass tuple or ztuple according to
    the table storage. And then in ExecARUpdateTriggers(), do the
    conversion from zheap to heap if it's a zheap tuple.

    On similar lines, do changes for ExecARInsertTriggers(), where
    trigtuple is made trigtuple_abstract. Now that this function accepts
    an abstract tuple, fix another pending issue in copy.c : in CopyFrom()
    and CopyFromInsertBatch(), pass either zheap or heap tuples to
    ExecARInsertTriggers().

    Reviewed by Dilip Kumar and Amit Kapila.

commit 51da00138eeceda6ea57e59760e49b9d60518274
Author: Rafia Sabih <[email protected]>
Date:   2018-10-05 17:04:22 +0530

    This commit completes the work of adding the new lock type for
    sub-transactions in zheap that was started in commit
    13b72c94cc77f6471e46f6e9da29423994753240. This commit handles the cases
    of waiting on sub-transactions when using dirty snapshot, inserting
    index tuples in btree, and while checking for constraints violation.

    Patch by me, reviewed by Amit Kapila

commit 0cb8b6c800d4437c0e413c8bd2473181d843f1e3
Author: Mithun CY <[email protected]>
Date:   2018-10-05 02:22:45 -0700

    Fix condition for page pruning.

    In zheap_page_prune_guts condition for pruning was wrongly set. This patch
    fixes same. Along with it patch also fixes the code which made NULL pointer
    dereference.

    By Amit Kapila and Mithun C Y

commit 1662919e20b45e515849304f68e310b28939aae6
Author: Amit Kapila <[email protected]>
Date:   2018-10-04 19:36:10 +0530

    Support Cluster/Vacuum Full in zheap.

    As of now we only rewrite LIVE tuples and we freeze them before storing in new
    heap.  This is not a good idea as we lose all the visibility information of
    tuples, but OTOH, the same can't be copied from the original tuple as that is
    maintained in undo and we don't have facility to modify undorecords.  We
    have some ideas how to do that and those are documented in rewritezheap.c.

    Patch by Amit Kapila with help from Mithun C Y who also reviewed the patch.

commit 62606342d267ad671d7084798ac9febd1230919c
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-04 11:22:11 +0530

    Fix compiler warnings

commit bfe41c9db8b397d9c230b36f5c7f6f7826b7fa64
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-04 10:49:57 +0530

    Fix assert for insertion of frozen tuple

    If we're freezing a tuple during insertion, we can use the HEAP_INSERT_SKIP_WAL
    optimization since we don't write undo for the same. Hence, adjust the
    assert in zheap_prepare_insert accordingly.

commit 8defd8aa1852f24ca81552efbf158d3abeda7662
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-03 19:07:57 +0530

    In zheap parallel scan, use SnapshotAny if required

commit 268ab31eebddb41e4f5c9bfb026b9e88f24d4416
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-03 19:06:48 +0530

    During in-place updates, update t_hoff correctly

commit 14dd056736a4cdf4949f798bf1386b80671ada85
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-03 19:01:57 +0530

    Initialize startblock for zheap scan

    Since zheap scan unconditionally uses scan->rs_startblock in zheap_getnext,
    we should initialize the same by default. Otherwise, valgrind barks
    loudly. This may also result in undefined behaviour in release mode.

commit bf1b20a81832f1c007690cda95088aef857bd34d
Author: Kuntal Ghosh <[email protected]>
Date:   2018-10-03 19:00:25 +0530

    Fix scan initialization for zheap tables

    Use zheap_beginscan_parallel in _bt_parallel_scan_and_sort for scanning
    zheap tables.

commit e090a7c5b3f82578d38860cf0e0244aee5e585e7
Author: Dilip Kumar <[email protected]>
Date:   2018-09-28 15:03:14 +0530

    undoworker for hadling the rollback

    This patch introduces two type of workers the discard-worker and
    the undo-launcher. The discard worker's main responsibility is
    to discard the older undo and the undo-launcher will process the
    rollback hash table and launch undo-worker one for each dbid.
    The undoworker will take the database connection and start
    processing all the request for that db.  Once the undo-action is
    applied than it will mark the transaction header in the undo as
    processed and remove the entry from the rollback hash table.

    Dilip Kumar Reviewed by Amit Kapila

commit 93ed5d44e3f9c62b78fa651d7a9082cfc57791f6
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-25 13:28:47 +0530

    Fix some TPD issues

    1. Introduced Asserts for ZHEAP_METAPAGE before calling ZheapInitPage.
    Metapage should not be initialized using this method.
    2. Introduced Asserts to identify zheap metapage after reading the same.
    3. Fixed tpd_desc.
    4. In TPDPageAddEntry, we shouldn't shuffle the item pointers.
    5. In TPDAllocatePageAndAddEntry, when new page is not added, we
    shouldn't over-write previous and next block number in tpd opaque space.
    6. Set LSN in page header for meta page.
    7. For PageSetUNDO while locking a tuple, send set_tpd_map_slot=false.
    8. Properly initilize fist and last tpd page in meta page.
    9. In zheap_xlog_update, send proper undo pointer in TPDSetUNDO.
    10. Fixed the storage of old tpd slot in xlrec.
    11. Fixed compactify_ztuple memory overrun issue.

    Patch by Dilip Kumar and me. Reviewed by Amit Kapila.

commit 8683fff396da98ad00ae3b853714b0788bff99b6
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-27 16:54:01 +0530

    Fix compiler warnings in xact.c

commit 3f86bb91ece478ab9ab562cc1972bb85d9f2a965
Author: Rafia Sabih <[email protected]>
Date:   2018-09-26 15:32:12 +0530

    Introducing sub-transactions lock type in zheap

    With this patch, the sub-transactions will have a new type
    of lock for them. Now, instead of waiting for top-level
    transaction lock, the tuples are free once the sub-transaction
    is committed. This way, we neither waste our transaction-slots
    by assigning transaction ids to sub-transaction, nor we suffer
    in performance by waiting on top-level transactions.

    Patch by Amit Kapila and me.

commit f0a2c8247aad9fe1569709599c5b267f473a6024
Author: Dilip Kumar <[email protected]>
Date:   2018-09-25 17:22:41 +0530

    Bugfix in inserting the undo record when previous transaction and
    the current transaction are in different undo logs.

    Earlier it was just comparing the block number to find whether
    we have already read the  buffer or not, but that's not
    enough when we are comparing block no. which are in two different
    undo logs.

    Dilip kumar Reported by Thomas and Reviewed by Amit Kapila

commit 4060bd90a3a47dfc9e5b396b3071c9c4d6bd0dcd
Author: Dilip Kumar <[email protected]>
Date:   2018-09-25 17:17:48 +0530

    Add comment for specific handling of geting CID for inserted
    tuple with lockers.

    Dilip Kumar Reviewed by Amit Kapila

commit e5eee5471d739b1abf084feed6635c5a526e43b4
Author: Dilip Kumar <[email protected]>
Date:   2018-09-25 14:15:21 +0530

    Fix compilation error

commit 0fe57bf56a54fecf31d7b810c47853ba8e00925b
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-25 13:26:05 +0530

    Fix zheap_mask declaration

commit 61226ffd40ad0841d6c1cd4bbf792ec9e85349ba
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-20 11:44:55 +0530

    Dont call GetTransactionSlotInfo for all visible tuple

    For all visible tuple, the corresponding slot can be re-used or pruned.
    Hence, we shouldn't call GetTransactionSlotInfo to retrieve the
    transaction information for the same slot.

commit 20c3244baba9a72530fc4747da962190a15623f2
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-25 12:04:00 +0530

    Check WAL Consistency for TPD and zheap meta pages

commit 5f8604946763e6b537f8f68f382b5da62a7d5a86
Author: Mithun CY <[email protected]>
Date:   2018-09-24 06:24:18 -0700

    Test fix, Allow inplace updates if the row can fit on the same page.

    By Mithun C Y Review Amit Kapila.

commit 0b83a48a01eb57ffd8a247c8adbe3c85de1d8d98
Author: Amit Kapila <[email protected]>
Date:   2018-09-24 18:46:55 +0530

    Allow inplace updates if the row can fit on the same page.

    Currently, we perform inplace updates only when the new row is smaller than
    old row or if the old row is the last row on page and it has space after
    it. However, there are more cases where we can perform inplace updates:
    (a) If there's no free space immediately following the tuple, but there is
    a space in the page to accomodate the entire tuple. (b) If there's no free
    space immediately following the tuple, but there is a space in page to
    accommodate the delta tuple (new_tuple_size - old_tuple_size).

    We allow pruning function to rearrange the page such that it can make space
    adjacent to the tuple being updated. This is only possible if the page has
    at least space to support equal to (newtupsize - oldtupsize). Otherwise,
    also we try to prune the dead/deleted tuples to see if the new tuple can be
    accommodated on same page and that will allow inplace updates.

    To perform pruning, we make the copy of the page. We don't scribble on
    that copy, rather it is only used during repair fragmentation to copy the
    tuples. So, we need to ensure that after making the copy, we operate on
    tuples, otherwise, the temporary copy will become useless. It is okay
    to scribble on itemid's or special space of page.  While rearranging the
    page tuples will be placed in itemid order. It will help in the speedup of
    future sequential scans. Note that we use the temporary copy of the page to
    copy the tuples as writing in itemid order will overwrite some tuples. We have
    also changed the patch such that REDO will perform repairfragmentation only if
    we it has been done during DO operation.

    Amit Kapila, Mithun C Y.

commit 85262536130fbf40afb96b4d7a64692d31171cc5
Author: edb <[email protected]>
Date:   2018-09-19 09:57:29 +0530

    Fix compiler warning in tpd.c

    Reported by Mithun

commit de73a4d3c89af83d08f3e2822f0ad07090d89f77
Author: Mithun CY <[email protected]>
Date:   2018-09-18 19:46:36 -0700

    Bugfix in vacuuming zheap table.

    The function count_nondeletable_pages is using vac_strategy variable
    defined for heap even when it is called for a zheap relation. This
    patch fixes it to use zheap's vac_strategy variable.

    Reported by Neha Sharma, fix by Mithun C Y, review by Amit Kapila.

commit 92fdaf6736bd975fcf6fba3486e2578781c16404
Author: Mithun CY <[email protected]>
Date:   2018-09-18 19:36:25 -0700

    Remove no longer needed fixme comments on visibility map.

    Reported by Amit Kapila.

commit 2509bd2e93e2cc16f4555cd2112895badc304471
Author: Mithun CY <[email protected]>
Date:   2018-09-18 19:35:15 -0700

    Bug fix in execute_undo_actions_page.

    ove ZheapInitPage after XLogInsert, as TPD related information in
    page are needed by some of the functions called before.

    By Mithun C Y and Amit Kapila.

commit c5817d6ade8c1ba423bb0d04f983a65e718138d0
Author: Amit Kapila <[email protected]>
Date:   2018-09-18 08:10:04 +0530

    Support variable sized TPD entries.

    We extend the TPD entries when (a) while reserving a slot, we found that
    there aren't enough slots in TPD entry or offset-map doesn't have much
    space, (b) while getting the existing TPD entry we found that offset-map
    doesn't have enough space. If we find the space in the same TPD page, then
    we perform inplace update of the TPD entry, otherwise, a non-inplace-update
    is performed. In non-inplace-update, we mark the old entry as deleted and
    later during pruning, if we encounter any deleted entry, we directly prune
    it.

    Currently, the implementation of in-place updates is not complete, so we
    always perform non-in-place update.

    Patch by Amit Kapila, Dilip Kumar and Kuntal Ghosh.

commit f17c96014308f8f01385a82e41be8601073d147e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-14 16:43:14 +0530

    In replay of freeze_xact, read TPD buffer before using it

commit 40ce6e610d138de1ebb2944ce619db9f53df61f1
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-14 12:39:18 +0530

    Fix a flag in xl_zheap_lock

    In xl_zheap_lock flags, we've skipped the second bit for no good reason.

    Reported by Dilip Kumar.

commit 58000e7691eda261ddc99566f24b03692bf2b19a
Author: Kuntal Ghosh <[email protected]>
Date:   2018-09-13 17:51:11 +0530

    Implement serializable isolation APIs for zheap

    For PredicateLockTid, ConflictIn and ConflictOut, we pass the tid to
    identify the tuple.

    For conflict out, we've introduced a function ZHeapTupleHasSerializableConflictOut
    that performs all zheap related work to figure out whether the reader
    conflicts out with any other writers. In ZHeapTupleHasSerializableConflictOut,
    we refetch the tuple and check the recent status of the tuple. Using
    that, we decide whether we conflicts out.

    We've a special handling for the tuple which is in-place updated or the
    latest transaction that modified that tuple got aborted. In that case,
    we check whether the latest committed transaction that modified that
    tuple is a concurrent transaction. Based on that, we take a decision
    whether we have any serialization conflict.

    Patch by me with help from Amit Kapila. Reviewed by Amit Kapila and
    Thomas Munro.

commit b401a9c4da9e9038a0a72e4c31f31ba87bd43dbb
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-07 19:49:32 +0530

    Make serializable code independent of storage

    This code aims to make PredicateLockTuple, CheckForSerializableConflictIn
    and CheckForSerializableConflictOut independent of storage tuple.
    PredicateLockTuple and CheckForSerializableConflictIn method can
    work with tid only. However, CheckForSerializableConflictOut requires
    the storage tuple to check latest visibility status of the tuple. Hence,
    I've separated the *SatisfiesVacuum and its usage towards conflict
    resolution in a separate storage specific function.
    I've also renamed PredicateLockTuple to PredicateLockTid.

    Patch by me. Reviewed by Amit Kapila and Thomas Munro.

commit 44d776147cdafc55ea3fe95569bb039352e580ac
Author: edb <[email protected]>
Date:   2018-09-10 21:27:38 +0530

    Change behaviour of zheap_fetchinsertxid

    Earlier this function was returning xid which has inserted the tuple.
    But, the tuple can be inserted by multi_insert and inplace-update
    operations as well. Hence, we should handle that.

commit e5b821e0cfc905ea32e11a9619cf797de2342104
Author: Rafia Sabih <[email protected]>
Date:   2018-09-06 18:28:49 +0530

    Modifying the size of rs_visztuples in HeapScanDescData

    The size of rs_visztuples was kept to a fixed value which was causing
    the failure in regression suite when running with increased blocksize.
    Now, it is modified to the value of MaxZHeapTuplesPerPageAlign0.

    Patch by me, reviewed by Amit Kapila.

commit 0136ec40cb54df56f52af626df680ae5981e8fd3
Author: Rafia Sabih <[email protected]>
Date:   2018-09-06 17:07:53 +0530

    Bugfix in toast table updation

    Patch by me and reviewed by Amit Kapila

commit e12bb90c6751d60564535a7effc8e08994d61f3c
Author: dilip kumar <[email protected]>
Date:   2018-09-03 11:32:30 +0530

    Fix compilation warning in test_undorecord.c

    Reported By Amit Kapila.

commit c11609baa42bd0332bc90a97a2d27814a66346b9
Author: Thomas Munro <[email protected]>
Date:   2018-09-03 15:43:14 +1200

    Reorder handling of ONCOMMIT_TEMP_DISCARD.

    The previous coding accidentally caused ONCOMMIT_NOOP to enter the
    new ONCOMMIT_TEMP_DISCARD case.

    Patch from Rafia.

commit 16a7bf70c67dae185d74e5cd988af8bb6d2bb4fd
Author: Thomas Munro <[email protected]>
Date:   2018-09-02 05:02:57 +1200

    Fix test_undo undo_append_file() procedure.

commit 6f94ac34370ffd305bf702fa514136eab98e43f7
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 22:46:34 +1200

    Delete undo log files in dropped tablespaces in recovery.

    When a tablespace is dropped, we clear out any remaining undo log files.

commit c7e00a820e5daaa3c7a268cdae195a859c5476af
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 18:43:50 +1200

    Handle missing undo log segment files during WAL replay.

    In recovery, segment files may not be present because they will be deleted
    by later WAL records.  Following the example of regular relation files, we'll
    supply empty files.

    Previously, I created unexpectedly missing files during startup, which
    didn't work correctly if we crashed after dropping a tablespace (I couldn't
    create the files in the tablespace directory if it has already been
    deleted).  This new approach does what other PostgreSQL code does, and
    creates a new tablespace directory as required (expecting it to be deleted
    by a later WAL record).

    Thomas Munro

commit 3bbf152f4d330e582e950a45790d0e375d93bc5c
Author: dilip kumar <[email protected]>
Date:   2018-08-26 14:11:59 +0530

    Fix thinko in assert.

commit 1e9d17cc2406683b014f872ce873c845adafe3af
Author: dilip kumar <[email protected]>
Date:   2018-08-26 14:10:21 +0530

    Fix discrepancy between ZHeapTupleSatisfiesUpdate and

    HeapTupleSatisfiesUpdate also for the non-inplace update, it was trying to
    fetch the cid from the prev_undoptr but in case of non-inplace update it will
    not find the previous version of the undo so get the cid while copying the
    tuple.

    Dilip Kumar, Amit Kapila  Review and tested by Ashutosh Sharm

commit 4cc08c3ee0c31346af8c8a02a45a7bb759c3ed68
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-10 22:24:22 +0530

    Refetch tuple after reserving slots in the page

    When we reserve a slot in the page, we sometimes freeze some tuple in
    the same page. Hence, we should re-fetch the tuple to update the slot
    information.

    Patch by me. Reviewed by Amit Kapila.

commit 056a37b464058d6c386b6337ad65589f15c1a9b3
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-10 16:49:11 +0530

    An optimization for temp tables

    For temp relations, we don't have to check all the slots since
    no other backend can access the same relation. If a slot is available,
    we return it from here. Else, we freeze the slot in PageFreezeTransSlots.

    Note that for temp tables, oldestXidWithEpochHavingUndo is not relevant as
    the undo for them can be discarded on commit.  Hence, comparing xid
    with oldestXidWithEpochHavingUndo during visibility checks can lead to
    incorrect behavior.  To avoid that, we mark the tuple as frozen for any
    previous transaction id.  In that way, we don't have to compare the previous
    xid of tuple with oldestXidWithEpochHavingUndo.

    Patch by me. Reviewed by Amit Kapila.

commit 10c225fbd9a3aa8239efaf8cf6d00e8b7e9d589d
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-10 13:50:15 +0530

    GUC to enable/disable undo launcher

    We've introduced a new GUC variable called disable_undo_launcher
    to enable/disable the undo launcher process. If true, the postmaster
    won't register the undo launcher. By default, it's set to false.
    This is a postmaster option. Changing the value requires a restart.

    Patch by me. Reviewed by Amit Kapila.

commit e613fa25d714ddba99f2b3675894f3d0d141df4f
Author: dilip kumar <[email protected]>
Date:   2018-08-23 16:40:35 +0530

    Undorecord cleanup.

    Created two files undorecord.c and undoinsert.c where undorecord.c
    mainly deals with how to insert and read the undo record and the
    undoinsert.c provides external interfaces to prepare,insert and
    fetch undo and deals with buffers management required for undo record.

    Dilip Kumar Review by Amit Kapila

commit dccab1c216d8677bb6ad716e13adc08da44f79a9
Author: dilip kumar <[email protected]>
Date:   2018-08-23 10:39:53 +0530

    bug fix in pg_control_checkpoint

    Reported by Andres

commit 6d3f5716cb4257e8226212fbe002f05cc0d60145
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-17 18:54:13 +0530

    Fix issue in vmbuffer wal replay

    While logging visibility map changes for zheap, we don't register
    the zheap buffer. That's intentional since we don't set any hint bits
    in zheap buffer for tracking visibility. But, we've to store the block
    number in WAL so that we can track the block number for setting the
    corresponding visibility map bit while replaying the WAL for the same.

commit 9fc32f608a0900f8ed051cc010e72a40abe318ac
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-20 14:39:05 +0530

    Fix prevxid for insert/multiinsert WAL replay

    We should set the prev xid as frozen during WAL replay of insert and
    multiinsert.

commit 9fcccee5d272c437a898171a4a97317ba1430ee0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-20 16:25:02 +0530

    Fix slot index in undo_xlog_reset_xid

commit 0047fe43fe0fa5a10833d7f864d81b6a2e4ac4ed
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-17 17:59:59 +0530

    In zheap_update, fix WAL record for lock tuple

    This is leftover of commit 9b1f493a6335d07024. In zheap_update, we also
    lock the tuple. Hence, we need to fix the transaction slot related issue
    that was fixed as part of the above-mentioned commit.

commit e5f5c83c3120ac90c0a8501a584935a0ceb782f4
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-16 16:13:10 +0530

    Lock undo buffer while preparing an undorecord

    Currently, we're locking the undo buffers in InsertPreparedUndo. This
    is called under critical section. If we encounter any error while
    taking the lock under critical section, it'll lead to server crash. We
    can easily avoid this situation by taking the lock in PrepareUndoInsert.

commit 25593d3c8351df93c9d5d57ec5b88ba94f10df7a
Author: Rafia Sabih <[email protected]>
Date:   2018-08-21 11:37:09 +0530

    Bugfix in temp table rollbacks

    If rollback_oversize is set to zero then rollbacks of temp tables
    were pushed to RollbackHT. This is corrected to perform the
    rollbacks by the backend itself.

    Reported by Neha Sharma, patch reviewed by Amit Kapila

commit 420810a9cc500cdc539d34e8e4e49296337453e8
Author: Rafia Sabih <[email protected]>
Date:   2018-08-20 12:00:03 +0530

    Bugfixes in UserAbortTransactionBlock

    - If rollback request could not be pushed, then backend executes
    the undo actions.
    - Corrected arguments for PushRollbackRequest.

    Reported by Dilip Kumar.

commit 771f43b086060f2b1bba25a857693886aa0ef4e9
Author: Mithun CY <[email protected]>
Date:   2018-08-19 19:21:41 -0700

    Bug fix, In lazy_cleanup_index and lazy_vacuum_index we shall use
    vac_strategy passed to it by either zheap or heap relation.

    By Mithun C Y, reviewed by Amit Kapila.

commit bd0b43b93ed204749347d3c885ee258942cc8221
Author: Rafia Sabih <[email protected]>
Date:   2018-08-17 15:55:22 +0530

    Bugfix for speculative insert in toast table

    Reported by Kuntal Ghosh, reviewed by Amit Kapila

commit cb36f7e7e848cfb11a5062684451788a41f048f9
Author: Rafia Sabih <[email protected]>
Date:   2018-08-17 15:53:50 +0530

    Bugfix in ZMultilockers

    Found as part of a bug reported by Neha, reviewed by Amit Kapila

commit 22e1c1c33e1e5ed129de8fbfa539d943ae42c844
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-16 13:46:54 +0530

    For insert/multi-insert, set previous xid as frozen

    When we modify a tuple, we set the previous xid for this tuple as frozen
    if its previous modifier xid is older than the discarded xid. For insert/
    multi-insert, we don't have any previous modifier. Hence, we can set it
    as frozen unconditionally.

commit 9668bfac227acb13c87dcdf8a54e440aab768e07
Author: Rafia Sabih <[email protected]>
Date:   2018-08-16 09:32:43 +0530

    Indentation fix.

    Reported by Andres.

commit 45e405946ff54b5461fdeb7f2a4826c7a87a890a
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-14 17:14:23 +0530

    Use ZHeapTupleHasInvalidXact wrapper consistently

commit 043603d58f4dfc4bd8b1f7ddaa4f2c73e5713f24
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-14 17:12:46 +0530

    Update regression tests file in pageinspect

commit 4d0a2ebf9e8bc40f44430174d9990b26b473405c
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-14 16:19:35 +0530

    Bugfix in zheap_update for non-inplace updates

    For non-inplace, we should always mark the tuple as locker-only
    if we're propagating the key-share lock to the new tuple.

    Reported by Rafia Sabih. Reviewed by Amit Kapila. Patch by me.

commit 1b8c7eba990341809096a245937c48e2fdb875d2
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-14 14:49:36 +0530

    Fix bug in regression tests for pageinspect

    The previous commit of pageinspect forgot to attach the zheap.sql
    and zheap.out file required for regression tests.

commit 02d983e5a5b4a6e2b76b59023668a98457465060
Author: Amit Kapila <[email protected]>
Date:   2018-08-14 13:43:31 +0530

    Propagate lockers information.

    We were not propagating the lockers information when the tuple has
    multi-lockers bit set.  Fix it.

    Reported by Ashutosh Sharma, Patch by Amit Kapila.

commit b16f0fec8868482773d5a7bc37ec9369dcfaa476
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-14 10:52:08 +0530

    In bitmap scan, don't keep the pin on the buffer

    For bitmap scan, we always use pagemode to scan the tuple. Hence, there
    is no need to keep the lock on the tuple.

commit 191d6f03c143097d63e17e057935a30f3a4db6bc
Author: Rafia Sabih <[email protected]>
Date:   2018-08-13 15:25:56 +0530

    Bug fixes

    - fixes for incorrect retieval of TPD buffer
    - fixes for incorrect size calculation of undo-header at recovery time
    - fix for accessing an uninitialised variable in TPDPageGetTransactionSlots
    - fixed one space issue in zheapamxlog.c

    Came across these while working on an issue reported by Neha Sharma.
    Reviewed by Dilip Kumar

commit 5fcf8c59430fe4ae105d544d9f406c1e7e3e3959
Author: dilip kumar <[email protected]>
Date:   2018-08-10 17:34:05 +0530

    Bug fix in undo action

    When previous version of the tuple has the TPD slot that time
    we need to pass a flag to the function so that it can set the
    tpd slot in the offset map.  Mistakenly that option was always
    passed as 0.

    Dilip Kumar Reviwed by Kuntal Ghosh

commit ef717922bb7f357a772e2f274766e1d1049beb37
Author: dilip kumar <[email protected]>
Date:   2018-08-10 15:27:29 +0530

    Fix Typo

    Reported by Andres.

commit f68d2c8862ee2f0981ccbc767c1435cca647b804
Author: Amit Khandekar <[email protected]>
Date:   2018-08-10 09:35:12 +0530

    Allow in-place updates for some expression indexes.

    This is a zheap port of commit c203d6cf81b4d :
    "Allow HOT updates for some expression indexes."

    Since we can do HOT udpates for such expressions, allow in-place
    updates for the same expressions.

    Add a new regression test zheap_func_index.sql derived from the
    existing test func_index.sql. The new test uses
    pg_stat_get_xact_tuples_inplace_updated().

    Amit Khandekar, reviewed by Amit Kapila.

commit c5e306aa3afc6b8ac2975be699772c76734d0ff0
Author: Amit Khandekar <[email protected]>
Date:   2018-08-10 09:24:10 +0530

    Add a pg_stat function for inplace updates in a transaction.

    There was already a pg_stat_get_tuples_inplace_updated() function for
    getting in-place updates in a session. But the _xact_ version was
    missing.

    Amit Khandekar, reviewed by Amit Kapila.

commit 24c5086eb332d3e0549238f25641887c9c9d03fb
Author: Kuntal Ghosh <[email protected]>
Date:   2018-06-25 20:22:29 +0530

    Add pageinspect functions to analyze zheap page and zheap tuples

    It adds two functions zheap_page_items to inspect the tuples in
    the page. It also adds another function zheap_page_slots to inspect
    the transaction slots in the special space. If the page contains
    TPD slot, then zheap_page_slots doesn't show the same since it
    doesn't contain any transaction information.
    TPD slot information can be shown in future once the structure of
    TPD page is stabilized.

    Patch by me, reviewed by Ashutosh Sharma

commit a8442adccf916a5de5c79f4c8a155cc6d4fe9919
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-08 17:28:47 +0530

    Initialize some local tuples in zheap scan APIs

    It also fixes a bug in zheapgetpage. We should not copy the tuple
    for deleted item pointers.

commit abb680be862a99fc23b3abfa28f159b545eba5e6
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-09 14:22:37 +0530

    Fix some compiler warnings

commit 11b199c7d779a2beb6ba9217303d4b73359665c2
Author: dilip kumar <[email protected]>
Date:   2018-08-09 11:39:09 +0530

    Allow freezing and reusing of the TPD slots

    Currently, for zheap pages we allow to freeze slots of the
    the all visible xids and also allow to reuse the slot of the
    committed xids.

    This patch is implementing the same for the TPD slots. The mechanism
    of the freezing and reusing the tpd slots are same as for the
    zheap page slots.

    Dilip Kumar reviewed by Amit Kapila

commit 67ca8248109f52c10f06347ac82ab20693547b7f
Author: Amit Kapila <[email protected]>
Date:   2018-08-09 12:04:50 +0530

    Remove unnecessary changes related to zheap from RelationGetBufferForTuple.

    Now, that we have a corresponding separate function for zheap, we can remove
    the zheap related changes from the function RelationGetBufferForTuple.

commit e18858cffcbf964d7cf3aab7a087673bd492652b
Author: dilip kumar <[email protected]>
Date:   2018-08-09 11:22:40 +0530

    Bug fix in execution undo action

    Set the proper slot on the TPD offset map while replaying undo actions
    if the prior version of the tuple is pointing to the TPD slot.  Prior
    to this we are simply overwriting the older tuple version but the slot
    is not updated in the TPD offset map.

    Dilip Kumar review by Amit Kapila

commit db2d9ae8a2c609e2535932b1bbcc9bb9181ca7b8
Author: Mithun CY <[email protected]>
Date:   2018-08-08 22:10:29 -0700

    Post push fix for 2c9d6d9216ad28be2 which by mistake resued
    a flag value.

    By Mithun C Y

commit 2c9d6d9216ad28be25b5e4d60c07f5fb2db6096b
Author: Mithun CY <[email protected]>
Date:   2018-08-08 21:49:15 -0700

    Bug fix, move calls of visibilitymap_pin or visibilitymap_status
    outside the critical section at execute_undo_actions_page.

commit 7b799efee32450a93b5200774d3550893d4049e0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-07 10:44:00 +0530

    Handle whether a tuple is self-locked before modifying it

    While deleting/updating a tuple, we should check whether the tuple
    is already locked in desirable lockmode by the current transaction.
    We've missed this check in zheap_delete/zheap_update when the tuple
    is marked with multilocker flag.

    Patch by me and Dilip Kumar. Reported by Thomas Munro.

commit b51357225493b0436bedece52075de58334d3abd
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-07 14:14:24 +0530

    Fix a bug while fetching a pruned tuple from all-visible page

    In zheapgetpage, when a pruned tuple is fetched from an all-visible
    page, we return NULL (and we should return NULL). But, in page-scan mode,
    we increase rs_ntuples by mistake.

commit 2b9bb36f1a7bdcf1e2792e31d943fad3bbc9fa8b
Author: dilip kumar <[email protected]>
Date:   2018-08-07 08:54:58 +0530

    Fix various bugs in TPD with multi-lockers
    - Locker is setting wrong slot in TPD offset map
    - Locker is not calculating proper TPD slot for members.

    Dilip Kumar Reviewed by Amit Kpila

commit 3967b9019e051842c2947aa0333c4938facdb636
Author: dilip kumar <[email protected]>
Date:   2018-08-06 16:02:02 +0530

    A minor bug fix in TPD code, missing break statement in switch case

    Reported by Andres.

commit 7949de7ff8bd4cd9d99f5cd81ad1211af5a55c7e
Author: Mithun CY <[email protected]>
Date:   2018-08-05 05:58:36 -0700

    Support visibility map for zheap.

    With the support of visibility map for zheap relation, vacuum task
    and Index Only scan can skip looking into all visible pages. Also,
    on page flag PD_ALL_VISIBLE is no more in use for zheap.

    Index Only scan for zheap is enabled with this patch.

    By Amit Kapila, Mithun C Y

    Review by Amit Kapila.

commit 585226697f91c61926361ad565a10f7a78144ad5
Author: Amit Khandekar <[email protected]>
Date:   2018-08-03 12:44:03 +0530

    Pass the right priorXMax to ValidateTuplesXact()

    In zheap_get_latest_tid(), ZHeapTupleGetTransInfo() was getting called
    with 'resulttup'. But because 'resulttup' is returned from
    ZHeapTupleSatisfiesVisibility(), it can be a tuple generated from an
    undo record. And if we use ZHeapTupleGetTransInfo() to get the xid
    that modified resulttup, it returns the xid that created the original
    tuple instead of the xid that modified the tuple. This results in
    the wrong xid being passed as priorXMax to ValidateTuplesXact(), which
    in turn leads to assertion failures.

    So move the ZHeapTupleGetTransInfo() call before
    ZHeapTupleSatisfiesVisibility() call, so that we could use 'tp' rather
    than resulttup. 'tp' gets freed by ZHeapTupleSatisfiesVisibility(), so
    we could not use tp after ZHeapTupleSatisfiesVisibility() call.

    Added a new isolation test.

commit 7ad7a9aedaf883e02caf5b172374344faa4507b8
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-02 19:44:07 +0530

    Fix some compiler warnings

commit db8af0bf6388182415d0cbcde55882a1bf8de84c
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-02 14:18:00 +0530

    Report the scan location for zheap meta page

    During scan, we report our scan position for synchronization
    purposes. We do this before checking for end of scan so that the
    final state of the position hint is back at the start of the
    rel. But, if we skip metapage, the scan location may point to a
    block at the end of the relation.

    Patch by me, reviewed by Amit Kapila

commit caf343183b8940670f9f953014f6815883f9f66c
Author: Kuntal Ghosh <[email protected]>
Date:   2018-08-02 14:14:50 +0530

    For parallel scan, find and set the scan's startblock

    Probably, we've missed this change during earlier rebase.

commit ec6c8b936c6de6af49816e29dd04ebc363aad5e6
Author: Thomas Munro <[email protected]>
Date:   2018-07-26 16:43:44 +1200

    Fix silly bug in undolog_xlog_discard().

    When an XLOG_UNDOLOG_DISCARD record is replayed, we need to tell the
    checkpointer to forget about any files that we are about to unlink.
    I was using the wrong variable, so if a single XLOG_UNDOLOG_DISCARD
    record caused segment files 1, 2, 3 to be unlinked, I was telling it
    to forget about fsyncing 3, 3, 3.  Then it would eventually try to
    fsync 1 and 2 and try to raise an error.  Repair that.

    Additionally, in the error path resulting from the above bug, I was
    also calling FilePathName() on a File that I had failed to open.  That
    causes an assertion failure.  Repair that too.

    Thomas Munro, reported by Neha Sharma, RM43571

commit 9d8be03646a5775000e1008badcabf0a5ff828bc
Author: Thomas Munro <[email protected]>
Date:   2018-07-26 17:56:27 +1200

    The startup process shouldn't attach to undo logs.

    When replaying XLOG_UNDOLOG_META records, the startup process was
    recording that it was attached to the referenced undo log.  That
    caused corruption of the freelists when it tried to detach on exit.
    During recovery we shouldn't attach at all; instead we use the
    xid->undo log mapping.

    Thomas Munro, RM43614

commit adaaac4518c68b378ec2c60a2a8b29353de6b190
Author: Rafia Sabih <[email protected]>
Date:   2018-08-01 11:52:41 +0530

    Toast table support for zheap

    Now, toast tables for zheap tables are created of zheap type. This imporves the
    performance in terms of memory by reducing the bloat in toast tables. With zheap
    type toast tables, as soon as a transaction deletes a tuple and commits, the space
    can be utilised for the next insertion. Since, toast tables are larger in size
    compared to ordinary tables and their updation is handled by insertion + deletion,
    zheap storage is likely to benefit significantly.

    Reviwed by Amit Khandekar and Amit Kapila.

commit b2509b38661f97c1e1308a5b043a1f34d4d9ebeb
Author: Rafia Sabih <[email protected]>
Date:   2018-08-01 11:46:12 +0530

    Bugfix in GetLockerTransInfo

    The initialization of trans_slots was missing.

commit b455083f2a902df76ba43e38fb16260fd26fb4f0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-31 16:21:47 +0530

    In zheap, we cannot ignore trans status of backends executing vacuum

    For zheap, since vacuum process also reserves transaction slot in page,
    other backend can't ignore this while calculating OldestXmin/RecentXmin.

commit df3e6a10a3ba9c5fe81dd80fc1bfd105b7b42478
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-31 16:15:23 +0530

    During vacuum, reserve sufficient offsets in tpd page

    In lazy_vacuum_zpage_with_undo, we should allocate sufficient space
    in tpd page to store the highest unused offset from zheap page.  Since,
    we've to reserve space before determining the unused offsets, we reserve
    space for maximum used offset in the zheap page.

commit 58e36c8929684198c40bb326cfb455e719b7a11d
Author: Amit Kapila <[email protected]>
Date:   2018-07-31 14:51:17 +0530

    Support pruning in TPD pages.

    The basic idea is process all the TPD entries in the page and remove
    the old entries which are all-visible. We attempt pruning when there
    is no space in the existing TPD page. Also, while accessing TPD entry,
    we can consider the entry as pruned, if we find that the
    ItemIdIsUnused or the block number in TPD entry is different from the
    heap block number for which we are accessing the TPD entry.

    Amit Kapila with help from Dilip Kumar.

commit 1c37ab83d083241d8738444980ca5510e8e5deb0
Author: Amit Kapila <[email protected]>
Date:   2018-07-31 14:23:08 +0530

    Store Itemids in TPD page.

    Earlier heappage always point directly to the actual offset of TPD
    entry in a TPD page.  This won't work after pruning as even if the
    particular page's TPD entry is not pruned, we might not be able to
    directly access the TPD entry as offset might have moved. Now, we can
    reach our TPD entry if we can traverse all the TPD entries and TPD
    entry has block number in it, but that is quite inefficient.  To
    overcome this problem, it is better to store Itemids in the TPD page.

    Amit Kapila, reviewed and verified by Dilip Kumar

commit ed01319cc1d9541b3293b051d3d91eb35b7c448d
Author: Thomas Munro <[email protected]>
Date:   2018-07-31 18:43:17 +1200

    Improve smgr README.

    Wordsmithing.

    Thomas Munro

commit 99f54c695641304061847f6124f04fc9f82a5317
Author: Thomas Munro <[email protected]>
Date:   2018-07-31 18:33:22 +1200

    Add missing case to undolog_identify().

commit 9a956e391937f685fd3284620c0c6796362cfdf0
Author: Thomas Munro <[email protected]>
Date:   2018-07-31 18:30:04 +1200

    Add basic undo log storage tests.

    Exercise basic undo log storage code under make check-world.

    Thomas Munro

commit 576f60e34994d4e5777c3e1e17c9987199c46a1f
Author: Rafia Sabih <[email protected]>
Date:   2018-07-27 17:55:32 +0530

    Discard temp table undo logs for zheap

    At the commit of a transaction, backend discards temp table undo
    logs.

    Reviewed by Dilip Kumar and Amit Kapila

commit c61887386927699c1f40c8ad2da0bb49948d38eb
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-27 17:21:48 +0530

    In zheap_update, fix condition for reserving slots.

commit 142f2a014312c668eddc20d9a43d5c81baa48675
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-27 12:37:02 +0530

    An optimization to improve COPY FREEZE in zheap

    In COPY FREEZE, when we insert a tuple, we always mark it as frozen.
    Hence, there is a possible performance optimization for the same scenario:
    1. We can skip inserting undo records for the tuples to be inserted.
    2. There is no need to reserve a transaction slot.

    Here is the implementation details:
    1. Set skip_undo = true if HEAP_INSERT_FROZEN is mentioned.
    2. If skip_undo is true, we don't have to reserve a transaction slot in
    the page. Also, we skip preparing and inserting undo records for the
    to-be-inserted tuples.
    3. For recovery, a new WAL flag XLZ_INSERT_IS_FROZEN is introduced. It's
    true if HEAP_INSERT_FROZEN is mentioned. During WAL replay, we skip preparing
    and inserting undo records if XLZ_INSERT_IS_FROZEN is set in WAL records.

    Patch by me. Reviewed by Amit Kapila.

commit 3dd753713bfdedebd5d38cdd709d61f4cf97b60e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-06-22 12:46:15 +0530

    Cosmetic changes in zheap_multi_insert and zheap_xlog_multi_insert

    This commit removes the usage of undo record information at other
    places in the same function. This makes the coding easy when we
    intend to skip undo insertions.

    Patch by me. Reviewed by Amit Kapila.

commit bf8288d70bad7da53ea6ab3457ac234ca08ff4f9
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-27 16:29:44 +0530

    In ZHeapGetVisibleTuple, fetch transaction slot correctly

    When we call GetTransactionSlotInfo to fetch the transaction info
    from undo, we should pass TPDSlot=false since we fetch the slot
    from the item pointer. Item pointer never stores TPD slots.

    Reported by Neha Sharma. Patch by Mithun CY. Reviewed by Amit Kapila.

commit 0f4f8ad4b402ab3163c78691c70ebcf38cc54384
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-27 12:15:32 +0530

    In ZHeapGetVisibleTuple, handle non-mvcc snapshots

    Reported by Neha Sharma. Patch by me. Reviewed by Amit Kapila.

commit 8d395035cc9a711b6761006b5b2433aa4077ea12
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-27 11:12:05 +0530

    Fix some compiler warnings

commit 2a932c0c1580a699740b5628562f014381dd48c5
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-25 16:50:58 +0530

    Handle locked-only tuple in ZHeapTupleSatisfiesOldestXmin

    In ZHeapTupleSatisfiesOldestXmin, we can't take any decision if the
    tuple is marked as locked-only. It's possible that inserted transaction
    took a lock on the tuple. Later, if it rolled back, we should return
    HEAPTUPLE_DEAD, or if it's still in progress, we should return
    HEAPTUPLE_INSERT_IN_PROGRESS. Similarly, if the inserted transaction
    got committed, we should return HEAPTUPLE_LIVE. The subsequent checks
    in the function already takes care of all these possible scenarios,
    so we don't need any extra checks for locked-only tuple.

commit bca6d63cdc78fd8e8d5804b0296b2d1c436af7d5
Author: dilip kumar <[email protected]>
Date:   2018-07-26 17:52:14 +0530

    Fix bug in prepared transaction.  StartPrepare is only copying
    the first member of the array instead of copying whole array.

    Dilip Kumar Reviewed by Amit Kapila

commit 199b463c81cb253b4bb77645629dc9b621ab865c
Author: dilip kumar <[email protected]>
Date:   2018-07-26 17:51:43 +0530

    fix the regression test for the zheap.

commit 85b792b7a12c91e59abe0189e79587fd516ea1c2
Author: dilip kumar <[email protected]>
Date:   2018-07-26 17:49:08 +0530

    Create an auxiliary resource owner for the undoworker because now
    we need to have valid resource owner for accessing the buffer.

    Dilip Kumar Reviewed by Amit Kapila

commit f41d0055f5129b99530f1fc0f612b21627e816b2
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-25 12:09:10 +0530

    Handle single in-progress locker in ZHeapTupleSatisfiesUpdate

    For single in-progress locker, ZHeapTupleSatisfiesUpdate returns
    locker's xid and transaction slot along with latest modifier/inserter's
    xid and transaction slot. We also send the single locker's trans info
    and latest modifier/inserter's to compute_new_xid_infomask.

    Kuntal Ghosh and Amit Kapila

commit afe785f273dfbb393c0026677e00c32296e7406e
Author: Rafia Sabih <[email protected]>
Date:   2018-07-25 09:06:26 +0530

    Rollbacks of zheap temp tables

    We diligently take care to never push the rollback requests to
    undo worker for temp tables and the backend itself performs the
    required undo actions.

    Reviewed by Dilip Kumar and Amit Kapila

commit 9282d623ae17a9ff3f15e5e8e000150a8aee6011
Author: dilip kumar <[email protected]>
Date:   2018-07-23 18:41:22 +0530

    Undo actions is not executed in many cases when failure occurs during
    commit/abort path.  This commit fixes the same.

    Dilip Kumar Reviewed by Amit Kapila

commit 3ac8b197c0f12f91f0f8f93426e818f902036c1e
Author: Rafia Sabih <[email protected]>
Date:   2018-07-23 17:02:02 +0530

    Bug fix in PushRollbackHT

    In PushRollbackHT, if the start_urec_ptr is not given then
    get it from the log, as done in execute_undo_actions.

    Reported by Neha Sharma.

commit 5c599edf74c44a02332ed50ee939bf974bde6fef
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-19 16:43:19 +0530

    Remove unnecessary GetTransactionSlotInfo() call

commit e68f8d97ecbdf730fdd910b0e683542684c6c9d8
Author: Amit Kapila <[email protected]>
Date:   2018-07-19 08:34:50 +0530

    Fix Rollback of multilockers.

    Uptill now, on rollback, we never change the slot of tuple if the
    multilockers flag is set on the tuple.  This is because we can't find
    the next highest locker (there could be multiple lockers with same
    lock level) even by traversing undo chains.  To overcome this problem,
    we come up with a new design where we ensure that the tuple always
    point to the transaction slot of latest inserter/updater.  For example,
    say after a committed insert/update, a new request arrives to lock the
    tuple in key share mode, we will keep the inserter's/updater's slot on
    the tuple and set the multi-locker and key-share bit.  If the
    inserter/updater is already known to be having a frozen slot (visible
    to every one), we will set the key-share locker bit and the tuple will
    indicate a frozen slot.  Similarly, for a new updater, if the tuple has
    a single locker, then the undo will have a frozen tuple and for multi-lockers,
    the undo of updater will have previous inserter/updater slot; in both cases
    the new tuple will point to the updaters slot.  Now, the rollback of a single
    locker will set the frozen slot on tuple and the rollback of multi-locker
    won't change slot information on tuple.  We don't want to keep the slot of
    locker on the tuple as after rollback, we will lose track of last
    updater/inserter.

    Amit Kapila, Kuntal Ghosh and Dilip Kumar

commit 143adfee5ad287dedc744e06eaae0c0ed390005e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-16 17:14:54 +0530

    Small fix in GetTupleFromUndoForAbortedXact

commit dd2f4010834f885af0c2baffa16bc4f6cfeb0664
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-10 23:16:25 +0530

    Implement ZHeapTupleSatisfiesVacuum for pruning/vacuum

    For pruning/vacuum, we can skip the tuples inserted/modified by an
    aborted transaction. It'll be handled by future pruning/vacuum calls
    once the pending rollback is applied on the tuple. This optimization
    allows to avoid fetching prior version of the tuple from undo.

    Patch by me. Reviewed by Amit Kapila.

commit d5d9f72eca46bc01efea01f3236f1a3d279459d7
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-16 16:45:29 +0530

    Handle aborted xact in ZHeapTupleSatisfiesOldestXmin

    If the latest transaction for the tuple aborted, we fetch a prior committed
    version of the tuple and return it along with prior comitted xid and status
    as HEAPTUPLE_LIVE.
    If the latest transaction for the tuple aborted and it also inserted
    the tuple, we return the aborted transaction id and status as
    HEAPTUPLE_DEAD. In this case, the caller *should* never mark the
    corresponding item id as dead. Because, when undo action for the same
    will be performed, we need the item pointer.

    Patch by Amit Kapila and me. Reviewed by Amit Kapila.

commit 3cc15be2061d294fe2762da471c321394bf06ebb
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-13 13:26:43 +0530

    In zheap, don't support the optimization for HEAP_INSERT_SKIP_WAL

    If we skip writing/using WAL, we must force the relation down to disk
    (using heap_sync) before it's safe to commit the transaction. This
    requires writing out any dirty buffers of that relation and then doing
    a forced fsync. For zheap, we've to fsync the corresponding undo buffers
    as well. It is difficult to keep track of dirty undo buffers and fsync
    them at end of the operation in some function similar to heap_sync.

    This commit skips copy_relation_data and copy_heap_data. We need to
    revisit the same once we implement ALTER TABLE.. SET TABLESPACE and
    CREATE CLUSTER/VACUUM FULL feature for zheap.

    Reviewed by Dilip Kumar and Amit Kapila

commit d261daaee572c0d6ea953948428a93eec95eee79
Author: Rafia Sabih <[email protected]>
Date:   2018-07-10 15:45:05 +0530

    Modified output file for triggers.sql for zheap

    When storage_engine = zheap, the behavior for one test case
    is different than heap. The difference in behavior is because
    of inplace updates in zheap and non inplace updates in heap.
    This changed behavior is acceptable for zheap, hence, adding a
    new output file for zheap.

    Reported by Neha

commit 1ca9a92cde64fcc798c5a0a5e7dbc0b8aae7454f
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-09 11:58:50 +0530

    Bug fix in UndoRecordAllocateMulti

    Reported by Neha, reviewed by Amit Kapila and Dilip Kumar

commit 2eb1df348fe34bd4d68b0892a5e63d6d8a9ddb47
Author: Kuntal Ghosh <[email protected]>
Date:   2018-07-09 11:57:45 +0530

    In recovery, transaction id should be sent in UndoSetPrepareSize

    Reported by Neha, reviewed by Amit Kapila and Dilip Kumar

commit c4b6cc166f11fbc22147e4f5567791ac9bbc572e
Author: dilip kumar <[email protected]>
Date:   2018-07-05 17:39:50 +0530

    Handling when a transaction span across undo logs and avoid single
    WAL logged operation to span across multiple log.

    The first part of the patch handle a case, when a single WAL logged
    operation which needs multiple undo records (e.g non-inplace update,
    multi-insert) we avoid it to go in multiple logs.  For that we first
    allocate all the undo required for the operation in one allocate call.

    And the second part handle the discarding and rollback when a transaction
    span across undo logs.

    Path by Dilip Kumar Reviewed by Amit Kapila.

commit 7ed998fd1d369ce8012cd69bed7b020a367c9294
Author: Amit Khandekar <[email protected]>
Date:   2018-07-03 12:14:47 +0530

    Handle changed relfilenode while executing undo actions.

    While an undo worker executes undo actions for a relation, the same
    relation can be truncated. In that case, RelidByRelfilenode() when
    called using the relfilenode saved in the undo record returns invalid
    relation oid. Use this behaviour to figure out that the relation is
    truncated, and abort the undo actions.

    Because this was not handled earlier, the algorithm in
    execute_undo_actions() failed to identify when exactly the undo
    records switch to new pages, and kept on fetching records, without
    releasing them, thus leaving behind those many records and their
    buffers unreleased. This eventually leads to "no unpinned buffers
    available" error in the server log. This was reproducible easily when
    truncate is run immediately after interrupting a long insert, and with
    shared_buffers set to minimum value.

    Amit Khandekar, reviewed by Amit Kapila.
    Reported by Neha Sharma.

commit a96820d722ca0244c8bd9a9749f18e5b2604c45d
Author: Amit Khandekar <[email protected]>
Date:   2018-06-28 09:42:58 +0530

    Prevent usage of uninitialized tuple during tuple routing.

    TransitionCaptureState.tcs_original_insert_tuple is of type HeapTuple,
    and it was assigned a tuple variable which remains unitinitialized in
    case of zheap table. Fix it so that the zheap tuple is converted to
    heap tuple and then assigned to tcs_original_insert_tuple. Fixed this
    in both ExecPrepareTupleRouting() and CopyFrom(). Due to this issue,
    trigger.sql regression test used to crash on some environments.

    Amit Khandekar, reviewed by Kuntal Ghosh.

commit 304dfa7af0547db1f22d72b30b42baa92647b136
Author: dilip kumar <[email protected]>
Date:   2018-06-27 20:49:04 -0700

    Fix compilation warning

commit 89c80035015098c563c104e31406dd23d483fc0f
Author: Kuntal Ghosh <[email protected]>
Date:   2018-06-13 16:49:04 +0530

    Change minimum transaction slots per zheap page to one

    We distinguish a zheap page from a TPD page by comparing the special
    page size. TPD pages always have 1 slot in its special space. Hence,
    we've to set minimum slot as two in zheap pages.

    Tested on Windows by Ashutosh Sharma

commit 1265603a63e90def6a1738f5cca962a13d59e43d
Author: Amit Kapila <[email protected]>
Date:   2018-06-25 08:08:51 +0530

    Free payload data only when it is allocated.

commit 045032bdedff74d583bd54c68a1560f63b7cb967
Author: dilip kumar <[email protected]>
Date:   2018-06-21 06:24:13 -0700

    Isolation test for tpd patch.

    Patch by Rafia Sabih Reviewed by Dilip Kumar

commit 6bbe1f3fde618cf35f64da2726f1100963ba5576
Author: dilip kumar <[email protected]>
Date:   2018-06-21 06:14:12 -0700

    Post TPD commit fix.  After Rereserve the slot,  trans_slot is not
    set back to the new slot.  Ideally we should get the same slot but
    if our slot moved to TPD than it can be old_slo +1.  Also, removed
    the invalid Assert and converted to if condition.

    Patch by Dilip Kumar Reviewed by Amit Kapila

commit 3d3697e196c2f44eceaa07b77d00bc9d90ff0c19
Author: Amit Kapila <[email protected]>
Date:   2018-06-21 16:32:10 +0530

    Support TPD which allows transaction slots to be extended beyond page
    boundary.

    TPD is nothing but temporary data page consisting of extended
    transaction slots from heap pages.  There are two primary reasons for
    having TPD (a) In the heap page, we have fixed number of transaction
    slots which can lead to deadlock, (b) To support cases where a large
    number of transactions acquire SHARE or KEY SHARE locks on a single page.

    The TPD overflow pages will be stored in the zheap itself, interleaved
    with regular pages.  We have a meta page in zheap from which all overflow
    pages are tracked.

    TPD Entry acts like an extension of the transaction slot array in heap
    page.  Tuple headers normally point to the transaction slot responsible
    for the last modification, but since there aren't enough bits available
    to do this in the case where a TPD is used, an offset -> slot mapping is
    stored in the TPD entry itself.  This array can be used to get the slot
    for tuples in heap page, but for undo tuples we can't use it because we
    can't track multiple slots that have updated the same tuple.  So for
    undo records, we record the TPD transaction slot number along with the undo
    record.

    This commit provides basic support of TPD entries where a fixed number
    of entries per page can be allocated in extended pages.  There is more
    to do in order to complete the support of TPD.  The remaining work
    consisits of
    1. Reuse transaction slots in TPD entry.
    2. Allocate bigger TPD entries once the initially configured slots or
    offsets are exhausted.
    3. TPD page pruning and once the page is clean, we can add it to the
    FSM.
    4. Find the free TPD page from FSM.
    5. Chain of TPD entries when the single TPD entry can't fit on a page.

    Amit Kapila with the help of Dilip Kumar and Rafia Sabih

commit 15536e74ed38ba970f30684850ad013d2174d6e8
Author: Mithun CY <[email protected]>
Date:   2018-06-20 04:31:51 -0700

    Move Assert to right place.

    By Mithun C Y review By Dilip Kumar

commit 9724bc889e4a99309e74912c739416c4345cd5d1
Author: Mithun CY <[email protected]>
Date:   2018-06-19 22:24:35 -0700

    Release restriction on page compactification.

    Previously a30d278e8d we did not allow compactification of page
    if it ever have deleted uncommitted tuple in it. This is not
    necessary and hence removing same.

    By Mithun C Y, review by Amit Kapila.

commit a07a3976029c6322cc3e3f954eae0cd606e776b2
Author: Mithun CY <[email protected]>
Date:   2018-06-18 05:29:17 -0700

    Fix bugs related to concurrency in zheap update

    While updating the tuple we might need to release the buffer lock and
    reaquire same. During that period where we do not hold buffer lock
    a concurrent process might have moved the tuple to undo and/or pruned
    the page. So whenever we reacquire the buffer lock check if
    itemid is deleted and readjust the position of tuple in page buffer.

    Patch by Mithun C Y and Amit Kapila.

commit 2448790b692e8f6581cce59b4d08abc977dbd20b
Author: Kuntal Ghosh <[email protected]>
Date:   2018-06-12 11:13:34 +0530

    In PrepareUndoInsert, don't call SubTransGetTopmostTransaction

    In PrepareUndoInsert, we always send the top transaction id. Hence,
    there is no need to fetch the parent xid for a transaction.

commit 4abb8ba5305ef04f7164be58f4c0c94b11ab793c
Author: dilip kumar <[email protected]>
Date:   2018-06-14 05:00:13 -0700

    LogUndoMetaData was called inside XLogBeginInsert, And,
    LogUndoMetaData iteself call XLogBeginInsert for inserting the
    meta WAL.

    Patch by Dilip Kumar

commit 7c44b88155a14186ca91ca010cf84d5f7be5fd93
Author: dilip kumar <[email protected]>
Date:   2018-06-14 04:54:20 -0700

    Conditions for rollback request push to worker was not consistant
    it should only be pushed for the top transaction.  Also, when there
    is an error in top transaction, then we will not have xid for the
    top transaction. So we have removed the xid based key for rollback
    hashtable.

    Path by Rafia Sabih Review by Amit Kapila tested by me.

commit 2797c4bc90ad986804b698a4eaa39991ffcf2094
Author: Amit Kapila <[email protected]>
Date:   2018-06-14 15:37:44 +0530

    Implement stats for in-place updates

    Reuse the existing hot-update stat variable for in-place updates
    instead of introducing a new variable as that will increase the size
    of stats structure.  It appears ugly to overload the unrelated
    variable, but it is better to discuss in community before introducing
    a new variable.

    Beena Emerson, reviewed by Mithun C Y and me

commit 0b8ef5ea24a55c23d54821fa4bc3667319e84801
Author: Kuntal Ghosh <[email protected]>
Date:   2018-06-08 17:12:59 +0530

    Use high 4-bits of xl_info to store undoaction WAL operation type

commit 80e9fe40e186dac8ffbd4b9bf2479cb1fca4f770
Author: ashu <[email protected]>
Date:   2018-06-11 13:04:33 +0530

    Pass '/c:' option with findstr command on Windows.

    Commit 3e9f07a8fe22 uses findstr command to remove the lines having
    "Options: storage_engine='zheap'" pattern from the results/*.out
    files on Windows platform but, it doesn't pass the correct option to
    findstr to ensure that only the lines having the given pattern gets
    removed form the results/*.out file.

    Ashutosh Sharma, Reported by Amit Kapila.

commit a600e4e055877dbb9071f40f215a8f8bb8662d79
Author: Rafia Sabih <[email protected]>
Date:   2018-06-08 17:00:07 +0530

    Buffer leak fix in zheap_insert

commit 303634f18969c53dc31b6668668232f327d7bed6
Author: dilip kumar <[email protected]>
Date:   2018-06-07 23:08:42 -0700

    During rollback we rewind the insert location, Now if the insert
    location is used by some other transaction then its updating its
    own next pointer with its own insert location resulting in cycle
    and due to that undo worker is stuck in this cycle.

    Patch by Dilip Kumar Review by Amit Kapila and Kuntal Ghosh

commit 6fe4dfdda5db82e0e24eeaefa4cdc63a3277be49
Author: dilip kumar <[email protected]>
Date:   2018-06-07 23:06:34 -0700

    ZHeapPageGetCid currently comparing with RecentGlobalXmin to
    identify the old undo, ideally it should compare with oldest
    xid having undo. Due to this it fetching many extra undo hence
    the performance of is low.

    Fix by Dilip Kumar review by Amit Kapila

commit 363c7aa95eeb35f57908ed7c777817cfa38a0f1d
Author: Kuntal Ghosh <[email protected]>
Date:   2018-06-04 22:09:13 +0530

    While performing undo, ignore out of range block numbers

    If a table is truncated just berfore performing undo actions on the same,
    it's possible to encounter out of range block numbers. In that case,
    we can safely ignore those block since we don't have to perform rollback
    on the same.

commit 7cd5b08da9380552376a69456ca11c6f97ce1a1c
Author: ashu <[email protected]>
Date:   2018-06-07 17:32:52 +0530

    Store the information about lockmode in undorecord and initialize
    the flags variable in xl_zheap_lock to zero.

    Commit 0763c68645e9 introduced the support for different tuple
    locking modes and added the necessary changes in
    zheap_lock_tuple_guts() to store lockmode information in undo record
    but, missed to do the similar changes in zheap_update() due to which
    the undo record pointers for non-inplace updates were not the same in
    master and standby nodes thereby, resulting in an assertion failure.

    Additionally, commit f45251a37fe2 introduced flags variable in
    xl_zheap_lock to store transaction slot related information and did
    the necessary changes for it in zheap_lock_tuple_guts() but, missed
    to do the same in zheap_update().

    Ashutosh Sharma, reported by Neha Sharma, reviewed by Dilip Kumar.

commit 643bf383e77acb5eca372380267d01ed01d3a545
Author: Mithun CY <[email protected]>
Date:   2018-05-31 03:17:44 -0700

    Correct style issues in macro definition.

    By Mithun C Y comments by Robert Haas.

commit aaf09cb0491869b5d6e84e4cc68cfe28418ef6ad
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-30 15:37:24 +0530

    In zheap insert option, HEAP_INSERT_FROZEN should be used

    In zheap_insert/multi_insert, we can use HEAP_INSERT_FROZEN flag
    similar to heap to indicate the inserted tuple should be frozen
    after insertion.

commit 409cf3957bee5894cacc603670587476171277fe
Author: dilip kumar <[email protected]>
Date:   2018-05-30 01:42:43 -0700

    Applying pending undo action before modifying the page.

    Currently, if a transaction wants to update a tuple and we
    find that the other modifier is aborted and undo actions is
    not yet applied we simply modify the page, which will create
    an unpredictable behaviour as the execute undo action may
    rollback the changes made by our transaction.
    This commit first apply the pending undo action only for that
    page and then perform the changes.

    Patch by Dilip Kumar and Amit Kapila Reviewed by Amit Kapila
    Tested by Kuntal Ghosh

commit 736ff4cb26355992800792dc64954e55694a82fb
Author: dilip kumar <[email protected]>
Date:   2018-05-30 01:41:06 -0700

    Bugfix in condition check while applying the undo action.

    Earlier it was not collect when two undo pointer was in different logs.

    Patch by Dilip Kumar Reviewed By Amit Kapila

commit c708efefa812ffe54d94841b3c54c906b263a3da
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-30 12:00:01 +0530

    In zheap_update, don't propagate lockers when no lockers are present

    When no lockers are present, we should not propagate any locker
    related information to the newly inserted tuple.

    Patch by Dilip Kumar, reviewed by Amit Kapila and me.

commit 640c67490b76c096405fe38253ae222439707ba5
Author: ashu <[email protected]>
Date:   2018-05-25 13:20:53 +0530

    Correct the insert and discard pointer of the undo log segment file
    when resetting the undo logs.

    Report by Neha Sharma, Initial Analysis by Ashutosh Sharma, Patch
    by Thomas Munro.

commit dc28828a8aa5a54fd8a5aced67c4a69cad84faf7
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-24 14:39:34 +0530

    Allow DML commands that create zheap tables to use parallel query

    This commit applies the required changes for zheap corrsponding to
    the commit e9baa5e9fa147e00a2466.

    Reviewed by Amit Kapila

commit be186ca7f02be4c8d88632bc9fff37d2a7680267
Author: Thomas Munro <[email protected]>
Date:   2018-05-25 15:30:31 +1200

    Fix corruption of oldest_data.

    After commit 9ebe7511 it could be left pointing to space before log->discard,
    and we'd later try to read from there and possibly see a bunch of zeroes.

    Thomas Munro, RM43553, reviewed by Rafia Sabih

commit ba2406238eb93e400ac223a3d8e78097984072c6
Author: Amit Kapila <[email protected]>
Date:   2018-05-25 08:31:46 +0530

    Fix the freespace recording by vacuum

    The freespace was not being updated till we have some deleted/dead
    tuples in the page.

    Report and initial analysis by Ashutosh Sharma, patch by me

commit ab0049c4bb174c332052b187ce60b3f01466bb18
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-24 11:11:40 +0530

    Revert last commit 853849138bf05bcac85

    We're already releasing the lock in function IsPrevTxnUndoDiscarded.
    Although, we could've released the lock in the same function where
    it was taken, but let it be as it is for now.

commit d7e1b3f1c30456b25fbbaa22ffa6bb9791f60a6e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-23 16:38:33 +0530

    In PrepareUndoRecordUpdateTransInfo, release discard lock before leaving page

commit e329d580a973fcb41dc37b6283fc0db67e8262f3
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-21 12:28:12 +0530

    In execute_undo_actions, release undo records before exiting

    When undo record is discarded, we return from execute_undo_actions
    immediately. But, we should release the undo records and corresponding
    undo buffers collected earlier in the same function for rollback purpose.

commit 9dcdb6468df34f45b2975e5c4cac69a05ed27ac2
Author: Mithun CY <[email protected]>
Date:   2018-05-22 23:14:02 -0700

    Revert the restriction on page pruning.

    Revert code which disallowed pruning if there exist any open
    transaction on the page.

    Patch By Mithun C Y

commit 7023615ca40a2041e79863f56c2c1fa6b7c58cda
Author: Amit Khandekar <[email protected]>
Date:   2018-05-23 09:42:55 +0530

    Pass nobuflock=false to ZHeapTupleGetTransInfo().

    In zheap_get_latest_tid(), ZHeapTupleGetTransInfo() was called with
    nobuflock=true, which is wrong because the buffer is already locked.

    Discovered by Kuntal Ghosh, patch by Amit Khandekar.

commit ad0dd279a096e5f9763f44799dfc78c18c4bbd26
Author: Amit Khandekar <[email protected]>
Date:   2018-05-23 09:12:09 +0530

    Avoid using tuple freed by a visibility function.

    In zheap_get_latest_tid(), the tuple that is passed to
    ZHeapTupleSatisfiesVisibility() was being used subsequently, ignoring
    the fact that the visibility function frees the passed-in tuple.

    Rather than the passed-in tuple, use the tuple returned by the
    visibility function in the subsequent code. While at it, make sure
    that the returned tuple is also freed if it is different than the
    passed-in tuple.

    Discovered by Neha Sharma while testing TidScan implementation for
    zheap.

    Amit Khandekar, reviewed by Kuntal Ghosh.

commit e47016cdfba942a07cc3c9fb98d698e22251cb77
Author: Amit Khandekar <[email protected]>
Date:   2018-05-22 09:38:16 +0530

    Fix an issue with copying overlapping memory areas.

    For adjusting zheap tuple location, the tuple header was getting
    corrupted because memcpy() was used to copy, and the old and new tuple
    header areas may sometimes overlap, which memcpy does not handle. This
    was discovered when trigger.sql regression test used to crash on some
    environments.

    So use memmove() instead of memcpy(). memmove() is meant to handle
    this scenario of overlapping areas by first copying the data from
    source location into a temporary location.

    Amit Khandekar, reviewed by Dilip Kumar.

commit ec2d2d7b51bd843b88c2668d548fb90da60fcc67
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-17 10:33:47 +0530

    Fetch correct cid for undo tuples

    In ZHeapTupleGetCid, we should fetch the correct cid from undo.

    Patch by me, reviewed by Amit Kapila

commit ef42a733e045b5624308ce37f4d745b0b9e7d221
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-21 13:09:17 +0530

    Fix compiler warnings

commit 804476bd9929532a83fd0b30ddacfa00b68c5028
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 14:38:34 +1200

    Add a smgrsync() implementation for undofile.c.

    Teach the checkpointer to go through an sgmr API call to mark a (RelFileNode,
    forknum, segment) as in need of flushing to disk at the next call to
    smgrsync().  Previously it called RememberFsyncRequest() in md.c directly,
    but undofile.c needs to be able to participate in this scheme too.  So, add a
    new function smgrrequestsync(), and have it forward to mdrequestsync() or
    undofile_requestsync() as appropriate.

    For now, there is a LOG message when undo segment files are fsync'd, like the
    existing create/recycle/unlink messages.  These will be removed in future.

    This contains a small amount of code that is copied from md.c, but the fsync
    queue machinery is being redesigned so this can be rebased later to use a
    common fsync queue.  See commitfest entry 18/1639 (work independent of zheap).

    Thomas Munro, RM43460, reviewed by Amit Kapila

commit 74c0db38b6469fd92bfca32b41ecbadafd99ed40
Author: Thomas Munro <[email protected]>
Date:   2018-05-15 01:22:41 +1200

    Free up undo log DSM segments and trim pg_undo file size.

    To prevent the pg_undo file from getting gradually larger and the number of
    undo log DSM segments from gradually increasing in a long running system,
    update the lowest non-discarded undo log number at each checkpoint so that we
    can free up resources.

    In passing, change UNDO_LOG_STATUS_DROPPED to UNDO_LOG_STATUS_DISCARDED, a
    name that better describes the state.

    Thomas Munro, RM43532, reviewed by Amit Kapila

commit 9b18132fe9ad889e0aaecb2d2019e3bcf9433018
Author: Thomas Munro <[email protected]>
Date:   2018-04-24 16:45:58 +1200

    Recycle memory used in recovery for the xid->undo log map.

    At each checkpoint, free up memory used to hold information about which
    undo log old xids are attached to.  Also rename associated variables and
    functions to make things clearer.

    Thomas Munro, RM43532, reviewed by Amit Kapila

commit 8cb810f82a694d794429f0b8e28328baf6334bc5
Author: Rafia Sabih <[email protected]>
Date:   2018-05-17 15:06:51 +0530

    Bug fix in discard mechanism

    When undo actions were applied by backend and the undo record pointer
    is rewound, discard the corresponding undo logs and skip performing
    undo actions.

    Reported by Neha Sharma, reviewed by Dilip Kumar and Amit Kapila

commit 56762bc994dfa14e79c29f13231bd0f6e99e0782
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-15 17:16:55 +0530

    Fix compiler warnings

commit e40d26a76fb67a3b2f1cf144a2e76c8301be6a4b
Author: Thomas Munro <[email protected]>
Date:   2018-05-15 05:12:47 +1200

    Improve smgr.c and undofile.c modularity.

    Add a void pointer called "private_data" to SmgrRelationData where undofile.c
    can put its state, instead of the previous horrible hack where it was using
    relm->md_seg_fds.  md.c should really use the new member too, but that'll be a
    patch for another day.

    Thomas Munro

commit bc419ace343682505687cbb39f402d4e90cf228a
Author: Thomas Munro <[email protected]>
Date:   2018-05-15 17:04:31 +1200

    Remove obsolete comment from undolog.c.

commit 62e17972070c1b994f2ae63abe07f951f59bdbc3
Author: Thomas Munro <[email protected]>
Date:   2018-05-15 13:40:29 +1200

    Update copyright date to 2018.

    For all undolog-related files.

commit b591268e289fba15aeb9f1160d7c164e241c6a11
Author: Thomas Munro <[email protected]>
Date:   2018-05-09 18:44:56 +1200

    Add some user-facing documentation about undo logs.

    This commit documents the pg_stat_undo_logs view and the layout of files on
    disk.  More wordsmithing will be needed.

    Thomas Munro

commit 350dadc12b77a4efccafbb5f11663c07370bfd01
Author: Thomas Munro <[email protected]>
Date:   2018-05-09 19:16:24 +1200

    Undo log README tweaks.

    Author: Thomas Munro

commit 22560511be9b6d49034573736feb0c7a830e1a3a
Author: Thomas Munro <[email protected]>
Date:   2018-04-16 16:15:54 +1200

    Skip unnecessary reads of newly allocated undo log pages.

    Whenever we're inserting new undo data that happens to fall at the start of a
    page, we know that there can be no pre-existing data on the page.  Therefore
    we can ask bufmgr.c to zero it out instead of reading it from the storage
    manager.

    To facilitate this, create a new BufferReadMode RBM_ZERO, just like
    RBM_ZERO_AND_LOCK except without the content lock.  undorecord.c expects to
    acquire the content lock a bit later.  Since each backend has sole write
    access to write to the undo log, it's not necessary for bufmgr.c to acquire
    the lock for us.

    Thomas Munro, RM43486, reviewed by Amit Kapila

commit b88edc54636b2649101106ad08b95c16fbfc1d7f
Author: Mithun CY <[email protected]>
Date:   2018-05-14 21:46:38 -0700

    Move previous transaction's undo updation inside critical section

    Update the previous transaction's undo record inside
    InsertPreparedUndo after we have actually inserted the undo record.

    Patch by Mithun C Y Review by Dilip Kumar.

commit 87075c70ffaeea5c570340df7aa144823d94a510
Author: Mithun CY <[email protected]>
Date:   2018-05-14 21:35:47 -0700

    Get deleted rows from zheap_fetch.

    In zheap_fetch if ItemId is set as deleted we need to
    fetch the old version of rows from undo.

    Patch by Mithun C Y Review by Kuntal Ghosh

commit 229aaef467f263bf779cab93c2bf05011a03f335
Author: Amit Khandekar <[email protected]>
Date:   2018-05-14 18:18:30 +0530

    Fix an issue in parallel btree index build.

    Commit 9da0cc35284b added support for parallel btree index build.
    While imitating those changes for zheap in IndexBuildZHeapRangeScan()
    with commit a33e61f999f03, some changes got missed, due to which
    an already-unregistered snapshot is tried to be freed again.
    Added the missing changes.

    Reviewed by Mithun Cy and Amit Kapila.

commit 43d9001c390852fae721b9351a8404f3e063b0d5
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-07 16:10:29 +0530

    During ROLLBACK, set frozen/invalid xact flag correctly

    Reviewed by Amit Kapila

commit e18393d52f04e6c5ade7529581b521d2f7387bdf
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-14 12:05:48 +0530

    In UndoLogAllocate, set is_first_rec to false by default

commit db7d7ee6110a47b420d2be2dc88381e39a099f9c
Author: Amit Kapila <[email protected]>
Date:   2018-05-13 09:29:14 +0530

    Update README.md to reflect the current status of zheap.

commit 19235c3d03f0505f91b5056871c79a70e79430c4
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-08 12:26:35 +0530

    Add new expected .out files for zheap to compensate the failures
    only happening due to inplace updates.

commit 4396609900c4bd5efdd7ecebc8d3966411304786
Author: Rafia Sabih <[email protected]>
Date:   2018-05-08 11:41:45 +0530

    Fetch the tuple from undo for aborted transactions when checking
    the visibility for dirty snapshot

    Reviewed by Kuntal Ghosh

commit 27814264865d23ab8cfae46cdbe9202117ae7c6c
Author: Rafia Sabih <[email protected]>
Date:   2018-05-07 13:18:29 +0530

    Thinko fixed for execute_undo_actions caller

commit d8a3a11957e1e4647da0782308ca89b5ac931b1b
Author: Rafia Sabih <[email protected]>
Date:   2018-05-07 13:11:26 +0530

    Fixed a thinko in RollbackFromHT

    Reported by Dilip Kumar

commit 35a9231220d0866847cd7bd3729c5d231b10e3b5
Author: Thomas Munro <[email protected]>
Date:   2018-05-04 15:45:25 +1200

    Document the undo log IO wait events.

    Add the new undo log wait events to monitoring.sgml.

    Thomas Munro

commit 7dc8a6862586586b48eadfe708044e679f86f153
Author: Thomas Munro <[email protected]>
Date:   2018-05-04 15:06:23 +1200

    Report read/write/sync wait events for undo checkpoints.

    Like other file IO, let's make these show up in pg_stat_activity.

    Thomas Munro, RM43509, based on feedback from Amit Kapila

commit ff7193ad4d4472014344e0983ce90adce9be3229
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 23:19:49 +1200

    CRC verification for pg_undo checkpoint files.

    Add CRC32C checksums to the per-checkpoint files stored under pg_undo.

    Thomas Munro, RM43509, reviewed by Amit Kapila

commit 5ec98770f1e4a1b6fc515447a7d01e1139a8eb27
Author: Thomas Munro <[email protected]>
Date:   2018-05-01 17:48:01 +1200

    Fix compiler error in test_undo.c on Windows.

    Per CI build report.

commit e8ee49180be2391e87a0858d6c2b09eca5fbd716
Author: Amit Kapila <[email protected]>
Date:   2018-05-03 18:55:15 +0530

    Avoid calling PageGetUNDO

    We need to avoid calling PageGetUndo as it re-access the transaction
    slots the second time.  We can already get it via PageReserveTransactionSlot.
    This is okay till now, but with TPD, we need to again access the TPD page
    which will be costly.

    Patch by me, reviewed and edited by Dilip Kumar

commit 83986b54c2b6445517502d1750f5523ed2690bba
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-03 14:23:22 +0530

    Small fix in CopyTupleFromUndoRecord

    We should free the memory for zheap tuple only after allocating memory
    for the copied undo tuple.

commit c8ce97a9d55c0c3a3f537a389513ce10de1b6c0e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-03 11:51:11 +0530

    Remove unnecessary undo type from CopyTupleFromUndoRecord

    Reported and reviewed by Amit Kapila

commit a2a88babb3e190f526cdb3fae496c41fc9c1d2f2
Author: Amit Kapila <[email protected]>
Date:   2018-05-03 12:45:30 +0530

    Fix WAL replay of XLOG_ZHEAP_UNUSED

    We forgot to call PageSetUNDO during wal replay of XLOG_ZHEAP_UNUSED.

    Patch by me, verified by Mithun C Y

commit 9b1f493a6335d0702479bc56506dc34287b46b35
Author: Amit Kapila <[email protected]>
Date:   2018-05-02 16:54:50 +0530

    WAL replay for lock tuple was not using correct transaction slot to
    update the transaction information

    This commit fixes the issue by logging and using the correct
    transaction slot during replay of lock tuple.

    Patch by me, reviewed by Dilip Kumar

commit 6a74940a505bd5e302cc9ac7b3adbb3625c560a8
Author: dilip kumar <[email protected]>
Date:   2018-05-01 23:19:24 -0700

    Bug fix in undo record start header update during recovery

    Patch by Dilip Kumar Reviewed by Rafia Sabih

commit a5c5e1706570f379eb8bf6a12a9226af60912016
Author: Kuntal Ghosh <[email protected]>
Date:   2018-05-02 13:42:36 +0530

    Handle non-exixtent/empty files in pg_regress

    Commit 3e9f07a8fe222b0e9 excluded storage_engine option from result
    files using grep/findstr command. But, these commands returns
    non-zero values in case of non-existent/empty files. Hence, we've to
    skip the checks for the same.

commit fd4c197eca2a0846d08727361073cbc1f82d7cbf
Author: dilip kumar <[email protected]>
Date:   2018-05-01 22:51:15 -0700

    Fix tuple lock wal replay

    lock mode was not stored in lock tuple WAL and also not stored in undo
    during replay.  This commit fixes the same.

    Patch by Dilip Kumar Reviewed by Amit Kapila

commit 3775d97153d1cd63bc98d561816e9662cd03eb53
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-30 17:14:08 +0530

    Fix copy undo payload

    Reported by Amit Kapila

commit 02a89f973c2be94019d695fb0d917494db319473
Author: dilip kumar <[email protected]>
Date:   2018-05-01 21:45:18 -0700

    Bug fix in update wal replay.

    Patch by Dilip Kumar Reviewed by Amit Kapila

commit c5f63f27f73618b994bd561057d3f4e9c0da15ff
Author: Amit Kapila <[email protected]>
Date:   2018-05-01 12:42:26 +0530

    The check to ensure whether undo is discarded was missing at few
    places.

    This patch fixes two such occurrences.

    Patch by me, reported and reviewed by Rafia Sabih

commit f336c7a16c72e0048f897f85b1e38b24adc8ff8e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-30 11:15:40 +0530

    Add new expected .out files for zheap to compensate the failures
    only happening due to inplace updates.

commit 1a8e463d48e1bbf5ea9abb1e07b1512a097fb963
Author: Rafia Sabih <[email protected]>
Date:   2018-04-30 10:49:06 +0530

    Additional flag in execute_undo_actions for relation lock

    Callers of execute_undo_actions now provide a flag based on if they
    a lock on the relation. If the caller have relation lock already
    then no need to lock again in execute_undo_actions.

    This is required particularly in cases when rollbacking the prepared
    transactions or rollback to savepoints. In such cases the transaction
    have already held the relation locks and we need not take another.

    Reviewed by Dilip Kumar

commit 5f229e04af2f187fc757e8f59ba8c075e56cf46c
Author: dilip kumar <[email protected]>
Date:   2018-04-27 04:21:42 -0700

    While vacuuming a large zheap table, update upper-level FSM data every so often.
    for detail refer commit 851a26e26637aac60d6e974acbadb31748b12f86 of PG.

    Patch by Dilip Kumar Reviewed by Amit kapila

commit 90dbf29c4b815ea3b51c8736f412a67d59d5f4f1
Author: Thomas Munro <[email protected]>
Date:   2018-04-27 21:49:59 +1200

    Log the same undo segment messages in REDO and in DO.

    During DO we currently output LOG messages when undo segment files are
    recycled etc.  Output the same messages in recovery.  All of these
    messages will later be removed, but it's helpful for testing to show
    them for now.

    Thomas Munro

commit 292856c5c73f80f9089441a9079ce76ab17b9764
Author: ashu <[email protected]>
Date:   2018-04-27 12:53:10 +0530

    Add new expected .out files for zheap to compensate the failures
    only happening due to inplace updates.

    Patch by Ashutosh Sharma, suggested by Amit Kapila, reviewed by
    Kuntal Ghosh.

commit 0925b489735ab6ba01c3c57a85175947ec04a373
Author: ashu <[email protected]>
Date:   2018-04-27 12:51:00 +0530

    Allow pg_regress module to exclude storage_engine option printed
    when viewing the definition of zheap table using \d command.
    Additionally, also add a new reloption_1.out file to compensate
    for the diffs generated due to storage_engine option in reltopions
    field of pg_class table.

    Patch by Ashutosh Sharma, reviewed by Kuntal Ghosh.

commit c13e3a64be6fe571f48c1abc8a837c063594ce1d
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-18 18:17:16 +0530

    Implement Foreign Key Constraint for zheap

    For zheap, when we call the triggers we convert a zheap tuple to heap
    tuple. But, we don't store any transaction related information on the
    heap tuple. Hence, I've to make the following two
    assumptions/considerations for the foreign key implementation in
    zheap:

    1. RI_FKey_fk_upd_check_required: In this function, we check if the
    original row was inserted by our own transaction, we must fire the
    trigger whether or not the keys are equal. For zheap, since we don't
    have the transaction related information, we always fire the trigger.
    So, even if the keys are equal, we cannot skip the trigger for zheap.

    2. validateForeignKeyConstraint: During ALTER TABLE..ADD CONSTRAINT
    FOREIGN KEY, this function is called to validate whether we can add
    the foreign key constraint. First, it tries to fire a LEFT JOIN query
    to test the validity. If the user doesn't have proper access rights to
    pktable/fktable, we scan the table in pagescanmode and fire trigger
    for each tuple. Before firing the trigger, it takes buffer lock to
    check whether it can skip the trigger. For zheap, we don't retain the
    pin on the buffer. Hence, we've to read the buffer again before
    locking the same.

    Patch by me, Reviewed and tested by Ashutosh Sharma

commit 4113663bfa26941ef3b5eec9589e70dfe3643e96
Author: ashu <[email protected]>
Date:   2018-04-27 11:34:49 +0530

    Update t_infomask2 field of old tuple correctly during inplace
    updates.

    Patch by Amit Kapila, reviewed by Ashutosh Sharma

commit 06fb3f80e349e0a329606702cd94cd2bdc740946
Author: Mithun CY <[email protected]>
Date:   2018-04-25 23:56:02 -0700

    Mark all_dead if ItemId is already dead.

    By Mithun C Y review by Ashutosh Sharma

commit 60731dbac9433dc640d3412504423e15260b1ed6
Author: Mithun CY <[email protected]>
Date:   2018-04-25 23:52:55 -0700

    Fix rebase issue

    Prototype change of GetOldestXmin was not updated while rebasing to
    postgres main branch. Above patch corrects same.

commit 7e10f40e60dcd2704ba98781ae98d658b3dcbb5a
Author: Thomas Munro <[email protected]>
Date:   2018-04-25 15:07:34 +1200

    Track undo logs' is_first_rec correctly in recovery.

    Previously we could get confused about whether an undo record is the first
    in a transaction during recovery.  Use XLOG_UNDOLOG_ATTACH to set the flag,
    since that is always emitted before the first zheap WAL record for each
    transaction.

    If a checkpoint happens to come between that and the first zheap operation,
    it doesn't matter because then an XLOG_UNDOLOG_META will be inserted and that
    will restore the is_first_rec flag, assuming it was also tracked correctly
    during DO (that's a separate investigation).

    Thomas Munro, RM43459, reviewed by Dilip Kumar

commit 3a82f2f014ac86b7587bc85f12a5df6fc4bb1514
Author: Thomas Munro <[email protected]>
Date:   2018-04-25 21:10:30 +1200

    Make src/test/modules/test_undo compile.

    After many recent changes it wasn't building.  Repair.  It isn't useful
    for testing at the moment, because if you add test content to undo logs it
    causes the undo worker to crash.  I need to figure out a way to prevent that
    from happening and then convert this into a useful set of tests of undo log
    machinery.  Watch this space.

    Thomas Munro

commit 0bf11c41400b26ec50a2edd4fb70777268993d56
Author: Thomas Munro <[email protected]>
Date:   2018-03-26 09:59:39 +1300

    Change undo log segment size to 1MB.

    The previous size was 4MB.  That size wasn't chosen with much thought, and it
    creates a fairly large disk footprint for systems with many concurrent
    backends.  Let's try the smaller and nice, round number of 1MB and see how
    frequently we finish up doing filesystem operations.  Early testing with
    pgbench on powerful machines seem acceptable, since the undo worker is very
    easily able to recycle segments fast enough so that foreground processes never
    have to create a new one.

    Thomas Munro

commit 5b7fbed0c316ec15cdf8fc566a503e5428946dd7
Author: Thomas Munro <[email protected]>
Date:   2018-03-09 16:18:12 +1300

    Add a README file describing the undo log storage subsystem.

    Add src/backend/access/undo/README, and update src/backend/storage/smgr/README
    to describe the new storage manager.

    Thomas Munro

commit 2b620d2e8b3bc0708106e122d42464f417406071
Author: Thomas Munro <[email protected]>
Date:   2018-03-20 05:19:45 +1300

    Make temporary undo logs use backend-local buffers.

    For now temporary undo data is not discarded, except at startup when it's all
    discarded at once.  This will be addressed in later commits.

    Thomas Munro, RM43422

commit 1f176882f95411b5a4fd18740687143fd4cd2c0e
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 14:30:14 +1200

    Basic tablespace and persistence support for undo (take II).

    You can now be attached to a separate undo log for each persistence level
    (permanent, unlogged, temporary).  Undo logs can now be created in tablespaces
    other than pg_default by setting the new GUC "undo_tablespaces".

    Temporary undo logs are not yet backend-local; a separate commit will add
    that.  A separate commit will also fix some details of crash recovery.

    Thomas Munro, RM43422, reviewed by Rafia Sabih, Dilip Kumar, Amit Kapila

commit 25eb200b1aa3d05cb1d8365946fc03c3ca1c96fc
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 13:01:51 +1200

    Introduce XLOG_UNDOLOG_META WAL records.

    During checkpoints, undo log meta-data is captured at an arbitrary time after
    the redo point is chosen.  In the case of an online checkpoint, this means
    that we might capture incorrect meta-data.  Correct that by inserting an
    XLOG_UNDOLOG_META record before the first WAL record that writes to each undo
    log after a checkpoint.

    Dilip Kumar, RM43459, reviewed by Thomas Munro

commit 47c7e3b5199d561953f693e18c2f85dae7b56264
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 12:32:00 +1200

    Remove code for consistent pg_undo checkpoint files.

    Instead of trying to make pg_undo files consistent, we have decided to allow
    them to contain data from any arbitrary time after the redo point.  A
    follow-up commit will introduce new WAL records that will be emitted to
    correct them.

    This is not a complete revert of commit d8a02edf as there were some
    refactorings and small fixes that seem worth keeping.

    Thomas Munro, RM43459

commit b43da384a36b13679f5f0ec12aa72e218656d0d1
Author: dilip kumar <[email protected]>
Date:   2018-04-24 07:09:41 -0700

    Fix the assert.  In recovery we can not ensure that we are attached
    to the undo log from which we are allocating.

commit f306a1c5c10e63eb38c790be504e154413372a90
Author: Mithun CY <[email protected]>
Date:   2018-04-24 06:35:27 -0700

    Force page init on Insert rollback

    In zheap_xlog_insert we see insert of first and only tuple on the
    page we re-initialize the page. Force page init on insert or multi
    insert rollabck so wal consistency check of page on standby still
    satisfy. This overrides previous commit 15179e57b124

    Patch by me and review by Kuntal Ghosh.

commit ffc5ea7e8577d3cce4b5e44fda55a4f7df6bed75
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-13 14:13:44 +0530

    Fix ZHeapPageGetCtid for deleted tuples

commit d8107861935ad0e202aeb14ad116722af5d22af5
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-24 18:26:23 +0530

    Handle deleted item pointers for no-key-exclusive mode

    Reported by Amit Kapila

commit 156e25415049a1d9a940bf709abc5fd5f550ee7e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-20 15:15:59 +0530

    Fix assert in zheap lock,update and delete tuple

    For deleted item id, we don't retrieve the tuple. Hence, we should
    check for the same.

commit af6f63e740cd904f234475bf530a9290b982b38b
Author: dilip kumar <[email protected]>
Date:   2018-04-24 03:35:42 -0700

    make zheap changes in slot_getsysattr function.  This function is
    now called by execCurrentOf.

commit 8b6041f28b8e2554da439da7701500bb2af2c712
Author: Thomas Munro <[email protected]>
Date:   2018-04-23 11:11:57 +1200

    Fix warnings in non-assertion build.

    Clang complained about uninitialized variables when there was no assertion.

commit 2b96b1be41fad5aa00e8d8b8db63aada925f7581
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-20 19:17:48 +0530

    Fix a bug in ALTER DOMAIN .. ADD CONSTRAINT

    The previous commit doesn't use beginscan correctly for heap/zheap
    relation.

commit 7cb019bbcec083052f8436f4489fe6e2957b223a
Author: Beena Emerson <[email protected]>
Date:   2018-04-20 16:11:19 +0530

    Correct the behaviour of ALTER DOMAIN .. ADD CONSTRAINT in zheap

    Add zheap support in functions validateDomainConstraint and
    AlterDomainNotNull which will check if any tuple violates the
    newly added constraint.

    Reviewed by Kuntal Ghosh

commit dbcfe95943c7f5ddd5fbcb3b84daa62a32c3abf9
Author: Beena Emerson <[email protected]>
Date:   2018-04-20 14:22:16 +0530

    Allow foreign tables to be added as partitions of zheap table

    Since foreign tables do not support the storage_engine option, exempt
    them from the checks where we check if the partitions have the same
    storage_engine option as their ancestors.

commit 439869f9fc77a8e6121a74fc433eef7d822951b8
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-20 00:38:59 +0530

    Add isolation expected file of vacuum-reltuples test for zheap

    In zheap, we don't have to take cleanup lock for vaccuming the
    relation. Hence, the vacuum command won't skip the buffer even
    when another backend holds a pin on the same.

commit d50ed5e003d5104171540e3bcb45335bc941cd4a
Author: Mithun CY <[email protected]>
Date:   2018-04-18 13:00:28 -0700

    Force Refragmentation on Insert rollback

    In zheap_xlog_insert we see insert of first and only tuple on the
    page we re-initialize the page. Force pruning on insert or multi
    insert so wal consistency check of page on standby still satisfy.

    Patch by me and review ny Kuntal Ghosh.

commit 240b960b6cf36a5611aa13b7f67e6cebedd15b63
Author: Rafia Sabih <[email protected]>
Date:   2018-04-18 14:26:43 +0530

    Introducing a queue for passing rollback requests to undo worker

    To increase the efficiency of rollback mechanism in zheap,
    we now have a rollback queue. Now, any rollback request that
    exceeds the threshold -- rollback_overflow_size, is added to
    this queue. Whenever undo worker is idle it checks if rollback
    queue has some entries and executes the required undo actions,
    if any. The rollbacks required for 'rollbacks to savepoint' are
    not added to this queue, rather the backend itself executes the
    required undo actions for them.

    The rollback queue is implemented as a shared hash table.

    Reviewd by Beena Emerson and Amit Kapila

commit fee9b99b1ccf3dca9a822d4e41e6a3a801598eb1
Author: Mithun CY <[email protected]>
Date:   2018-04-17 03:37:04 -0700

    Block VACUUM FULL on zheap table, which got unblocked by commit
    0d27be592d82a44158d

    Reported by Thomas Munro and Kuntal Ghosh.

commit 49743ef26167946e60292aa3251b6bbdfdacd015
Author: Thomas Munro <[email protected]>
Date:   2018-04-16 17:26:56 +1200

    Fix uninitialized variable.

    Per compiler warning from clang.

commit 31cd2baf750596b961c9838a61078f3c9f3eb70f
Author: Mithun CY <[email protected]>
Date:   2018-04-13 05:12:13 -0700

    Fix for warnings introduced by commit 0d27be592d82a44158d

    Reported by Kuntal Ghosh.

commit 274b0cb5c7ad77da7f4f98db23619a30571f6ac0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-04-12 12:53:26 +0530

    Declare get_old_lock_mode as static inline

    Otherwise clang complains about the inline function declaration.
    Reported by Thomas Munro, reviewed by Amit Kapila

commit ee296fd6b96d8294dba9437f30353797e756d6da
Author: Amit Kapila <[email protected]>
Date:   2018-04-12 10:07:15 +0530

    Two pass vacuum

    We need vacuum in zheap for non-delete marked indexes, however, we can
    use undo to reduce three-pass to two-pass vacuum.  When a row is
    deleted, the vacuum will directly mark the line pointer as unused,
    writing an undo record as it does, and then mark the corresponding
    index entries as dead.  If vacuum fails midway through the undo can
    ensure that changes to the heap page are rolled back.  If the vacuum
    goes on to commit, we don't need to revisit the heap page after index
    cleanup.

    We must be careful about  TID reuse: we will only allow a TID to be
    reused when the transaction that has marked it as unused has
    committed. At that point, we can be assured that all the index
    entries corresponding to dead tuples will be marked as dead.

    Currently, due to lack of visibility map for zheap, we scan all the
    pages during vacuum.  A future patch which will introduce visibility
    map in zheap will remove that limitation.

    Patch by me, Mithun has fixed few bugs and added implementation for
    Rollback action, also he has done basic verification of the patch

commit 4f3a0106661ab1f52be6a4b1c1de37216c710535
Author: Amit Kapila <[email protected]>
Date:   2018-04-11 16:51:11 +0530

    Support different tuple locking modes

    The basic idea is that we maintain each lockers information in undo
    and the strongest lockers information on the tuple. If there is more
    than one locker, then we set multi_locker bit on tuple. Now, if the
    multi_locker bit is set and the new locker conflicts with the
    strongest locker, then we traverse all the undo chains in the page and
    wait for all the conflicting lockers to finish. As we have to wait for
    all the lockers by releasing the lock on the buffer and then reacquire
    the buffer lock after waiting for all the transactions is finished, in
    the meantime, a new locker (say key share) can take a lock on the
    tuple and we won't be able to detect it unless we do something
    special.  Now, one might think that as before waiting for multiple
    lockers we have acquired a heavyweight lock on tuple by using
    heap_acquire_tuplock, no other transaction can acquire xid-based lock
    (something like key share), but that is not true, as that is allowed for
    both heap as well as for zheap (till now).

    Now, the heap can detect such a case because it always creates a new
    multixact whenever a new locker is added to the existing set of
    lockers and it puts the newly create multixact id in xmax of tuple, so
    in above case after reacquiring the buffer lock we can just check if
    the xmax has changed and if so, then we redo the *TupleSatisfies check
    and again wait for new lockers.

    For zheap, after reacquiring the buffer lock, check again if there is
    any new locker on the tuple and to find this we need to again traverse
    the undo chains. Although this doesn't sound the best design, it is
    not clear whether it can really create the problem. If we want we can
    optimize by checking whether LSN of the page is changed, then only go
    for chasing all the undo chains, sure that won't work for unlogged
    tables, but still it is a good optimization. Another thing is that
    this approach is quite simple, so we inclined to go with this
    approach.

    We clear the multi_locker bit lazily like when we are already
    traversing all the undo chains to verify if there is any new locker on
    the tuple after taking the buffer lock.

    The visibility routines don't need any special handling as we are
    already storing the strongest locker information on a tuple which can
    help us get the transaction information of updater which is what is
    required to check visibility of tuple.

    Patch by me with help from Kuntal Ghosh and Dilip Kumar, reviewed and
    tested by Kuntal Ghosh

commit 5bf3a603cd575ec188e42b1e0b7b0978f0fc54ed
Author: Amit Kapila <[email protected]>
Date:   2018-04-11 16:12:12 +0530

    Retrieve the transaction slot of modified tuple

    This is required for the upcoming tuple locking patch.

    Patch by me, reviewed by Dilip Kumar

commit f2922167ffb0134854ca1fceea7b80d1a657cc23
Author: Amit Kapila <[email protected]>
Date:   2018-04-05 11:03:14 +0530

    Fix the incorrect update of infomask for inplace updates

    Ensure to copy everything from new tuple in infomask apart from
    visibility flags.

    Patch by me, reported by Kuntal and reviewed by Ashutosh Sharma

commit 1dc99668b499b30a6fb7146e7c6156178143ced7
Author: dilip kumar <[email protected]>
Date:   2018-04-04 00:30:38 -0700

    If full_page_writes is enabled, and the buffer image is not included in
    the WAL then we can rely on the tuple in the page to regenerate the undo
    tuple during recovery as the tuple state must be same as now, otherwise,
    we need to store it explicitly. But, in current code it is not stored
    externally even if the page image in included in the WAL.

    Introduced new API XLogInsertExtended. Unlike XLogInsert, this function will
    not retry for WAL insert if the page image inclusion decision got changed
    instead it will return immediately. Also, it will not calculate the latest
    value of the RedoRecPtr like XLogInsert does, instead it will take as input
    from caller so that if the caller has decided to not to include the tuple
    info (because page image is not present in the WAL) it can start over again
    (if including page image decision got changed during WAL insertion). And
    for the zheap wherever we need to include tuple info for generating the undo
    record, we will call this new function instead of XLogInsert.

    Patch by Dilip Kumar. Review and modified by Ashutosh Sharma and Amit Kapila

commit 9b3f81dd68751cd8fc61a588e07c0299c52b1e7b
Author: dilip kumar <[email protected]>
Date:   2018-04-03 01:44:20 -0700

    Remove undo for INVALID_XACT_SLOT

    Previously we needed this undo to identify the exact xid which
    was there in the slot before reusing it.  And, that was stored
    as uur_prevxid of the undo record.  Now, we are already including
    uur_xid (transaction id which has inserted undo record) so we can
    find the actual slot xid just by traversing the undo chain.

    This will reduce the complexity of the code.  And, this will also
    remove the limitation that one transaction is writing the undo in
    other slots. So, by removing this limitation we can rewind the insert
    location during rollback from the backend.

    Patch by Dilip Kumar Review and Defect fixes by Amit Kapila

commit a354f4e7ad32176b57a47251fb8ac2366d0bff3c
Author: ashu <[email protected]>
Date:   2018-04-03 13:44:33 +0530

    Include undolog.h in undorecord.h to fix compilation error on MSVC.

    Ashutosh Sharma

commit 44f5d0336add411302e9de94329ac7cc8808508c
Author: Thomas Munro <[email protected]>
Date:   2018-03-20 00:26:36 +1300

    Fix uur_next corruption by replacing global variables with UndoLogControl.

    Previously we could corrupt our uur_next chain when the undo log you're
    attached to changes.  This broke some later commits.

    Get last_xact_start and prevlen in UndoLogControl instead of maintaining a
    local copy.  They can be read directly from shmem without locking (but not
    written) by the backend that is currently attached.

    prev_txid remains as a global variable, and it needs to be cleared whenever
    the undo log changes.  Perhaps it could be stored in UndoLogControl too, but
    that leads to some circularities.

    Thomas Munro, RM43421, reviewed by Rafia Sabih

commit a0536401ad8f228ea7bffa08ccbb9f69d62fb4d1
Author: Thomas Munro <[email protected]>
Date:   2018-03-12 15:29:05 +1300

    Remove UndoDiscard and move its state into UndoLogControl.

    Previously, a per-undo log object "UndoDiscard" was used to track the progress
    of the undo worker machinery.  It was in a shared memory array of fixed size,
    which isn't going to work.  Move that state into the UndoLogControl object for
    each undo log.

    Since this change requires undodiscard.c to have direct access to
    UndoLogControl objects and to iterate over them, create new functions
    UndoLogNext(), UndoLogGet() with extern linkage to do that.  A better
    interface is probably needed -- to review later when we work out the type of
    access that multi-process undo worker infrastructure will need.

    Register the LWLock tranches.

    Thomas Munro, RM43420, reviewed by Dilip Kumar and Amit Kapila

commit 709a41dc526b9eecda1d4891f758b3d268af2650
Author: Thomas Munro <[email protected]>
Date:   2018-03-08 16:01:03 +1300

    Move UndoLogControl struct into header to prepare for wider use.

    A later commit will make use of it from other translation units so let's not
    define it in undolog.c.  This requires hiding the definition when included
    from FRONTEND code.  Perhaps this should have a new header of its own or some
    other reorganization, but for now let's just do it conditionally.

    Thomas Munro, RM43420

commit 8b74af923855cd72e1fca40b8822d546fc07a1ab
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-22 11:07:35 +0530

    For calculating latest removable xid, don't use raw xid from page

    This commit also modifies ZHeapTupleGetTransInfo to work with
    deleted item pointers when we've buffer lock on the page.

    Reviewed by Amit Kapila

commit 38345d269e4bb4908b9e48cb3a4a955d2579a0cf
Author: Amit Khandekar <[email protected]>
Date:   2018-03-26 12:23:43 +0530

    Support Tid Scan for tables with zheap storage.

    Use zheap equivalent of heap_fetch() to fetch the next tid.

    To support WHERE CURRENT OF, have a zheap-equivalent of
    heap_get_latest_tid() function. This function in turns uses
    the zheap visibility function. For following the ctid chain
    for non-in-place-updated tuples, have the MVCC visibility function
    pass back the ctid of the new tuple.

    Although zheap_get_latest_tid() accepts a snapshot, it may not work
    with snapshots other than MVCC snapshot, because the corresponding
    visibility functions for those snapshots are not modified to return
    the new tuple ctid. This would be done in later commits, since it is
    not necessary for Tid Scan.

    Furthermore, the callers of heap_get_latest_tid()
    (e.g. currtid_byreloid) should be modified to call
    zheap_get_latest_tid() for zheap tables. This also would be done
    in later commits.

    Patch by Amit Khandekar, reviewed by Amit Kapila and Kuntal Ghosh.

commit ec068b0903c8dc9788b06e0405f6d4c94ba24dcc
Author: dilip kumar <[email protected]>
Date:   2018-03-25 22:14:13 -0700

    Handling the rollback if error in commit path

    During the commit if there is error occure before updating the
    status in the clog then we need to track the undo pointers and
    apply the undo actions.

    Patch by Dilip Kumar review by Amit Khandekar.

commit 37994ff7060acc5317ccfd8c48c2ef440e4a3504
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-23 13:55:50 +0530

    Fix README.md for better readability

commit 698f1fb1bb35f423891c7ae64b4f6f7f1f1f2074
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-21 16:22:49 +0530

    Make transaction slots per zheap page as compile-time parameter

    One can specify the same using --with-trans_slots_per_page=<VALUE> while
    configuring postgres installer. Allowed values are 1,2,4,8,16,31. By default,
    it is assigned to 4 slots per page.
    The changes required for Windows have been done by Ashutosh Sharma.

    Patch by me, reviewed by Amit Kapila and Ashutosh Sharma

commit acbc6636929b21c6df12e4c69964a2c4035652c6
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-23 12:33:34 +0530

    Bugfix in btree and hash delete items

    Sizes of xl_btree_delete and xl_hash_vacuum_one_page were not properly
    calculated.

commit a8bae1f3400d9e98e46268040521f517d556efe9
Author: Rafia Sabih <[email protected]>
Date:   2018-03-23 12:02:35 +0530

    Handling rollbacks in prepared transactions

    Reviewed by Dilip Kumar and Amit Kapila

commit 2fa48d89c290f309fa92b719d1070b5f329f4daa
Author: ashu <[email protected]>
Date:   2018-03-23 10:58:40 +0530

    For speculative insertion, store a dummy speculative token in the
    REDO function (zheap_xlog_insert()) so that, the size of undorecord
    in DO and REDO function matches with each other.

    Ashutosh Sharma, Reported by Neha Sharma.

commit 574f673a1cf6d494b2ef0817962aee93bb0659a1
Author: Rafia Sabih <[email protected]>
Date:   2018-03-22 10:51:23 +0530

    Fix for warnings introduced by commit 70f35f756834028c

    Reported by Amit Kapila

commit 89cb28898369622578be42f7a131c024b7bb5f05
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-19 18:13:52 +0530

    Skip unnecessary palloc for deleted item pointers

    Reviewed by Amit Kapila

commit 4765f6669408f9e13e3cebd1c33a668d718b5b98
Author: Rafia Sabih <[email protected]>
Date:   2018-03-20 16:19:00 +0530

    Bug fixes in rollback

    1. Check for running transactions using top transaction instead of
    current transaction state in XactPerfromUndoActionsIfPending

    2. Insert start undo record if we rewound the previous start undo
    record pointer while rollbacking the subtransaction containing the
    start undo record of the transaction.

    Issues reported by Neha Sharma, reviewed by Dilip Kumar, Amit Kapila

commit 1830381aa7c44d0ba24fb1fc6fc94cab87165705
Author: dilip kumar <[email protected]>
Date:   2018-03-19 23:44:10 -0700

    Removed unwanted function "SetUndoPageLSNs"

commit 6a2b8d3f80829987908005941de9c9583577430e
Author: ashu <[email protected]>
Date:   2018-03-19 16:36:54 +0530

    Place the if-check used to decide whether the last tuple in a page
    can be inplace updated or not outside the check to know if a page
    needs to be pruned, otherwise, even if the tuple to be updated is
    a last tuple in a page, it won't go for inplace updated if the
    page pruning is not required.

    Ashutosh Sharma, Reported by Neha Sharma, Reviewed by Mithun CY.

commit 6953e07fcf5bd914c31beb6adcc756ea34974940
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-16 14:28:39 +0530

    Fix zheap_xlog_multi_insert to release the buffer properly

    In zheap_xlog_multi_insert, we should unlock and release the buffer
    even after restoring the block from backup image.

    Issue reported by Tushar Ahuja

commit 350f34b92fcac83aa9447cb8b7685f1f5e3655e4
Author: Mithun CY <[email protected]>
Date:   2018-03-15 22:09:38 -0700

    Bugfix advance latest RemovedXid only if tuple is dead.

    By Mithun C Y, Review Dilip Kumar

commit e63e2365e1ccc78424032fafa8c3a5a012955c1e
Author: Thomas Munro <[email protected]>
Date:   2018-03-08 11:50:50 +1300

    Fix incorrect worker name displayed if undo launcher/worker dies.

    Previously bgw_type was uninitialized, causing at least some systems to show
    a value that confusingly just happened to be "logical replication launcher" to
    be displayed by the postmaster in error messages.

commit 5541c5927873c34aecbf5bc82b7610fc8b035e94
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-14 14:17:48 +0530

    Fix UndoFetchRecord for fetching UNDO_MULTI_INSERT

    For UNDO_MULTI_INSERT undorecords, we've to check whether our offset
    number falls in the offset range stored in the payload of undorecord.
    We've added a callback function in UndoFetchRecord to check whether
    an undorecord satisfies any blocknumber, offset number and xid.

    Reviewed by Amit Kapila

commit 986cfc9f789e51fa796b2afdb8ee093c740172a3
Author: Mithun CY <[email protected]>
Date:   2018-03-13 22:12:30 -0700

    Bug Fix in CopyTupleFromUndoRecord

    For certain undo record type we will not have tuple data associated
    with them. For Copying such tuple we need an input tuple. Above patch
    Asserts and address those issues.

    Patch By Mithun C Y Review By Amit Kapila

commit 28078c9b70d8d6d7a9af9f5f5789b3a739af0ca9
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-07 16:03:23 +0530

    In zheap_prepare_insert, reset visibility bits in infomask/infomask2

    Dilip Kumar and Kuntal Ghosh, reviewed by Amit Kapila

commit 1cd9b192209084bcea39c8603a1de54e8481e5ee
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-08 14:26:14 +0530

    Enable WAL consistency check for zheap

    We've added zheap_mask function to mask unimportant fields in
    zheap page before consistency check.

    Patch by me, reviewed by Mithun CY

commit d1d0d9de831695f218f6390f0fea742ddce98b46
Author: Rafia Sabih <[email protected]>
Date:   2018-03-07 13:17:25 +0530

    Fix compiler warnings

commit ac3838b9ab274d2e18e7f4ec19b02ece442d043b
Author: Amit Kapila <[email protected]>
Date:   2018-03-06 17:30:13 +0530

    Support Insert .. On Conflict

    The design is similar to current heap such that we use the
    speculative token to detect conflicts.  We store the speculative token
    in undo instead of in the tuple header (CTID) simply because zheap’s
    tuple header doesn’t have CTID. Additionally, we set a bit in tuple
    header to indicate speculative insertion.  ZheapTupleSatisfiesDirty
    routine checks this bit and fetches a speculative token from undo.

    Amit Kapila and Ashutosh Sharma

commit 96eeccc2d9c095fcea050e3c797b9934c9d1cfcc
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-06 12:31:21 +0530

    Fix MinZHeapTupleSize definition

commit 7ba6c3c85e913faa02cb7507093abf648d05a3b2
Author: dilip <[email protected]>
Date:   2018-03-02 01:17:23 -0800

    Commit (db9d0b2988c829b8e0599ebf087a10b98cb9690d) calculated the
    latest_urec_ptr in case of SUB_INPROGRESS but it should have done that
    for SUB_ABORT case.

    Pointed out by Rafia Sabih

commit 89cb2efebb0b039786a1ffde7b48ff16b2ece128
Author: Kuntal Ghosh <[email protected]>
Date:   2018-03-01 13:47:14 +0530

    Bug fix in zheap_xlog_multi_insert

    This fixes a type casting error. It also fixes the condition for changing
    the offset range.

commit 0eb31eb589c1430eecf430a9c04f988b98914d8e
Author: dilip <[email protected]>
Date:   2018-03-01 05:55:22 -0800

    Bugfix in rollback

    Latest_urec_ptr is not calculated before executing undo actions,
    fixed the same.

    Patch by me, Reviewed by Amit Kapila.

commit 8043baef73e74311eb399305e99e12bb8e86f868
Author: akapila16 <[email protected]>
Date:   2018-03-01 17:26:52 +0530

    Create README.md

    This document is to help users understand how to use zheap and open issues.

    Amit Kapila, reviewed by Robert Haas

commit 82320f78eec7eb44584d00728ed84e6a89d5d55b
Author: ashu <[email protected]>
Date:   2018-03-01 17:12:41 +0530

    Remove memory leak in various zheap related functions.

    Ashutosh Sharma, reviewed by Amit Kapila.

commit 0618b93ac8f431de813f23d5c8a7b68812ef729c
Author: ashu <[email protected]>
Date:   2018-03-01 17:02:12 +0530

    Initialize the new zheap page allocated during update operation on
    zheap tables correctly in zheap_xlog_update().

    Ashutosh Sharma, reviewed by Amit Kapila, reported by Tushar Ahuja.

commit 729d4cb6b09c98a5ecc57a670f55b468ab598d45
Author: Amit Kapila <[email protected]>
Date:   2018-03-01 16:34:44 +0530

    Design of zheap

    This readme covers overall design of zheap.  This is to help
    developers and or users to understand the zheap.  Later, we might
    split this into multiple README's.

    Amit Kapila, Robert Haas and Dilip Kumar

commit 17ae6f76fb85a1036111eb62f6bf0a2375531306
Author: Kuntal Ghosh <[email protected]>
Date:   2018-02-28 11:27:23 +0530

    Fix memory leak in zheap_multi_insert wal replay

    Reported by Ashutosh Sharma

commit 0d03216692b1d38b646126fd6300de1e619bc2db
Author: ashu <[email protected]>
Date:   2018-02-27 16:30:11 +0530

    Allow zheap_lock_tuple() to release lock on a zheap page if the
    tuple may be updated but the desired lock on a tuple is already
    acquired.

    Patch by me, as per the suggestions from Amit Kapila.

commit 37911c71c174dd3b95befe2d5f7b44d3dc421f62
Author: dilip <[email protected]>
Date:   2018-02-25 20:58:02 -0800

    Currently, on standby, we don't have DiscardUndoInfo like we have on the
    master side. So, on master before accessing any undo buffer we hold lock
    on DiscardUndoInfo in shared mode and undoworker hold that lock in exclusive
    mode. But on standby side we discard undo directly by WAL. So even though we
    check that undo is not discarded, but by the time we try to access the buffer
    undo may get discarded by the wal.

    Patch fixes the problem by checking the standby recovery conflict with other
    snapshot.

    Patch by Dilip Kumar, Reviewed by Ashutosh Sharma and Amit Kapila

commit c6457f72c4e7695680118902f4c662bedba3a965
Author: Mithun CY <[email protected]>
Date:   2018-02-21 01:34:42 -0800

    Remove unrelated code of previous commit

    In commit 5ba1e2f4c605f63a6deca278f39c9bfa05afb239 we have committed
    some unrelated code this patch removes same.

    By Mithun C Y

commit c04a4c83e19f0e9e10cb6aab0ab12ff8a241880f
Author: Kuntal Ghosh <[email protected]>
Date:   2018-02-19 21:18:29 +0530

    Fix zheap insert options for COPY

    Patch by me with help from Dilip Kumar

commit 17aaf8247ae3ef5763f5a164528f5c9f38dbe345
Author: Amit Kapila <[email protected]>
Date:   2018-02-20 16:37:37 +0530

    Remove redundant header inclusions.

commit 82681700ad5bd7b976438138d1c970eb6c55720a
Author: Mithun CY <[email protected]>
Date:   2018-02-20 02:26:27 -0800

    Check ItemIdIsDeleted on reacquire of BufferLocks

    In some cases after reacquiring the BufferLocks ItemId's might have
    been pruned so check if it is deleted before accessing ItemId's.

    Mithun C Y, reviewed by Amit Kapila

commit cf4614bf7a7b294eae264d4123d76584d66f0384
Author: Mithun CY <[email protected]>
Date:   2018-02-16 05:06:28 -0800

    Bugfix in ItemId status check.

    We have used tuple header flag
    ZHEAP_INVALID_XACT_SLOT instead of itemId flag
    ITEMID_XACT_INVALID while checking its status
    this caused undefined behavior. And, fixed a
    condition in zheap_search_buffer.

    Patch By Mithun C Y reviewed by Amit Kapila

commit 418c2e1ac7c46497b3d994bb3db5ea6850d66c50
Author: dilip <[email protected]>
Date:   2018-02-16 02:12:37 -0800

    bugfix in FetchTransInfoFromUndo

    The actual condition to break the while was if undo type is
    UNDO_INVALID_XACT_SLOT and undo_xid is input xid. This was
    broken in some of the previous commit.

    Patch by me reviewed by Amit Kapila

commit 051a7a2a3849a1140627de7414f79a868a292c38
Author: Beena Emerson <[email protected]>
Date:   2018-02-16 14:59:51 +0530

    Provide zheap support in check_default_allows_bounds

    For a zheap partitioned tables, check if the default partition has rows that
    meet the constraints of the new partition.

    Beena Emerson, reviewed by Rafia Sabih and Amit Kapila

commit a9c5724aca95877300414606bec648e8f512e045
Author: Rafia Sabih <[email protected]>
Date:   2018-02-13 16:02:37 +0530

    To add the storage_engine option in conf.sample file.

commit d61ff363ce28733fb518ccfa5fe9d32f71b7994d
Author: dilip <[email protected]>
Date:   2018-02-12 15:29:33 +0530

    wal log oldestxid having undo

    Currently oldestxid having undo is not durable and value is also
    not sent to standby.  As part of this patch this value is included
    in checkpoint record so after server restart also value will be
    valid.

    Patch by Dilip Kumar Reviewed by Kuntal Ghosh and Amit Kapila

commit 16fa749cf1c025efb744f1ebd246690a541fe0ac
Author: Mithun CY <[email protected]>
Date:   2018-02-12 02:02:57 -0800

    Set page prunable on Insert undo, inplace update
    with reduced lengths.

    Patch by Mithun C Y Reviewed by Amit Kapila.

commit 50f9fb43a3c302cf4fc206227786fba26ce72167
Author: Thomas Munro <[email protected]>
Date:   2018-02-09 23:52:42 +1300

    Create missing undo log segments during recovery.

    During recovery, we might discover that the segment files that existed at the
    time of the checkpoint don't exist, because they'll be deleted by later WAL
    traffic.  We'll create zero-filled files to avoid errors, and trust that the
    contents of the files will never be needed, because later WAL records discard
    them.

commit bc2ed1a1cefcb56749b3de382c6d6056e7837bd4
Author: Thomas Munro <[email protected]>
Date:   2018-02-09 23:10:22 +1300

    Make undolog meta-data checkpoints consistent.

    The earlier prototype code captured undo log meta-data at an arbitrary point
    in time somewhere after the redo point.  That worked only for clean shutdowns,
    at which point it was consistent and correct.  To do the job properly, this
    commit keeps track of two copied of each undo log's meta-data in memory: the
    current meta-data, and a snapshot as of the last checkpoint.  In order to
    maintain the checkpoint snapshot, every operation that modifies an undo log's
    meta-data must check if we are now on the other side of a redo point.  Since
    the shared memory access and lock contention would be expensive, we only
    actually do that while a checkpoint is in in progress, from a moment just
    before the redo point is chosen up until we discover that we are now on the
    other side of a redo point, which should ideally mean that it happens only
    once.

    RM43038, Thomas Munro

commit df81f34c6d62ec7601314d5561b8bf1be1596f53
Author: Mithun CY <[email protected]>
Date:   2018-02-08 23:37:10 -0800

    Fix crashes in page access after page pruning .

    Issue is in many places while fetching or updating
    tuple we failed to check if tuple has been
    eleted/updated and pruned after we have released the
    Buffer lock. This caused invalid access of pruned
    tuples from the page. Now we now check if itemid is
    deleted before accessing the tuple data in page.

commit b26c26c7e0651cbf4cd5fbfe865ee2226b776ee0
Author: Thomas Munro <[email protected]>
Date:   2018-02-09 10:29:42 +1300

    Fix an ordering bug when discarding undo buffers.

    We need to forget about undo buffers before we remove or recycle undo segment
    files, since otherwise a concurrent backend might try to write a buffer in
    order to evict it and discover that the file is gone.

    We also need need the same logic during recovery, so let's refactor that code
    into a function called from both UndoLogDiscard() and undolog_xlog_discard().

    Thomas Munro, based on report from Neha Sharma and diagnosis by Kuntal Ghosh

commit 25c38e52afb9d4252117fcb4bc575173b43f7492
Author: ashu <[email protected]>
Date:   2018-02-08 17:57:44 +0530

    Validate CHECK constraints on zheap relations.

    Ashutosh Sharma, reviewed by Dilip Kumar and Amit Kapila.

commit 1ef3bcd30c337456386ccfbafff1a913f111782a
Author: ashu <[email protected]>
Date:   2018-02-08 17:47:55 +0530

    Implement Table Rewrite performed during execution of ALTER
    TABLE command in zheap.

    Ashutosh Sharma, reviewed by Dilip Kumar and Amit Kapila.

commit 652911807ff33f35a7c297fdde709fbfc30f43be
Author: ashu <[email protected]>
Date:   2018-02-08 17:44:50 +0530

    Bugfixes in zheap_to_heap and heap_to_zheap APIs

    Allow zheap_to_heap and heap_to_zheap to allocate the values and
    nulls array based on the number of attributes specified in tuple
    descriptor rather than tuple header.

    Ashutosh Sharma, reviewed by Dilip Kumar and Amit Kapila.

commit fc6d0379c922e8c7cf797ec7c7247eb845c6ddb4
Author: ashu <[email protected]>
Date:   2018-02-08 17:43:55 +0530

    Restrict clustering of zheap tables

    Ashutosh Sharma, reviewed by Dilip Kumar and Amit Kapila

commit fe470e36e6ef990861d210cde6fc659657554ac3
Author: Thomas Munro <[email protected]>
Date:   2018-02-07 21:56:43 +1300

    Don't try to use DSM segments for undo logs in single-user mode.

    Thomas Munro, per bug report from Kuntal Ghosh

commit 5f10daf1c6a1a91b4311f0a578fb9f86eb1fd5cf
Author: Amit Kapila <[email protected]>
Date:   2018-02-06 14:13:29 +0530

    Avoid stack overflow in visibility routines

    Till now, we were traversing the undo chain in a recursive way which
    could easily lead to stack overflow for very large transactions.
    Traverse the undo chains in a non-recursive way.

    Amit Kapila, reviewed by Dilip Kumar

commit 2b3c4b122d756e4645c69709ed069eb754705a07
Author: Amit Kapila <[email protected]>
Date:   2018-02-05 18:28:47 +0530

    Implementation of 'For Update and For Share' tuple lock modes

    This requires tuple to be locked in Exclusive or Shared mode and it
    will conflict update, delete and other modes of locks.  Currently,
    multiple lockers for shared mode are not supported, that can be done
    as a separate patch.

    For other types of lock modes, user will get error "unsupported lock
    mode".

    Amit Kapila and Kuntal Ghosh

commit 57a987ada64779896e4c5653d7e65a628f51233c
Author: Mithun CY <[email protected]>
Date:   2018-02-05 03:28:56 -0800

    Bug fix in bitmap scan of zheap

    Consider zheap pages when calculating MAX_TUPLES_PER_PAGE

    Patch by Mithun C Y Review by Amit Kapila

commit 35c926be66fb6d991335e93ded5ae59e1919bf2b
Author: dilip <[email protected]>
Date:   2018-02-02 13:37:59 +0530

    Warning fix

commit 1d455e7504fd2a662c0624f36a42f1b303afdb20
Author: dilip <[email protected]>
Date:   2018-02-02 11:14:50 +0530

    Minor check fix while recovery from worker

    Reviewed by Rafia Sabih

commit 167901ea80db5e86c64e68630ac5c1082acf464b
Author: dilip <[email protected]>
Date:   2018-02-02 09:56:44 +0530

    Bugfix in wal recovery

    Flag, is_first_rec is not reset after allocating the first undolog
    for the transaction and it was considering transaction header for
    subsequent allocation for the transaction.

    Patch by Dilip Kumar Reviewed by Amit Kapila.

commit 1ddec06687a1c662d898c865d0a51fe85587040e
Author: Rafia Sabih <[email protected]>
Date:   2018-02-01 17:53:05 +0530

    Fix for Xmax value of unmodified zheap tuples

    Now, output InvalidTransactionId as the value of xmax for the
    zheap tuples which are unmodified. Previously, it was set to
    FrozenTransactionId which was incoherent with the behaviour of heap.

    Reported and reviewed by Ashutosh Sharma

commit d8c3e25148045a50a0f0a767cf803dad588e42d1
Author: Rafia Sabih <[email protected]>
Date:   2018-01-31 18:11:18 +0530

    Bug fix for undo actions

    If backend tries to apply undo actions for a record which is
    already discarded by undo worker, then exit quietly.

    Reported by Neha Sharma

commit 13ecdf57369df7a70087ce1a814fd5586dc420cb
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-29 15:18:32 +0530

    During recovery, set correct urecptr for non-inplace updates

commit 7f8c4546c7456a233b7317a08d730c797e23032f
Author: Thomas Munro <[email protected]>
Date:   2018-01-26 15:18:35 +1300

    Fix recovery of undo logs after a standby crash.

    A standby should never delete undo log meta data files that are referenced by
    its own control file, or it would fail to start up.

    RM43132, analysis and patch by Ashutosh Sharma, tweaked by me

commit 83159870bccd343672cb228580ec5f3c779c6b34
Author: Rafia Sabih <[email protected]>
Date:   2018-01-25 18:55:09 +0530

    Recovery of zheap relations when rollbacks are pending

    Now, the undo actions are performed at the time of restart
    for all those transactions that were in progress at the time
    of system crash or the last time when system was up. This
    ensures proper recovery of transactions involving zheap relations.

    A caveat to note here is that undo worker is initialised with the
    connection to default database 'postgres'.

    Reviewed by Dilip Kumar and Amit Kapila

commit c308be7d90a8a8ffb068203303cf0c1c99ff4fb2
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-25 11:00:10 +0530

    Fix definition of SizeOfZHeapMultiInsert

    Reported by Amit Kapila

commit 34619026014c203f2bd9a2d151ffae2778140ea4
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-24 17:43:10 +0530

    Allow ANALYZE on zheap table using VACUUM ANALYZE command

    Also, we forward the warning to LOG to avoid regression
    failure of some test cases.

commit d5454ef8d5e0556a1fceff48dcf13d55ecc8cffa
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-24 13:47:56 +0530

    Assign table oid while constructing heap tuple from zheap tuple

commit 81e55b488c707be50437484d21a1e92b553b291d
Author: Amit Kapila <[email protected]>
Date:   2018-01-24 12:39:39 +0530

    Move zheap_insert's buffer modifications inside critical section

    Previously, it was not done because we thought we need to add the
    tuple in page before forming the undo record as undo record requires
    blockid and offset which we can only get after adding the tuple.
    However, on closer inspection, actually, we only need blockid which we
    can get from the buffer.

    Patch by me, reviewed by Rafia Sabih

commit 9351f042a09197bcae827889e3b78ddea2e7b68d
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-02 12:07:15 +0530

    Concurrent index creation on zheap tables

    Add the ability to create indexes 'concurrently' on zheap relations,
    that is, without blocking concurrent writes to the table.
    Patch by me, Reviewed and tested by Ashutosh Sharma, Amit Kapila

commit 4780ba565205c638a890f053908157d128ea2470
Author: Beena Emerson <[email protected]>
Date:   2018-01-23 14:44:20 +0530

    Support storage_engine option for partitioned relations

    Allow partitioned table to have the storage_engine option and throw error when
    user tries to create a partition with storage_engine different from the parent.

    Reviewed by Rafia Sabih, Ashutosh Sharma

commit dec2957cbddadefda7b49fbf9c3a0d920d01a08b
Author: Rafia Sabih <[email protected]>
Date:   2018-01-23 12:28:41 +0530

    Bug fix for GiST indexes on ZHeap relations.

commit 9444dc2d14dc3f11d4a79156577475afe6e3f393
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-23 12:00:34 +0530

    Fix warning in nodeSamplescan

    Reported by Amit Kapila

commit bc3ff0e94567b0e85de7830113e84468fa003ed8
Author: Amit Kapila <[email protected]>
Date:   2018-01-23 11:11:13 +0530

    Add comments to elaborate why we always use Top Transaction Id in
    zheap.

commit a1b34455e7e1ca3b48373c192c25773e84b33b95
Author: Mithun CY <[email protected]>
Date:   2018-01-22 02:46:07 -0800

    Bug fix in space reuse

    Fix Null pointer access.
    Patch by Mithun C Y reported by Ashutosh Sharma.

commit 34be2349dca4d238ec3fe99fbe4bbc299ca0c615
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-22 12:28:25 +0530

    Fix definition of SizeOfZHeapMultiInsert

    Reported by Amit Kapila

commit 0257c1a99b1c1958d6c1ed535d219ab7ad4e73f6
Author: Rafia Sabih <[email protected]>
Date:   2018-01-19 15:55:49 +0530

    Add zheap relevant functions in DefineQueryRewrite

    Reviewed by Ashutosh Sharma

commit 38cef475cb6c6b74765be07b2e1f419661c002f6
Author: dilip <[email protected]>
Date:   2018-01-19 13:18:40 +0530

    Bug fix in space reuse

    Item is getting acceseed without checking whether its deleted or
    not.

    Patch by Dilip Kumar reviewed by Mithun C.Y.

commit ce9e110fb857e050aea92c5f1affbf7b7246d6b1
Author: ashu <[email protected]>
Date:   2018-01-19 11:54:19 +0530

    Bugfix in zheap_update().

    pfree memory allocated for payload bytes during non-inplace update
    in zheap_update().

    Ashutosh Sharma, With some help from Dilip and Kuntal.

commit 079443ce69d8425b42bbd217579753f6ce8d8ee6
Author: dilip <[email protected]>
Date:   2018-01-17 13:59:30 +0530

    Perform undo action in case of error.

    If there is some error while executing some sql statement, the patch
    take care of applying the undo actions required for rolling back the
    work done.

    Patch by Dilip Kumar Reviewed by Rafia Sabih and Amit Kapila

commit 9229daa6df42bc3eb60de0b4ef0728ea3a67a011
Author: dilip <[email protected]>
Date:   2018-01-18 11:08:17 +0530

    Block TidScan for the zheap

    Currently, tidscan is not implemented for zheap so give error.

commit 878ea5ed9c76ce7481a86d636728cc3e7b8e288a
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-17 15:47:05 +0530

    Bugfix in IndexBuildZHeapRangeScan

    We should avoid freeing zheap tuple from the slot in
    IndexBuildZHeapRangeScan when pageatatime scan mode is used for
    scanning the underlying relation.

    Reported by Ashutosh Sharma

commit 4ce7628b00bec6b0058ec9aeb4eade82075fd0b5
Author: Rafia Sabih <[email protected]>
Date:   2018-01-17 17:19:29 +0530

    Extend the support of exclusion constraints to zheap relations

    Reviewed by Ashutosh Sharma

commit a842d28fcb9de980a290268d8c557e1749bb232b
Author: dilip <[email protected]>
Date:   2018-01-17 13:58:37 +0530

    Bug fix in rewind

    If we are under a subtransaction then just reuse one
    slot, because during the rollback of the subtransaction we will rewind the
    undo insert location and the undo written for invalidating the slot will be
    overwritten. So, it is better to invalidate only one slot which our
    transaction is going to use.

    Patch by Dilip Kumar reviewed by Amit Kapila

commit e5e03186920b5a79025956258b17fe87b3d50699
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-11 17:48:06 +0530

    Fix mask value used in ZHeapTupleHeaderGetNatts

    ZHeapTupleHeaderGetNatts should use ZHEAP_NATTS_MASK to fetch number
    of attributes from t_infomask2.

commit 4c6d4c685f52b0a7d998097734d11b5387ee05c3
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-11 11:49:25 +0530

    Implement TableSampleScan for zheap

    Reviewed by Mithun CY

commit 68bee6f61f146ef71630d3809482a1944ef40ddd
Author: Mithun CY <[email protected]>
Date:   2018-01-10 03:26:41 -0800

    Fix cursor fetch backward scan for zheap

    Reviewed by Kuntal Ghosh

commit ed720bd223e3ce9842681ccacd4de84b052c619c
Author: Mithun CY <[email protected]>
Date:   2018-01-10 03:01:21 -0800

    get rid of KeyTest in zheap scan

    zheap do not support catalog tables hence
    no need of keytest as it is in heap. So
    adding asserts to acknowledge same.

    Reviewed by Kuntal Ghosh

commit cb19200ec6837fa2fb1aef37ad045db5661c892e
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-10 15:31:23 +0530

    Fix brin summarize for zheap

    Reported by Mithun CY

commit 9d6ee4a45df4911854ac32d205eeaab648ce4fb0
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-10 11:01:34 +0530

    Implement bulk insert strategy for zheap_insert

    Reported by Ashutosh Sharma

commit 8253166c9f8100e6ce75049004787215f5befe37
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-08 17:43:42 +0530

    Fix sysattributes fetching for the ZHeap

    Make sysattributes fetching work with 64-bit transaction ids.

commit e9a4184a96df7f96b53f1a849cdb75cae6b4ee2a
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-09 17:27:39 +0530

    Handl COPY FROM for non-multi-insert mode

commit 78d680eb0deef07ead5b93c70168284a73ea30ec
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-09 16:11:59 +0530

    For triggers, tuple table slot shouldn't try to free memory itself

commit 250fef496972efec042ec83a490d377b1621f4a1
Author: Amit Kapila <[email protected]>
Date:   2018-01-08 14:00:45 +0530

    Support Epoch in Zheap pages

    The idea is to make the change related to 64-bit transaction ids only
    for the zheap pages whereas heap pages still operate with 32-bit
    transaction ids. We will need wraparound and freeze vacuums for
    metadata (system tables) stored in heap, but not for data stored in
    zheap tables. The way to make 64-bit transaction ids in zheap is to
    store epoch along with transaction id in each transaction slot (which
    will make each transaction slot as 16 bytes (4 bytes transaction id,
    4 bytes epoch, 8 bytes undo pointer)). Now, if we somehow ensure that
    there is no undo for any transaction whose age is 2-billion years old
    (wraparound limit), then we can easily make out the visibility using
    current epoch and oldest_xid_having_undo. The way to achieve it is to
    stop the system if it reaches such a situation. We piggybacked on the
    existing wraparound machinery to raise different warning messages once
    the system reaches that stage. If the epoch+xid in the page is lesser
    than oldestXidWithEpochHavingUndo then it is all visible, otherwise,
    the transaction will belong to current epoch and all the current rules
    of current transaction system will work.

    The reason for relying on 2-billion transaction age limit is that
    current system (Transaction related functions like TransactionIdPrecedes)
    relies on that and we don't want to change it.

    We won't need any vacuum for freezing the transaction ids or wraparound
    vacuums for zheap pages after this commit.

    Amit Kapila, with some contribution by Dilip Kumar, reviewed and
    verified by Kuntal Ghosh and Dilip Kumar.

commit 0cc6dbc97f9320a21cad0d7deb86a9867b51e97f
Author: dilip <[email protected]>
Date:   2018-01-08 11:19:01 +0530

    Bugfix in rollback to savepoint

    When rollback (partial or complete) is done from the backend then
    rewind the insert location of the undo log.

commit 455bb1d00b8258f0e76b88cbae9705e308c8900a
Author: dilip <[email protected]>
Date:   2018-01-08 10:22:20 +0530

    Bugfix in parallel query

    Added function for parallel begin scan on the
    zheap table.

    Path by me, reported by Mithun C.Y reviewed by Amit Kapila

commit e9d75ef1410647ef223ebf52528d8010ede6f118
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-29 12:11:00 +0530

    Implement ANALYZE on zheap tables

    Reviewed by Amit Kapila

commit a74fac0c485211a102ffe4208a9549f0f5f5de52
Author: Mithun CY <[email protected]>
Date:   2018-01-04 19:16:00 -0800

    Bug fix for zheap page pruning

    When pruning we should ignore deleted itemid's as there
    is no tuple space assosiated with them.
    Also if tuple is non-inplace updated then consider the
    previous space assiated with them for pruning.

commit 3d4a58d41d19cb296633801169c31eeb7caf4c23
Author: Rafia Sabih <[email protected]>
Date:   2018-01-04 17:51:48 +0530

    Bug fixes for storage_engine option

    Ignore the storage_engine option for views or
    partitioned relations.

    Avoid adding storage_engine option multiple times
    when it's given in conf file as well as in CREATE
    statements.

    Reported by Ashutosh Sharma
    Reviewed by Amit Kapila and Ashutosh Sharma

commit 34dfda185019a93abdb77894558e37df9cd2b9b1
Author: Kuntal Ghosh <[email protected]>
Date:   2018-01-02 14:02:53 +0530

    Implement SatisfiesNonVacuumable for zheap

    Patch by me, Reviewed by Amit Kapila

commit 63e4455ec4009eae16fc2d4bbcc8c14767f0c5dd
Author: Amit Kapila <[email protected]>
Date:   2017-12-22 13:57:59 +0530

    Remove redundant function definition added by commit 8aeb255f.

commit fb16b15dd108f1769587a5f81d57ac5e9a9478ab
Author: Amit Kapila <[email protected]>
Date:   2017-12-22 13:51:13 +0530

    Support space reuse within a page

    Allow reuse of space for transactions that deletes or non-in-place
    updates the tuples or updates the tuples to shorter tuples. It has
    the capability to reclaim the space for deleted tuples as soon as
    the transaction that has performed the operation is committed. There
    is some difference between the way space is reclaimed for
    transactions that are committed and all-visible vs. the transactions
    that are committed but still not all-visible. In the former case, we
    can just indicate in line pointer that the corresponding item is dead
    whereas for later we need the capability to fetch the prior version of
    tuple for transactions to which delete is not visible. As of now, we
    have copied the transaction slot information in line pointer so that we
    can easily reach prior version of tuple.

    We try to prune the page for non-in-place updates when there is
    insufficient space on the page.  The other times where we can try to
    prune the page could be while Inserting if there is insufficient space
    on a page or when buffer is being evicted or read, but we can do that
    as a separate patch.

    Mithun C Y and Amit Kapila.

commit a1bce7facfd467c804ccab660f9befb3df8eae1f
Author: dilip <[email protected]>
Date:   2017-12-22 10:55:30 +0530

    Avoid using UndoDiscardInfo if it is not initialized

    If UndoDiscardInfo is not yet initialized, use UndoLogIsDiscarded to
    check whether an undo record is discarded. It also initialize UndoDiscardInfo
    for the same log.

    Reported by Mithun. patch by me

commit 4baf44c765524baf9833308af1d3807987f6889e
Author: dilip <[email protected]>
Date:   2017-12-18 17:47:48 +0530

    Fix warnings in zheap code

    Reported by Thomas Munro

commit 92c2b94de69c49504f3b7d79d676b364870ff279
Author: Rafia Sabih <[email protected]>
Date:   2017-12-12 14:53:54 +0530

    Buf fix for prevlen of the first record of the log

    Reviewed by Dilip Kumar

commit 6616d18f3080f2d80b21c891d2376ffe58b51614
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-08 18:23:09 +0530

    Restrict transition table creation for zheap

commit 97119d13a22de3759574c30ebc442cf7e00e3a49
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-08 16:55:25 +0530

    Fix defect in applying undo action in case of abort

commit c8287a5eaac5bc934645e4cc9b51da12d8f3f71e
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-08 18:25:57 +0530

    Fix dirtysnapshot behaviour for inserted tuples by aborted transactions

    Reviewed by Amit Kapila

commit 1369b1c6dc27d7eeac63791725f9e010ee09e495
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-07 17:50:30 +0530

    Restrict foreign key triggers on zheap tables

commit 1c1befcf0e8a08ff1f5cdd49110a0f4a0140afbc
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-07 17:49:51 +0530

    Restrict INSERT ON CONFLICT on zheap tables

commit e135508ebd7292042d8d12b820198025e569b9b8
Author: dilip <[email protected]>
Date:   2017-12-07 17:40:47 +0530

    Fix issue is PageFreezeSlot

    Memory was freed without checking NULL, fixed the same

    Reported By Kuntal Gosh

commit 1ba3aebd1b0d1789c99ba816237b487f950e40ff
Author: dilip <[email protected]>
Date:   2017-12-07 16:07:34 +0530

    Fix issue in regression test

    Avoid executing undo action when transaction is not in progress

    Reported by Kuntal Ghosh

commit 787fa1ff9697dcf872546812ad606a7e41950287
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-06 15:46:37 +0530

    During recovery of inplace-update, fix old tuple header

    Reviewed by Amit Kapila

commit 2eec4974f8da5a7db17524250fd466fbe8995dc7
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-06 15:43:52 +0530

    Update tuple length during inplace-update

    During inplace-update, the tuple should be updated to the new tuple.

    Reviewed by Amit Kapila

commit 03014036363d2c494ee80f95d64f5abd5bdae48a
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-06 15:26:15 +0530

    Store block number before preparing the undo record

    In undorecord, we should store block number before preparing the
    undo record. Otherwise, expected size of the undo record won't
    consider the size for including block info.

    Reviewed by Amit Kapila

commit e7fb026e79d9b724edc54d1b78d2725651d77757
Author: dilip <[email protected]>
Date:   2017-12-07 11:19:04 +0530

    Fix defect in applying undo action in case of abort

    Reviewed by Kuntal Ghosh

commit c646ff19e7fdaddba0b8757ce14e8ab0e824329b
Author: dilip <[email protected]>
Date:   2017-12-06 10:35:03 +0530

    Fix Typo

    Reported by Rafia

commit dac6bdc623bd7b8502dd6642f784024a50abfb1d
Author: dilip <[email protected]>
Date:   2017-12-05 18:55:41 +0530

    Fix warnings

commit 59eb32500326cfb4db8b1336d4ab9d97aa6741f4
Author: Amit Kapila <[email protected]>
Date:   2017-12-05 18:22:01 +0530

    Rewind the undo pointer after applying undo actions

    After applying all the undo actions for a page, we clear the
    transaction slot on a page if the undo chain for block is complete,
    otherwise rewind the undo pointer to the last record for that block
    that precedes the last undo record for which action is replayed.

    This will help us in knowing whether the undo action is already
    replayed during recovery.

    Patch by Amit Kapila, reviewed by Dilip Kumar

commit 43c6e1c541a4e9d6cc310c1e4b46e514ddfc9f98
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-05 14:30:26 +0530

    UndoDiscardInfo should be updated in exclusive lock on the mutex

    Reviewed by Dilip Kumar

commit 41c6d9d337e2b09448ff324991c639793e61889e
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-05 14:28:00 +0530

    UndoGetOneRecord should be called under shared lock on UndoDiscardInfo

    Reviewed by Dilip Kumar

commit 49b755159affcc0f0e23f3591ddc46d2a9a1e7fc
Author: dilip <[email protected]>
Date:   2017-12-01 15:27:16 +0530

    Remove genarating the subtransaction id in zheap

    Currently in heap we need to maintain the subxac id so that
    we can identify the changes done within suxact and properly
    identify the visible tuple if subxact status is not same as
    main transaction. But, in zheap we have undo and with help
    of that we can immediately revert the effect of the subxact
    and we never need to track the status of the subxact.

    This will also help in maintaining the limited slot inside the
    zheap page.  Because if we assign a separate xid to subxact then
    we may need to provide extra slot for each subxact.

    Patch by Dilip Kumar reviewed by Amit Kapila

commit c0c59ddea242f191eaeb55ddb2598ec31e77b96a
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-04 17:50:36 +0530

    During slot-reuse replay, use physical tuple if not included in wal record

    If tuple is not included in wal record, access the physical tuple
    to fetch the corresponding slot number for the same tuple.
    Reported by me, patch by Dilip Kumar.

commit a83904b8bb7e5aa81e8906d2daefed70afdacd80
Author: Mithun CY <[email protected]>
Date:   2017-12-04 20:48:01 -0800

    Zheap tuples are locally allocated hence set
    tts_shouldFree as true.

    Reviewed by kuntal

commit 5d561693d232b766ed618f48498b9a667cc1ac56
Author: dilip <[email protected]>
Date:   2017-12-04 17:36:45 +0530

    Fix issue in prevlen

    Return without releasing the lock
    Reported by Kuntal Ghosh

commit b5071ac66cf206801b0de4f0cc9de4390bb59cf8
Author: Kuntal Ghosh <[email protected]>
Date:   2017-12-04 14:34:27 +0530

    Avoid using UndoDiscardInfo just after undoshem initialization

    If UndoDiscardInfo is not yet initialized, use UndoLogIsDiscarded to
    check whether an undo record is discarded. It also initialize UndoDiscardInfo
    for the same log.

    Reported by Neha Sharma, patch by me, reviewed by Dilip Kumar

commit f916f158f39676de2ab755118924518e3c6f45b1
Author: dilip <[email protected]>
Date:   2017-11-28 09:16:00 +0530

    Make prevlen crash safe

    Currently transaction previous recrod's length is not crash safe
    but there is possibility that transaction can be spread across
    checkpoints, in such case while preparing the first undo record
    we do need to have the length of the previous record which was
    inserted before checkpoint. For fixing the same we are maintaining
    this value in undo meta and wal logging this along with other
    undo meta.

    As part of this patch also removed one unused structure member
    in undo meta.

    Patch by Dilip Kumar Reviewed by Amit Kapila

commit f20d78fe0d048ba600162e0f5d794399e0dbee13
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-22 16:27:25 +0530

    Write WAL for zheap_multi_insert

    Reviewed by Dilip Kumar, Amit Kapila

commit ed0f47495ef7de6c0e0e8940b6ac630704b0bf77
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-22 16:08:25 +0530

    Set uur_type for multi_insert at begining

    Reviewed by Amit Kapila, Dilip Kumar

commit e13cb875476963959cea79edd114fa8d701909e0
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-14 14:49:30 +0530

    Fix assertion failure in zheap_delete

    Reported by Neha Sharma

commit ee06e282b6bb1c64d6c0820fb2c690778af71f71
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-21 20:32:49 +0530

    Derive latestRemovedXid for hash deletes by reading zheap pages

    Reviewed by Amit Kapila

commit bf78457e2e7706338d00f60fbe487b315b626ff5
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-13 21:02:12 +0530

    Derive latestRemovedXid for btree deletes by reading zheap pages

    Reviewed by Amit Kapila

commit 53b6d509674a0aa1b59c00306bdec63c9cad3110
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-22 10:26:35 +0530

    Implement exclusion constraints for zheap

    Patch by Ashutosh Sharma. Reviewed by Kuntal Ghosh, Amit Kapila.

commit a4f00f80ba4745c45be7d747bdd7d4a6363a78f7
Author: Amit Kapila <[email protected]>
Date:   2017-11-22 09:33:47 +0530

    Implement SnapshotSelf for zheap

    Returns the visible version of tuple (including effects of previous
    commands in current transaction) if any, NULL otherwise.  This will
    be required for features like exclusion constraints to work with
    zheap.

    Ashutosh Sharma and Amit Kapila

commit a1f49ef37d8bbfd19741bc76b0c749000c9d281d
Author: Rafia Sabih <[email protected]>
Date:   2017-11-21 12:13:44 +0530

    Bug fix in rollbacks in zheap

    The patch fixes the case where ending undo record pointer
    is not provided. This is particularly required in rollback
    to savepoint type of scenarios.

    RM 42958, reviewed by Amit Kapila.

commit 64ecef026b765bba8262b3acce21b3c308e2b02a
Author: Amit Kapila <[email protected]>
Date:   2017-11-21 08:54:58 +0530

    Implement the API to advance the latest xid that has removed the
    tuple.

    This will be required by the future patches to implement free space
    management and xlog for indexes like btree and hash.

commit b6d4a835ee52a6c0eec1e2e29c0dc84f866ab42a
Author: Amit Kapila <[email protected]>
Date:   2017-11-20 17:43:12 +0530

    Implementation of undo actions for zheap operations

    Implemented undo actions for delete, update, lock tuple, multi-insert
    operations.

    Patch by Amit Kapila, reviewed by Rafia Sabih

commit 6828caf8f4d53788756079e0059a0d117e92afe3
Author: Amit Kapila <[email protected]>
Date:   2017-11-20 17:27:37 +0530

    Infrastructure to execute undo actions at page-level

    Starting from the last undo record of a transaction read the undo
    records in a backward direction till first undo record of a
    transaction and accumulate the actions per page.  As soon as the
    action is for a different page, we execute the accumulated actions
    of previous page.

    We are logging the complete page for undo actions, so we don't need
    to record the data for individual operations.  We can optimize it by
    recording the data for individual operations, but again if there are
    multiple operations, then it might be better to log the complete
    page.

    Patch by Amit Kapila, reviewed by Rafia and Dilip

commit c00df8c30bd5baa1eb1ea14f89747ee5ea7d7fe0
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-20 09:56:20 +0530

    Write WAL for zheap_lock_tuple

    Patch by Ashutosh Sharma and Kuntal Ghosh. Reviewed by Amit Kapila.

commit c00823a0787680eb8c0f02b8d998c6cf3bad39b1
Author: Rafia Sabih <[email protected]>
Date:   2017-11-17 15:59:40 +0530

    Bug fix for rollback inserts

    The page header size was not included in the calculation of
    prevlen for undo records when record starts from a new page.
    The patch fixes the issue.

commit b7bda571bb9c01fe2cb9355f9fd498cb6aa06078
Author: dilip <[email protected]>
Date:   2017-11-16 18:10:42 +0530

    Write WAL for invalidating the transaction slot

    The important consideration for logging invalidating slot operation is
    that we need to identify the tuples pointing to these slots and also the
    transaction id in the slot while performing redo operation for undo log.
    So, we are conditionally (when full page writes are off) writing tuple
    offsets and slot xid in WAL as well.  In case full page writes are
    on, we can rely on the tuples and slots from page.

    Path by Dilip Kumar, Reviewed by Kuntal Ghosh and Amit Kapila

commit 9c9a8f88ad2b8fea8a319e0d9aad40924e1f5684
Author: dilip <[email protected]>
Date:   2017-11-16 18:09:18 +0530

    Write WAL for slot Freeze operation

    Write the information of the slots which got frozen and during recovery
    we can generate the information of the tuple which are pointing to these
    slot and mark them frozen same as we are doing in DO operation.

    Path by Dilip Kumar, Reviewed by Kuntal Ghosh and Amit Kapila

commit f1be5834b52f5023522af5ce862f9c2c40d7048e
Author: Amit Kapila <[email protected]>
Date:   2017-11-15 17:17:17 +0530

    Store old version of tuple in WAL for delete

    Patch by me, reported and reviewed by Ashutosh Sharma

commit e1a47f763d17e4bc33af7ae64fa234f7fefbed96
Author: Rafia Sabih <[email protected]>
Date:   2017-11-14 13:26:53 +0530

    Support for SELECT INTO statements for zheap

    This enables the creation of tables in zheap format
    through SELECT INTO statements.

    Reviewed by Amit Kapila.

commit e1afa7d5eacde17d322dadb659f1d4c78d628cdb
Author: Rafia Sabih <[email protected]>
Date:   2017-11-14 11:56:43 +0530

    GUC for storage_engine

    Now, we have a GUC -- storage_engine to specify the storage_engine option,
    which can be modified before server start. Currently, we have two options
    for this GUC, viz. heap and zheap, with it's default value being heap.
    Note that once this GUC is set to zheap, relations are created in
    zheap format, irrespective of whether with (storage_engine ='zheap')
    is specified in CREATE TABLE statement or not.

    Reviewed by Amit Kapila.

commit 2587d533e90aa99701d3125f2dc0ac00c9a54029
Author: Amit Kapila <[email protected]>
Date:   2017-11-13 14:11:58 +0530

    Use better way to set item pointer.

    Suggested by Kuntal Ghosh.

commit 2c3e87e4e9efdef30663c93ee606c12de10c78de
Author: Amit Kapila <[email protected]>
Date:   2017-11-13 13:09:03 +0530

    WAL log update operation in zheap

    The important consideration for logging update operation is that we
    need to generate entire old tuple while performing redo operation for
    undo log.  So, we are conditionally (when full page writes are off)
    writing complete tuple in WAL as well.  In case full page writes are
    on, we can rely on the tuple from page. For the new tuple, we are
    writing just the diff tuple as we are doing for heap.

    Patch by me, reviewed by Kuntal Ghosh.

commit a6eb456784db76b444121ef171d635e4c4a01e13
Author: Amit Kapila <[email protected]>
Date:   2017-11-13 08:56:41 +0530

    Fix type of undo record in zheap_multi_insert

commit d1859b51bd51ac39d8915f40df7ff679c3df0461
Author: Amit Kapila <[email protected]>
Date:   2017-11-10 18:31:54 +0530

    Fix the calculation of previous undo record length

    When the undo record crosses page boundary, we need to consider
    pageheader length which was being ignored.  Fix the same.

commit 4159a0175ce16bd5684314b63a23c0cf9fc8733e
Author: Thomas Munro <[email protected]>
Date:   2017-11-09 22:27:44 +1300

    Show unattached undo logs as null xid and pid in pg_stat_undo_logs.

commit fce53d149e2b6e67e40eb33b92517cd58673cd4b
Author: dilip <[email protected]>
Date:   2017-11-08 17:13:31 +0530

    Enhance zheap_lock_tuple

    Handled the case when same tuple is locked multiple time by
    the same transaction.

    Patch by me, reviewed by Ashutosh Sharma and Amit Kapila.

commit 91cd6e14fa9e2a2a9a4bb929750951ed7cfa68ef
Author: dilip <[email protected]>
Date:   2017-11-08 17:03:49 +0530

    Bug fix in trigger for zheap

    Currently we are always getting the older as well as newer version
    of tuple from the zheap. But, in case of inplace update both are
    having same tid and will fetch the tuple.  Patch will fix the bug
    by getting the older version of the tuple from the undolog.

    Patch by me, reviewed by Ashutosh Sharma and Amit Kapila.

commit 0ef921f6fc46aa6a3fd20eac9d199a3e173c1fc1
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-06 16:00:43 +0530

    Restrict ExecLockRows on zheap relations

    As of now, we don't support FOR SHARE/FOR UPDATE on zheap tables.
    So, throw appropriate error for the same.

    Reviewed by Dilip Kumar

commit 3e73bc3ccd71c28c962749dcda4e54bc8f245022
Author: Amit Kapila <[email protected]>
Date:   2017-11-08 11:18:50 +0530

    WAL log delete operation in zheap

    The important consideration for logging delete operation is that we
    need to generate entire tuple while performing redo operation for undo
    log.  So, we are conditionally (when full page writes are off) writing
    complete tuple in WAL as well.  In case full page writes are on, we
    can rely on the tuple from page.

    Patch by me, reviewed by Ashutosh Sharma.

commit eaf3708c605930073dcb0d64caad1c9dd13efb01
Author: Kuntal Ghosh <[email protected]>
Date:   2017-11-07 15:42:10 +0530

    Fix assert in bitgetzpage

commit 01104c4a5af83cff71704bb399172e9c050929c0
Author: dilip <[email protected]>
Date:   2017-10-27 13:58:08 +0530

    Support sysattributes fetching for the ZHeap

    Properly fetch the xmin,xmax,cmin and cmax from the undo.

    Patch by Rafia some defect fixed by me reviewed by me and Amit.

commit 50f4297716c242fee4cb8e34c2903ccef297983f
Author: Amit Kapila <[email protected]>
Date:   2017-10-25 18:11:37 +0530

    Undo Action and Replay for Insert Operation

    The undo insert action is to mark the corresponding item as dead if
    relation has any index and unused otherwise.  The need to item as
    dead is that we can't completely clear the item till the
    corresponding index is marked as dead.  Currently undo actions are
    replayed on Rollback or Rollback to savepoint.  Ideally the action
    should be replayed on error as well, but we will deal with it in
    a separate patch.

    Amit Kapila, reviewed and tested by Rafia Sabih

commit a461ec04e06d1675d635904caa3d993370c7ef0f
Author: Amit Kapila <[email protected]>
Date:   2017-10-25 17:44:57 +0530

    Update prevlen in undo record header with the length of previous
    record.  This is required to traverse the undo chains from last undo
    record to first.

    Dilip Kumar.

commit 66c00153e2de48f9b8ab5c8d2454f87cb2efea6d
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-23 17:57:39 +0530

    Bug fix in UndoLogAdvance

    During recovery, MyUndoLogState is uninitialized. Hence, It can't be
    used to fetch undo control pointer while replaying undo records.

    Reviewed by Amit Kapila, Dilip Kumar

commit 08870389179383469196b243b6b5662bc8d41cb6
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-18 14:21:19 +0530

    Restrict alterting non-empty zheap tables

    During ALTER command, sometimes we scan and rewrite a table.
    For zheap, we've to implement the same in ATRewriteTable. For now,
    just throw an appropriate error.

    Reviewed by Amit Kapila

commit 1207f60fb21542e8b6675335848d373e6aafed3d
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-18 15:04:01 +0530

    ALTER should restrict partitioning/inheritance to same storage_engine

commit d43e896ba1e66d0a8246bbb3df58c4f38010fcbd
Author: Rafia Sabih <[email protected]>
Date:   2017-10-17 17:07:05 +0530

    Hibernate undo-worker when the system is inactive

    The undo-worker hibernates for minimum of 100ms and maximum of 10s,
    based on the time the system remained idle.

    RM42373, reviewed by Mithun Cy

commit 9c612f44ad2204510ab13a620a003460889c41db
Author: dilip <[email protected]>
Date:   2017-10-17 16:42:38 +0530

    Bug fix in multi-insert

    uur_xid is not set properly in multi-insert that was making undo-discard
    operate based on invalid xid and was causing segmentation fault.

    Reported by Ashutosh, fixed by me Reviewed by Kuntal

commit 0023cc82949adc74fdb18c7825cf7e5d1988da49
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-04 15:20:38 +0530

    Restrict partitioning/inheritance to same storage_engine

    The descendant/partitioned table inherits the same storage
    engine as its ancestors. User should not specify any storage_engine
    for the descendant/partitioned table. Also, this commit doesn't
    include any sanity checks for the scenarios where heap table
    inherits zheap table and vice versa.

    Reviewed by Amit Kapila, Rafia Sabih

commit 99623dfb48a055ae2b43db76d9e87747915fec09
Author: Rafia Sabih <[email protected]>
Date:   2017-10-17 10:39:51 +0530

    Avoid iteration over all the backends in UndoDiscard

    Instead of iterating over all the backends, now iterate only
    the active logs to determine the next log for undoDiscard.

    RM42373, reviewed by Dilip Kumar

commit 8f40d7b7802c1904f4c845c744f62a366d2f9a8a
Author: Thomas Munro <[email protected]>
Date:   2017-10-17 13:58:11 +1300

    Fix undolog wordsize thinkos that broke 32 bit builds.

commit 927c309586f38da7c737594c3beef65f7c51e5cc
Author: dilip <[email protected]>
Date:   2017-10-16 21:11:17 +0530

    Bug fix in update transaction start record

    In recovery start transaction info was not updated properly, it was
    fetching prev_xact_start from local variable which in fine during
    normal run, but InRecovery there is only one process so we can not
    depend upon the local variable instead we should always fetch that
    from log meta data.

commit ea6bf762f2a6f5673e8978118edfee99767b844f
Author: Thomas Munro <[email protected]>
Date:   2017-10-12 05:53:59 +1300

    Implement UndoLogNextActiveLog().

    Provide a simple way to iterate through the set of active undo log numbers.
    This interface might need some refinement to support UndoPersistence
    levels in future.

    RM42373, Rafia Sabih

commit 712f332b5ac98b22110929ae2136e4b0c38dffab
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-11 14:47:58 +0530

    Don't discard undo if a transaction rolls back

commit 1c2daa5b5a47856a227ad66c7cc08e761e147871
Author: dilip <[email protected]>
Date:   2017-10-11 09:48:37 +0530

    bug fix in Synchronizing undo update with undo discard

    update undo record is just checking whether undo is discarded
    or not, instead it should acquire the discard lock and read the
    undo under the lock. Fixed the same.

commit 8f17025103fc2c344f56b05770550e50e79b5bb3
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-05 16:48:57 +0530

    Wrong undorecord expected size for first record of a undolog

    When we attach a new undo log, a new transaction is definitely started.
    Hence, we should set is_first_rec flag in undo meta and calculate the
    undorecord expected size.

    Reviewed by Dilip Kumar

commit 23be6c5939487c691e77c03daffbdb04dff9afb4
Author: Kuntal Ghosh <[email protected]>
Date:   2017-10-04 11:36:04 +0530

    Fix some compiler warnings

commit 21c53521b5a1e98ba21a83ec0e8abd5fc97fa866
Author: ashu <[email protected]>
Date:   2017-09-28 15:11:33 +0530

    Add missing null terminator to the dest string after memcpy().

    memcpy() does copy the specified bytes of string from memory area
    src to memory area dest, but, doesn't add null terminator to the
    dest string. This patch handles to same in FindLatestUndoCheckpointFile().

    Patch by me, reported by Amit Kapila.

commit cee1d83ad2888cfe451ec6bf7c31c31ae79b694b
Author: dilip <[email protected]>
Date:   2017-09-28 14:16:05 +0530

    Fixed pending issues for WAL recovery

    Fixed the recovery for the subtransaction and properly update
    the start transaction header record.

commit 4df8c94e347ee6291f9310840164125e3c57a5fe
Author: Amit Kapila <[email protected]>
Date:   2017-09-28 09:25:43 +0530

    WAL log Insert operation in zheap

    We need to ensure that we log enough information that during recovery,
    we can construct the unpackedundo record and then insert it in same
    way as we insert for the DO operation.  Note, that we don't write full
    page image for undo logs as those are written serially and we always
    apply all the WAL records for undo log unlike for zheap pages where
    we don't apply it, if the LSN on a page is greater than the LSN of WAL
    record.  This is to avoid problems like if the page header is written
    after last checkpoint, but the other part is not then the LSN in page
    header will be latest but not all the data.

    Patch by me, reviewed by Dilip Kumar.

commit 604100e9ff28172ef1c4372745fafd5501e03a98
Author: ashu <[email protected]>
Date:   2017-09-27 16:45:24 +0530

    Throw an error message if index-only scan is performed for zheap
    tables.

    Patch by me, per suggestions from Amit Kapila.

commit 91630e7f7129b76fe46f29637f4117fca7ef3963
Author: ashu <[email protected]>
Date:   2017-09-26 16:30:52 +0530

    Make the macro 'RelationStorageIsZHeap' (used to determine if the
    relation storage format is zheap or not) more robust.

    Patch by me, quickly reviewed by Dilip.

commit 31a1c21f3e38e1935a8e8d9061ea307273ead50c
Author: ashu <[email protected]>
Date:   2017-09-26 10:34:17 +0530

    Add macro 'UndoCheckPointFilenamePrecedes' to find the oldest undo
    checkpoint file in pg_undo directory.

    RM42357, Patch by me, as per the suggestions from Thomas Munro.

commit fb101c53f1c750c6ca37b049694db50118637b61
Author: ashu <[email protected]>
Date:   2017-09-26 10:29:28 +0530

    pg_upgrade: Rename undo checkpoint file after pg_resetwal.

    During pg_upgrade, pg_resetwal module is invoked which resets all WAL
    related information in the Controlfile including the last checkpoint
    LSN and then a server process is started. But, as the undo checkpoint
    filename is based on last checkpoint LSN, the server startup process
    fails as it is unable to find the undo checkpoint file corresponding
    to the last checkpoint lsn as mentioned in the Controlfile.

    This patch fixes that issue and also copies the undo data and checkpoint
    files from old to new cluster during pg_upgrade.

    TODO: Currently, this patch just adds the logic to copy undo data files
    from default location i.e 'base/undo' which means if undo data files are
    present in non-default location it won't work. In future, when the support
    for storing undo data files in the non-default location is added, that
    needs to be handled in pg_upgrade as well.

    RM42357, Patch by me, reviewed by Thomas Munro.

commit c95f0fda591c3d1e1b3e520570c8e616d4fb42ea
Author: dilip <[email protected]>
Date:   2017-09-25 11:51:06 +0530

    Added trigger supports for zheap

    Currently zheap is not supporting the triggers because all
    trigger mechanism is dependent on HeapTuple, this patch
    provide a conversion between heap and zheap tuple and also
    a api to fetch tuple from zheap for trigger.

commit 13b7d1735e5444fca61368df9ab515267eadf4be
Author: dilip <[email protected]>
Date:   2017-09-22 15:00:13 +0530

    Bugfix in undo discard

    If log is not attached to any session it will have invalid
    transaction id.  In such case just discard till the current
    insert location.

commit ef93ec6350767d863b30cd8a11e632a1442a22af
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-21 16:50:30 +0530

    Fix update of zheap columns with null

    For in-place updates, we should copy non-visibility flags of
    infomask in the updated tuple.

    Reviewed by Amit Kapila

commit 19c54fb49faecbde387be5ed6bde2bc94cbf67bf
Author: dilip <[email protected]>
Date:   2017-09-22 09:49:29 +0530

    Bugfix in undo discard mechanishm

    Prior to this undo was not discarded properly for the last transaction
    in the undolog hence oldestxidhavingundo was also not getting updated
    properly.

commit 5e45ce2025a7024937763e71dcde007941057c3f
Author: ashu <[email protected]>
Date:   2017-09-21 20:03:44 +0530

    Replace unwanted Assert statement in ZHeapTupleSatisfiesDirty
    with if-check.

    Patch by me, reviewed by Amit Kapila, reported by Neha Sharma.

commit 943e365fc06f42c264b9c39d78d9a8a94b3754b6
Author: Amit Kapila <[email protected]>
Date:   2017-09-21 15:00:10 +0530

    Use oldexXidHavingUndo to determine if the record is visible

    Previously we were using RecentGlobalXmin to determine if the record
    is all visible, that is okay till we have rollbacks.  Use the more
    appropriate xid i.e oldexXidHavingUndo to determine if record is all
    visible.

    Patch by me, reviewed by Dilip and Kuntal.

commit 6715131fd875709a5b4d89808117b2e17bb7cc32
Author: Amit Kapila <[email protected]>
Date:   2017-09-21 14:02:57 +0530

    Code refactoring to eliminate duplicate code.

    We were using the similar code to fetch transaction information from
    undo records in multiple places.  Expose a new function to fetch that
    information and use it in all places.

    Patch by Amit Kapila, reviewed and tested by Dilip and Kuntal.

commit a69d8bb6cc49b4bfb3ef0ad8321508007f7e7d66
Author: ashu <[email protected]>
Date:   2017-09-20 16:18:19 +0530

    Allow INSERT/UPDATE/DELETE RETURNING to work with zheap relations.

    Patch by me, reviewed by Amit Kapila, reported by Tushar Ahuja.

commit 9c886fcb2e34d1ec073ce260a032c5fe3a484695
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-19 18:53:55 +0530

    Implement Bitmap Scan for zheap

    Reviewed by Amit Kapila

commit 113966f8755edabf26ce62eb54798a5bdb419911
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-19 23:44:47 +0530

    Implement COPY-TO for zheap relations

    Reviewed by Amit Kapila

commit 414f84fd6026b0e282c10b9fe01f40898d5a22a4
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-20 00:12:16 +0530

    Index Scan for spgist,gist,hash

    Reviewed by Amit Kapila

commit 95e893242410969de851bdf746b54b69292134ec
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-20 13:57:24 +0530

    Skip vacuum for zheap relations

    Tell autovacuum worker to skip zheap relations for vacuum. Also,
    throw appropriate error if one intends to vacuum zheap relations
    with VACUUM command.

    Reviewed by Amit Kapila, Dilip Kumar

commit e33f25249fc55d24c919d345b233a12b27e00db2
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-18 16:24:18 +0530

    Handle MinimalTuple for ztuple

    Reviewed by Amit Kapila, Ashutosh Sharma

commit f0d0850e99b3303a913a3f06998e120f052b0440
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-19 22:33:23 +0530

    Fix Oid crash in ExecInsert

commit aa0eefadeee806f7691cbe2374a942e771ca8d30
Author: dilip <[email protected]>
Date:   2017-09-19 12:14:37 +0530

    zheap mvcc routine was not set properly in RestoreSnapshot
    which was causing problem in parallel query.  This commit
    fixes the issue

commit e43b9eeeb33b7cce358e4a1bede6623151bb4101
Author: ashu <[email protected]>
Date:   2017-09-18 22:06:22 +0530

    Correct the XLOG record type used in UndoLogSetLastXactStartPoint().

    RM42384, Ashutosh Sharma, reviewed by Dilip Kumar and reported by
    Mithun CY.

commit 2edda475a0c19b293d61f657c02a4b38221765f5
Author: Amit Kapila <[email protected]>
Date:   2017-09-18 14:49:31 +0530

    Retrieve CTID from undo record when requested.

    Reported by Neha Sharma.

commit f34620869854458a3a671c2112b38109fc240af2
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-15 12:11:23 +0530

    Move BulkInsertStateData def to genham.h

commit 7b30e2d13b1ef23d19ba0d1c521e901d50be21ec
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-14 14:41:27 +0530

    Fix comment style in zheap_multi_insert

commit 91094f3776e5aa18b71fb0360d5e754b128998ae
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-14 13:51:35 +0530

    Implement COPY FROM command for zheap relations

    Reviewed by Amit Kapila, tested by Ashutosh Sharma

commit e7de2741292bfce5ddb7c69c102010f1dc81e2ed
Author: Kuntal Ghosh <[email protected]>
Date:   2017-07-21 12:00:38 +0530

    Add options in zheap_prepare_insert like heap_prepare_insert.

    Reviewed by Amit Kapila

commit 1d9f79cf415be06824f8893c5e6cdb58bdde3f18
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-13 13:40:44 +0530

    Fix warnings in zheapgettup_pagemode

commit fba570c012c02b96bb3817e33763f03dde1248a1
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-12 15:37:26 +0530

    Isolation tests for non-inplace updates

    Reviewed by Amit Kapila

commit 51fb8188e05d92a973ee14a057c956fec2caab93
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-12 15:42:22 +0530

    Regression tests for non-inplace updates

    Reviewed by Amit Kapila

commit 039efbc45bb68a11db71ed0137d619af07951b54
Author: Amit Kapila <[email protected]>
Date:   2017-09-11 17:40:21 +0530

    Fix usage of tuple in visibility API.

    ZHeapTupleSatisfiesVisibility API doesn't guarantee that the tuple
    passed won't be freed, so we can't reuse it.

commit ff452720310a3a8cbb27ff85625a5276110f9de2
Author: Amit Kapila <[email protected]>
Date:   2017-09-11 17:26:27 +0530

    Support non-inplace-updates

    Allow tuples to be updated such that a newer version of tuple will be
    stored separately if any index column is updated or length of new
    tuple is greater than old tuple.

    For undo generation, we always generate two undo records one for the
    deletion of old tuple and another for addition of new tuple.  We need
    separate undo record for new tuple because during visibility checks we
    sometimes need commandid and that is always stored in undo record.  To
    reach new tuple from old tuple, we need ctid which is stored in old tuples
    undo record.

    Patch by me, review and test by Dilip Kumar and Kuntal Ghosh.

commit 918aea9d904dd4f2ea82c8e4b0aefd7006cedce8
Author: dilip <[email protected]>
Date:   2017-09-11 16:44:26 +0530

    Support multi-prepare for undo record

    This will support preparing multiple undo record and all of
    them can be inserted with one call of InsertPreparedUndo.

    Reviewed by Amit Kapila.

commit 4df6058209a1028f328b5976315b9373d8385afc
Author: dilip <[email protected]>
Date:   2017-09-07 10:57:14 +0530

    Fix compilation warning

commit 3d9616d314008d2c34942d50d81d40558a771eda
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-06 18:19:48 +0530

    CREATE INDEX on non-empty zheap relations

    This extends the implementation for index creation on zheap
    relations to non-empty relations as well.
    Patch by me, reviewed by Amit Kapila

commit 295f464ede2c243c7872cd3bc48b4d022b4cf9d8
Author: Amit Kapila <[email protected]>
Date:   2017-09-06 15:15:30 +0530

    Implement and ZHeapTupleSatisfiesAny and
    ZHeapTupleSatisfiesOldestXmin

    Both these API's are required by upcoming patch to create index.
    These API's implement functionality similar to the heap API's
    HeapTupleSatisfiesAny and HeapTupleSatisfiesVacuum, but for zheap
    tuples.

commit a1bbc57456a2c0985aad6ca14042ff8690275b9b
Author: Kuntal Ghosh <[email protected]>
Date:   2017-09-01 17:07:30 +0530

    storage_engine can not be modified after table creation

    storage_engine can be set during CREATE TABLE. But, it can't be
    set/reset using ALTER TABLE later.

    Patch by me, reviewed by Mithun CY

commit 01e757ed5ff8e86fdece673c2dcee9d737628c5f
Author: dilip <[email protected]>
Date:   2017-09-04 16:59:52 +0530

    RM42314: Fixes one part of the problem

    Implements better way to know whether the undo record
    is discarded or not instead of adding the TRY_CATCH as
    done in current code.

commit fc5e48996af7ea9398aed4adfce093ba7bba3c53
Author: mithun <[email protected]>
Date:   2017-09-04 11:58:16 +0530

    RM41618: Asynchronous Undo Management - Undo BgWorker Part.

    Improved the log messages.

commit 7231d04084c1d305c374c91c8ac9328186ae90e2
Author: Amit Kapila <[email protected]>
Date:   2017-09-01 15:30:39 +0530

    Fix typo in error message

commit b9746b046d25e8db6c36cd28bd49e72f650e3552
Author: mithun <[email protected]>
Date:   2017-09-01 11:39:53 +0530

    RM41618: Asynchronous Undo Management - Undo BgWorker Part.

    registered a SITERM handler for undoworker.
    Review by Kuntal.

commit fec2d893806c3b163d4c96e6c2864361ad2eccae
Author: ashu <[email protected]>
Date:   2017-08-31 17:15:20 +0530

    Implement PRIMARY KEY for zheap relations.

    This patch allows PRIMARY KEY to be created on zheap relations.
    For now, all it does is, throw an error message, if user tries
    to add a NULL or duplicate value on primary-key column (i.e. when
    primary key constraint is violated) but it doesn't protect it
    from getting inserted into a zheap table as currently ROLLBACK is
    not implemented in zheap. Therefore, if users tries to violate a
    primary key constraint on zheap table, it will result into a data
    corruption.

    RM42103, Ashutosh Sharma, reviewed by Kuntal Ghosh and Amit Kapila.
    Few adjustments done by Amit Kapila.

commit 5b704a091e300d12f18e0bba4d6e2083fd652d0b
Author: mithun <[email protected]>
Date:   2017-08-30 08:25:40 +0530

    RM41618: Asynchronous Undo Management - Undo BgWorker Part.

    One undoworker's launcher process which calls a loop to
    periodically examine and discard undos of transactions
    which are visible to all.

    This is a very basic form of undoworker which can be used
    by undo subsystem for discarding undos. This code will
    later evolve into a more complex undoworker subsystem.

commit 1c16e16158d83850c20602acce9b6ab5e8833b7c
Author: dilip <[email protected]>
Date:   2017-08-29 18:20:28 +0530

    Discard Interfaces for undo worker

    Provide an interface to discard all the undo which are inserted by the
    transaction id which is smaller than input xid.  This will also calculate
    the oldestXidHavingUndo.

    Reviewed by Amit Kapila

commit 5e7384fc7d2684ca0714147a0a1c60fdeed8d7fd
Author: dilip <[email protected]>
Date:   2017-08-29 18:19:07 +0530

    Inserting a transaction header in the undo record.

    Insert a transaction header in the first undo record by the transaction. This
    header will contains the undo record ptr of the next transactions first undo
    log.  This will be used by discard api’s to process a undolog transaction by
    transaction.

    Reviewed by Amit Kapila

commit 72ca11a0fe330abd69958c361ecf8fde2369802f
Author: dilip <[email protected]>
Date:   2017-08-29 17:58:11 +0530

    Protection against accessing the discarded undo.

    This is a dirty way to handle the problem, we may need to find some
    better way for the same.

    Reviewed by Amit Kapila

commit 35c917a1e21c1c17c7de0d026c0820ac4086c0a2
Author: mithun <[email protected]>
Date:   2017-08-29 16:16:55 +0530

    RM42266: Support no movement scans for zheap.

    It seems the NoMovementScanDirection is a dead code for
    heap itself. So got rid of related code in zheap and added
    an Assert(false) to indicate same.

commit 38a4d0037a5636e08e00a4e3a352a4b1ded8ba61
Author: Kuntal Ghosh <[email protected]>
Date:   2017-08-29 15:27:29 +0530

    Make PageSetUNDO less chatty

commit 44c19cc1a6db1c8bd6a4d21b17d1549c059c77d1
Author: Thomas Munro <[email protected]>
Date:   2017-08-28 23:00:23 +1200

    Fix build problem on Windows.

    On Windows we have a macro wrapping open() that always needs three arguments.
    Per complaint from Amit Kapila.

commit 1302ec61e5bb482789db809c344b3fed5a9d6dae
Author: Amit Kapila <[email protected]>
Date:   2017-08-28 15:57:26 +0530

    Change ValidateTuplesXact so that it always get the fresh copy of
    tuple.

    If the tuple is updated such that its transaction slot has been changed,
    then we will never be able to get the correct tuple from undo. To avoid
    that we get the latest tuple from page rather than relying on it's
    in-memory copy.

    Amit Kapila and Dilip Kumar

commit 531f8bf739266d5d0e40512a983cc5b757689810
Author: Amit Kapila <[email protected]>
Date:   2017-08-28 15:11:39 +0530

    Add comments in code to explain the usage of commandid while
    traversing undo chain.

commit bd9d5215d2deff90615d8108cbdad07d8d4894df
Author: Amit Kapila <[email protected]>
Date:   2017-08-28 14:46:32 +0530

    Improve comments in code.

commit 91416a25cd2f950a7de078d7661f18e411962c15
Author: Amit Kapila <[email protected]>
Date:   2017-08-28 14:43:11 +0530

    Always write complete tuple in undo of delete.

    This will ensure that we can reuse the space of deleted tuples as soon
    as the transaction commits.

commit e63edb162c3a18acc7dc10e9510b24b53d2ddfda
Author: Amit Kapila <[email protected]>
Date:   2017-08-28 14:23:54 +0530

    Fixed few warnings.

commit ed04b0bc3a955f0abfe712626c13dd3734a3676c
Author: ashu <[email protected]>
Date:   2017-08-25 13:18:05 +0530

    Remove isolation test for REPEATABLE READ mode and rename mvcc.spec
    file with zheap prefix.

    Commit 0fd69d86 unintentionally added isolation test for REPEATABLE
    READ mode. But unfortunately, zheap is currently just restricted to
    READ COMMITTED mode. Hence, this commit removes the test added for
    REPEATABLE READ mode and it also renames the test file with zheap
    prefix.

    Patch by Kuntal Ghosh, reviewed by me.

commit 953868285ef6d57c83a246603d5e3b615b837b3a
Author: Amit Kapila <[email protected]>
Date:   2017-08-24 21:17:31 +0530

    Allow transaction slots to be reused after transaction is finished.

    To reuse the slot, it needs to ensure that (a) the xid is committed
    and all-visible (b) if the xid is committed, then write an undo
    records for all the tuples that belong to that slot.  The undo record
    will cover the transaction information of committed transaction. The
    basic idea is that after reuse of slot, if someone still needs to find
    the information of prior transaction that has modified the tuple, the
    same can be retrieved from undo.

    We can reuse the slot even after the transaction has aborted, but for
    that we need to have Rollback facility which is currently not
    implemented, so we can't reuse slots of aborted transactions.

    Amit Kapila and Dilip Kumar.

commit 13de424924220e65ec7348687210e3752ad0fd50
Author: Kuntal Ghosh <[email protected]>
Date:   2017-08-22 17:13:52 +0530

    Fix crash in EvalPlanQualStart during isolation check

    We can't use es_result_relation_info in EvalPlanQualStart to decide
    the type of the underlying relation. Instead, We can use es_range_table.

    Reported by Amit Kapila.

commit 10c6bff9873d3ce203eb0368ee262a67d6f43d79
Author: Kuntal Ghosh <[email protected]>
Date:   2017-08-11 15:54:28 +0530

    Deform zheap tuples for aggregate nodes

    Aggregate nodes don't recognize zheap tuples. To fix this,
    we deform a zheap tuple in ExecCopySlotTuple and form a heap
    tuple from the same.

commit 61d3d5e7178203d3070a11872bcdc64d365fce16
Author: Kuntal Ghosh <[email protected]>
Date:   2017-08-21 17:25:12 +0530

    Fix type of urec_fork in UndoRecordRelationDetails

commit 3d390e874b93b8f265520d2381cd5227f6f8f60c
Author: ashu <[email protected]>
Date:   2017-08-18 16:26:43 +0530

    Add some isolation tests to validate MVCC model with zheap.

    Thomas Munro and Ashutosh Sharma (The original patch here was
    by Thomas Munro and it was for heap storage, but I ported
    it to zheap.)

commit 89466c9b213f939809de73ae21e8ec939cec1925
Author: dilip <[email protected]>
Date:   2017-08-07 14:35:11 +0530

    Mark buffer dirty after inserting the undo record in undo buffer.

    Reported by Thomes and Amit.

commit 8fec492113e3f03eeea42063b23b530b689bfd8e
Author: Thomas Munro <[email protected]>
Date:   2017-08-05 21:10:32 +1200

    Correct comment.

commit e5818f2fd0b55cab123926db0afc52e832d44dd6
Author: Thomas Munro <[email protected]>
Date:   2017-08-05 21:08:17 +1200

    Define a macro UndoRecPtrFormat for use in printf-style functions.

commit 5eedbd8378b0b32cee25ff882a78082a273ac9a6
Author: Thomas Munro <[email protected]>
Date:   2017-08-04 16:53:50 +1200

    Git rid of last_size tracking from undo storage layer.

    This problem belongs higher up.

commit 93d94231ef7ff2b30a2c8ae5d795ca9129a0f00d
Author: Thomas Munro <[email protected]>
Date:   2017-08-04 16:47:41 +1200

    Report all UndoRecPtr values as hex in pg_stat_undo_logs.

    Previously raw offsets were shown.  Let's not confuse ourselves with more
    than one representation.

commit 1bc609f9f3943c70e94a3cd409c32c536871f309
Author: Thomas Munro <[email protected]>
Date:   2017-08-04 16:47:14 +1200

    Raise error if you try to access non-existent undo segment.

commit 799820348f683ff7b4120fdd3356ea75e98b757f
Author: Thomas Munro <[email protected]>
Date:   2017-08-04 16:34:31 +1200

    Make test_undo module more cromulent.

    Also change type used for space allocation size_t rather than anything smaller
    so that we can test insertion of large amounts of data at once.

commit def8e64b77cb8e50ac12768f930ee6dbc3785a38
Author: Amit Kapila <[email protected]>
Date:   2017-07-26 17:21:29 +0530

    Update the transaction id in undorecord header

    Separately store the latest transaction id that has changed the tuple
    in the undo record header to ensure that we don't try to process the
    tuple in undo chain that is already discarded. As of now, we are
    using RecentGlobalXmin to prevent it, but up-coming patches that have
    Discard undo mechanism will replace it with oldest_xid_that_has_undo.

commit 5126ec94af589fb56cfcad9f014f6a8c20b16fff
Author: dilip <[email protected]>
Date:   2017-07-26 15:30:05 +0530

    Adding xid in undo header

    Xid will be used by zheap to traverse the undo chain. It
    will not traverse the chain once it get the undo which has
    the xid smaller than OldestXidHavingUndo

commit 7f994a6806858bcc2069004fa16f50d37263dd51
Author: Amit Kapila <[email protected]>
Date:   2017-07-26 15:06:49 +0530

    Support EvalPlanQual mechanism for zheap

    To support evalplanqual mechanism we need to support locking a tuple
    (as of now only now only in LockTupleExclusive mode) to ensure that
    nobody else can update it once the tuple is qualified by this
    mechanism. We also need dirty snapshots to fetch the tuple by tupleid.
    We also need to update ExecScanFetch APIs so that it can recognise
    zheaptuples. We also need to adjust other visibility routines so that
    they can understand locked tuples, similarly we need to adjust
    zheap_update and zheap_delete to account for locked tuples.

    Patch by me, reviewed and tested by Dilip.

commit a4ac11945ae4201bc1c45ddd4ea676841f281cd3
Author: Thomas Munro <[email protected]>
Date:   2017-07-25 05:16:51 +1200

    Improve loop.  Nobody likes degenerate for loops.

commit 4980d572117fc14583af00006e741eedc269a7b3
Author: Thomas Munro <[email protected]>
Date:   2017-07-25 05:13:52 +1200

    Fix UndoLogDiscard().

    Commit d12ea1cec176c3793cb53b6133d413418c338f62 changed the way that the
    offset part of an UndoRecPtr maps to a block number from header exclusive
    to header inclusive, but I failed to change UndoLogDiscard().
    Thanks to Dilip Kumar for diagnosis & fix.

commit fbd05d66d941cb5410c8cc4b3c0bfe1fa4b9f3a6
Author: Kuntal Ghosh <[email protected]>
Date:   2017-07-17 14:49:36 +0530

    Implement Index Scan using btree on zheap relations

    This doesn't include the implementation required for fetching
    multiple versions of a tuple in case of a non-MVCC snapshot.

commit 5d9386b049a6dc61286c4140457ee1d728938fa6
Author: Kuntal Ghosh <[email protected]>
Date:   2017-07-18 10:43:19 +0530

    Implement insertion of zheap tuples in btree index

    It doesn't include the implementation for handling updates on
    key column.

commit f849ed2274727a5c04988fcace73361f79b0346f
Author: Kuntal Ghosh <[email protected]>
Date:   2017-07-17 14:18:16 +0530

    Implement CREATE INDEX on zheap relations USING BTREE.

    This allows creation of btree index on *empty* zheap relations.

commit 0bab411eeb75256cbcb6e58cf99b493d59158ce3
Author: Amit Kapila <[email protected]>
Date:   2017-07-14 10:12:17 +0530

    Define and use InvalidUndoRecPtr.

commit 64433f17dd08fa2db21af689ff673abf16d863ff
Author: Kuntal Ghosh <[email protected]>
Date:   2017-07-11 17:04:22 +0530

    Fix an assert failure in PrepareUndoInsert

commit 80878d1097ae747de6b257e8be911c16fd57196b
Author: Kuntal Ghosh <[email protected]>
Date:   2017-07-04 12:32:00 +0530

    Fix 'storage_engine' reloption to support case-insensitive inputs

commit 9d4097fad8db35add630b7da9b98b3d0e95dcfbe
Author: Thomas Munro <[email protected]>
Date:   2017-06-30 23:56:14 +1200

    Change the way that undolog.c accounts for page headers.

    Previously, the offset component of UndoRecPtr was a counter of usable bytes
    within the undo log.  Now it's straight physical offset into the undo log.
    This means that it's now possible to have a (corrupt) UndoRecPtr that points
    at header data, which is nonsensical, but it makes a lot of things simpler.
    Now segment filenames, insert, discard, end offsets and UndoRecPtr values are
    all based on the same scale: number of raw bytes from the start of the undo
    log, regardless of whether those are header or data bytes.

    Previously, UndoLogAllocate advanced the insert pointer by the exact number
    of bytes requested in the 'size' argument.  That was unusable because it
    required the caller to allocate header space this way too, and do a bunch of
    math that required knowing where the insert point already was.  Now 'size'
    means usable bytes; header bytes are automatically accounted for.

    Based on a complaint from Dilip.  Let's try it this way and see if it makes
    more sense.

commit 717961ad5ae25a6cfad73f7843e718a36b0f889b
Author: dilip <[email protected]>
Date:   2017-06-30 10:29:32 +0530

    Fix defect in undo record API

    In the earlier version there was an assumption that
    at least undorecor header will fit into the buffer,
    but actually that was not true undo record header
    can also split across 2 buffers, the same has been
    fixed.

commit c3cd40c69a91cee5d71fb04432393e49b8b62302
Author: dilip <[email protected]>
Date:   2017-06-29 16:26:48 +0530

    Fix compilation warning in undolog.c

commit a56bc2ce68de378fd73f31e48a127f0620c8fc48
Author: Amit Kapila <[email protected]>
Date:   2017-06-29 16:13:38 +0530

    Store command id in undo records.

    Till now, there was a primitive implementation of command id.  We were
    storing the command id in transaction slots, but that won't work for
    tuples stored in undo records.  Now, store the command id in undo
    record and fetch it from undo records during visibility checks.

commit abef75d8885d21857afbc9d4487628807e913cb4
Author: dilip <[email protected]>
Date:   2017-06-29 15:44:44 +0530

    Support for command ID in undorecord header

commit 779cb3080bf4e4862cd008aa902b55029f545f4e
Author: dilip <[email protected]>
Date:   2017-06-27 10:09:24 +0530

    Bug fix in undo buffer list: Reset the undo buffer list

commit 99f1adcf642e102df9f87f4763ca299ff0a57733
Author: Amit Kapila <[email protected]>
Date:   2017-06-23 20:45:43 +0530

    Support reuse of transaction slots

    Currently the zheap page has four transaction slots which means that
    there can't be more than four active transactions operating on a page.
    After four transactions the system will start waiting, this commit
    will allow to reuse the transaction slots.  The transaction slot can
    reuse if the transaction is committed and all-visible or if it is
    aborted then the undo has been applied.  As of now, we don't have
    rollback support so we just rely on the first check to reuse the slot.

commit 3d850d24e8aa04087ca55ebf9319e6b56ec5ec63
Author: Amit Kapila <[email protected]>
Date:   2017-06-23 20:32:51 +0530

    Support Zheap in-place update and delete operations

    This allows zheap tuples to be updated in-place and marked as deleted.
    This also supports visibility checking for snapshots and traversing
    the undo chains for non-visible tuples.  As of this commit, the
    support for snapshot visibility with respect to command id is not
    complete and can give wrong answers.  The future commit will support
    the same.

commit 9fe80770ed32020cac9487f93cdf542cd070c4fa
Author: dilip <[email protected]>
Date:   2017-06-23 16:53:26 +0530

    Fix warning in undolog and undorecord

commit 3075d2186e45ca0fe14add50d1a8bdf82de7e85f
Author: dilip <[email protected]>
Date:   2017-06-23 16:48:07 +0530

    Undo API for inserting and fetching the undo records from undo storage

    Undo API is an interface on top of the undo log storage which provides
    a way to insert and fetch records from undo logs. The API internally
    manages the buffers and performs encoding and decoding the undo records.

commit 21d2703d218f05c28638e1ec98559d357e4b94f8
Author: Thomas Munro <[email protected]>
Date:   2017-06-22 10:27:23 +1200

    Changed interface of UndoLogDiscard based on feedback.

    Previously it took old pointer and size.  Now it just takes the new pointer.
    In other words you call it with the address of the oldest byte you would
    like to keep.

    Also updated various comments, changed the pg_stat_undo_logs view a bit
    and fixed the rules.out to reflect that.

commit 10ccdce79fed7a4dd42321198c8f8a1e9bd26dda
Author: Thomas Munro <[email protected]>
Date:   2017-06-21 13:59:31 +1200

    Implemented UndoLogDiscard and related things.

    Now able to discard and recycle segment files on master and standby.
    Assorted other changes: using an LWLock per undo log, instead of a SpinLock.
    Using base/undo rather than base/9 to hold undo segment files.  Renamed
    segment files as logno.offset, so that they also tell you the UndoRecPtr
    of the first byte in the segment.  Got rid of the separate tracking of
    'mvcc' and 'rollback' discard pointers; I don't think that's my job, instead
    there is just a single 'discard' pointer.  Renamed 'capacity' to 'end'.

    There is plenty more work to be done here...

commit 502d0afd95e3b7a6bb089be6efed35ed24cec96e
Author: Thomas Munro <[email protected]>
Date:   2017-06-19 15:45:41 +1200

    Fix double lock release bug in ForgetBuffer

    Don't try to release the partition lock twice if we failed to find the
    buffer.

commit 32ca66260db1675f7fce94e59dbc55d9057bdfdd
Author: Thomas Munro <[email protected]>
Date:   2017-06-01 17:07:43 +1200

    Early prototype code for undo log storage.

    Includes a backport of 767bc028e5f001351feb498acef9a87c123093d6 because
    we need to be able to create pinned DSM segments without creating a bogus
    ResourceOwner first.

commit 80bb5103f41d28052c8cd11f5393de6eaf1522cd
Author: Kuntal Ghosh <[email protected]>
Date:   2017-06-06 21:47:46 +0530

    Fix return type for zheap_insert

commit 51f5293a475d6e2175f4e5d87978308e3d7b0a60
Author: Kuntal Ghosh <[email protected]>
Date:   2017-06-04 19:36:14 +0530

    Fix NULL pointer access in RelationStorageIsZHeap

commit 7c4f86a14b93151c9281a7cab3408b9d040fee88
Author: Amit Kapila <[email protected]>
Date:   2017-06-02 16:16:23 +0530

    Change UNDO Insert tuple contents.

    As per current understanding, we don't need to store any information
    about in undo insert as the command id (cid) is also stored in
    transaction slot.

commit 31142f2fcde9e84baf531feb4187505dbaf2259d
Author: Amit Kapila <[email protected]>
Date:   2017-06-02 16:12:42 +0530

    Few defines for zheap tuple

    Define infomask flags required for zheap tuples. One of these flags is
    required for the already committed code in commit
    a3bb8c3411d1a17fb190b5757bf181d38900800a.

commit feea62deb7528b7525090e6623cfc2482c6d20e0
Author: Amit Kapila <[email protected]>
Date:   2017-06-02 15:40:44 +0530

    Implement getsysattribute function for zheap.

    This is required for upcomimng zheap delete operation patch.
    Attributes related to transaction information won't give correct
    information for all cases.  I have added Fixme in code which needs
    to be fixed at later time when we need to use those attributes.

commit 7d7bb25644ad0a3fd234e6185d21151e7a7e8af0
Author: Amit Kapila <[email protected]>
Date:   2017-06-02 07:22:28 +0530

    Initialize Zheap page with appropriate special space size.

commit 7598316c1645db0e8d7eee55c45a529d5d426544
Author: Kuntal Ghosh <[email protected]>
Date:   2017-06-01 18:13:11 +0530

    Add a 'storage_engine' reloption.

    The code that decides which storage should be used for a relation.
    Allowed values are 'heap' and 'zheap'. The default value for this
    options is 'heap'. Also, it adds a macro 'RelationStorageIsZHeap(relation)'
    which can be used to decide whether a relation uses zheap or not.

    Patch by me, reviewed by Mithun C Y

commit 2d8452096418348c6f406b595cc75903fde38b61
Author: Kuntal Ghosh <[email protected]>
Date:   2017-05-31 12:00:05 +0530

    Support query quals for ZHeap

    It implements the qualification check of column names for a ZHeap tuple.

commit a0ae8ceb08757b0cdce77780c87267b6dbc7de1f
Author: Amit Kapila <[email protected]>
Date:   2017-05-30 16:31:54 +0530

    ZHeap Tuple visibility checks

    Implements the basic zheap tuple visibility skeleton wherein we can
    verify if the inserted tuple is visible to our command. The basic idea
    used is to have few transaction slots (as of now four, needs some
    testing to determine the exact number) in special space of zheap page.
    Each write operation on page first needs to reserve transaction slot
    in the page and update the same in tuple header and then proceed with
    the actual operation. We need to reserve two bits in tuple header to
    remember the information of transaction slot. There is a need of
    additional bit to indicate no tranasction slot in which case tuple
    will be all-visible.  This usage of additional bit will be implemented
    as a separate commit.  As of now, each transaction slot contains xid,
    cid and undo_rec_ptr which helps us to determine tuple visibility. We
    might not need cid in transaction slot as that can be retrieved from
    undo, however keeping it in page saves us from fetching undo record
    pointer in many cases and due to alignment, it doesn't cost us much
    space wise.

commit 74983024bedce424427bec359f8f0c0f0615a774
Author: Amit Kapila <[email protected]>
Date:   2017-05-17 10:59:55 +0530

    Handle cases for data_alignment = 4.

    Currently for four-byte alignment, we align everything to four-byte
    boundary which is not what we want for typalign 'c' or 's'.  So align the
    given offset as per attalign for char and short alignment and at four-byte
    boundary for other values of attalign.

    Patch by me, reported by Robert Haas.

commit a802bb024f8041c0122419729c86611f592a262e
Author: Amit Kapila <[email protected]>
Date:   2017-05-11 12:12:49 +0530

    Support basic seqscan operation for ZHeap.

    Make HeapScanDesc aware of ZHeapTuple, this is required to scan. We
    could create a separate ZHeapScanDesc, but at this stage, I don't see
    the need of same. I have written Zheap scan API's like zheap_getnext,
    zheap_beginscan, etc. As for inserts, it doesn't seem advisable to add
    a lot of if..else checks in heap scan API's to support Zheap tuple
    format. Apart from tuple format, we can't directly use heap visibility
    routines (fetching transaction info from tuple will be different),
    although I have yet to implement the same. Also, we might want to copy
    the zheap tuple before releasing buffer lock as zheap tuples can be
    updated in-place.

    Note that with this patch only select * from <table_name> can work, to
    make where clause work, we need to change few other *get_attr api's so
    that they can understand zheaptuple format.

commit ffbc3b0a84451e365457e7a1d1d31a15cd1366cd
Author: Amit Kapila <[email protected]>
Date:   2017-05-02 08:41:19 +0530

    Set Tag needs to use zheap tuple when zheap is enabled.

commit 63ba474f0d69a4123129ffa4849548e9d53a0146
Author: Amit Kapila <[email protected]>
Date:   2017-05-02 08:22:29 +0530

    Mark data_alignment_zheap as PGDLLIMPORT.

    This is so that extensions can use it.

commit 058618921b6f6319eb4f86909058a5a274fcabd0
Author: Amit Kapila <[email protected]>
Date:   2017-05-02 08:17:16 +0530

    Remove spurious whitespace.

commit 171bfaeeca96c2186ba45e5f9930df2cf7eeb5ee
Author: amitkapila <[email protected]>
Date:   2017-05-02 07:54:16 +0530

    Add missing Makefile in zheap directory.

    Commit 53643b6589a6b963b8621e3173d505383d510bb5 forgot to add Makefile
    for zheap directory.

commit e70c0c4404021ece54e8bdcb9ce2ec6d3c2d87eb
Author: amitkapila <[email protected]>
Date:   2017-04-28 15:38:56 +0530

    Change max heap tuples per page.

    With shorter tuple headers, the maximum number of tuples that can fit
    on a page have significantly increased.  So changed the calculation in
    API's required for insert operation.  I have choosen to expose new
    API's as doing checks for type of heap in such lower level API's
    doesn't seem sensible.

    For now, I have added new page level api's in zheapam.c.  I think
    later we might want to split them into a separate file.

commit 22449b025419c176ed74464ee26bbcc46125a63e
Author: amitkapila <[email protected]>
Date:   2017-04-28 14:56:44 +0530

    Support unaligned inserts in zheap.

    A new guc data_alignment has been introduced to decide the alignment
    of tuple data.  The data_alignment value 0 indicates no alignment,
    value 4 indicates align everything at 4 byte boundary and any other
    value indicates align as per typalign of the attribute.  The main
    objective of this commit is test the size of data with different
    alignments.

    Based on test results we might want to retain one type of alignment
    and remove this GUC and associated code.

commit eaf9f4b054e9d8e7bfd2fc86bf7c7f4e51a04e20
Author: amitkapila <[email protected]>
Date:   2017-04-28 12:24:29 +0530

    Support Zheap Insert Operation.

    The main idea of this patch is to support a short tuple header (3
    bytes instead of 24 bytes). As of this patch, I have kept tuple
    header aligned to 8-bytes and tuple data alignment works as for main
    heap. This doesn't include support for toast inserts or speculative
    inserts (Insert .. On Conflict). Also, we don't support selects. As
    of now, the support for undo record is dummy which means records are
    formed, but not stored. Similarly for WAL, there is support of XLOG
    record insertion, but replay is not done as that also needs some support
    from undo. I have added a guc enable_zheap to perform zheap inserts
    which needs to be changed to reloption or something else, but it serves
    the purpose as of now.

commit ba5b2b31bbd9d8053be2416fb0cad0fda64df053
Author: Robert Haas <[email protected]>
Date:   2017-03-05 10:18:45 +0530

    Throw-away test code for UndoRecordInsert.

commit daadef317fa3b8453115ac24c351faed5f277ffd
Author: Robert Haas <[email protected]>
Date:   2017-03-05 08:07:52 +0530

    Implement UndoRecordExpectedSize and InsertUndoRecord.

commit fe886f35e8b257c6a24fa3729df26432dfb52881
Author: Amit Kapila <[email protected]>
Date:   2017-02-24 11:42:16 +0530

    update comment to reflect function name changed in
    commit 29f4db6d7a158c75fc152351f874b8d4e6af63a0.

commit 0c79dde27afa0d432ed53ad7c353204560500611
Author: Thomas Munro <[email protected]>
Date:   2017-02-23 16:19:10 +0530

    Added bootstrap interface; tidied

commit b05429f48e3e7104e84428a81884055569e1006d
Author: Thomas Munro <[email protected]>
Date:   2017-02-23 14:57:08 +0530

    An early draft of undolog.h.

commit cc1c4927fbc236559c6831ab583f1600c96a543d
Author: Robert Haas <[email protected]>
Date:   2017-02-23 14:41:05 +0530

    Rename DropBuffer to ForgetBuffer, change API a bit, implement.

    Also, implement ForgetLocalBuffer.

commit 954bf571a3e332e5d0dd16f6ec2eb4c11d7962cf
Author: Amit Kapila <[email protected]>
Date:   2017-02-23 14:02:03 +0530

    Expose the DropBuffer API.

    We don't need a new header file just to expose one API.
    So move the API to bufmgr.h and remove the undobuf.h.

commit 28ca1b57f1d509657d6c77eaf07fd0af395e2e5b
Author: Amit Kapila <[email protected]>
Date:   2017-02-23 12:04:24 +0530

    draft header files for undoworker, undoloop and undobuf.

6 years agoWIP: Don't reset context across table_scan_getnextslot() calls.
Andres Freund [Thu, 6 Dec 2018 01:28:49 +0000 (17:28 -0800)]
WIP: Don't reset context across table_scan_getnextslot() calls.

That currently crashes zheap, but I'm doubtful this is the right fix.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoWIP: Fetch tuples for triggers & EPQ using a proper snapshot.
Andres Freund [Tue, 11 Dec 2018 00:13:45 +0000 (16:13 -0800)]
WIP: Fetch tuples for triggers & EPQ using a proper snapshot.

This is required for zheap, where tids don't uniquely identify a
tuple, due to in-place updates.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

tmp

6 years agoWIP: pluggable init fork creation, relation size estimation, file creation.
Andres Freund [Thu, 6 Dec 2018 04:09:05 +0000 (20:09 -0800)]
WIP: pluggable init fork creation, relation size estimation, file creation.

This doesn't yet really work.

6 years agoPluggable Storage.
Andres Freund [Tue, 11 Dec 2018 01:36:11 +0000 (17:36 -0800)]
Pluggable Storage.

Author: Haribabu Komi, Andres Freund and others.
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoslot type fixes
Andres Freund [Thu, 6 Dec 2018 01:27:40 +0000 (17:27 -0800)]
slot type fixes

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoFix parent of WCO qual.
Andres Freund [Thu, 6 Dec 2018 01:28:05 +0000 (17:28 -0800)]
Fix parent of WCO qual.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoWIP: ForceStore HeapTupleDatum
Andres Freund [Tue, 4 Dec 2018 19:11:09 +0000 (11:11 -0800)]
WIP: ForceStore HeapTupleDatum

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoMove vacuumlazy.c into access/heap/
Andres Freund [Wed, 3 Oct 2018 15:01:02 +0000 (08:01 -0700)]
Move vacuumlazy.c into access/heap/

It's heap table storage specific code that can't realistically be
generalized into table AM agnostic code.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoWIP: Fix tuple extension logic.
Andres Freund [Mon, 3 Dec 2018 20:56:23 +0000 (12:56 -0800)]
WIP: Fix tuple extension logic.

Author:
Reviewed-By:
Discussion: https://postgr.es/m/
Backpatch:

6 years agoAdd stack depth checks to key recursive functions in backend/nodes/*.c.
Tom Lane [Mon, 10 Dec 2018 16:12:43 +0000 (11:12 -0500)]
Add stack depth checks to key recursive functions in backend/nodes/*.c.

Although copyfuncs.c has a check_stack_depth call in its recursion,
equalfuncs.c, outfuncs.c, and readfuncs.c lacked one.  This seems
unwise.

Likewise fix planstate_tree_walker(), in branches where that exists.

Discussion: https://postgr.es/m/30253.1544286631@sss.pgh.pa.us

6 years agoDoc: remove obsolete reference to recursive expression evaluation.
Tom Lane [Mon, 10 Dec 2018 15:44:06 +0000 (10:44 -0500)]
Doc: remove obsolete reference to recursive expression evaluation.

John Naylor

Discussion: https://postgr.es/m/CAJVSVGUPH-0q5feP4v9b+Y8K3HGTn3bEd5KV7VbyUj-oFdSLzA@mail.gmail.com

6 years agoMake TupleDescInitBuiltinEntry throw error for unsupported types.
Tom Lane [Mon, 10 Dec 2018 15:38:48 +0000 (10:38 -0500)]
Make TupleDescInitBuiltinEntry throw error for unsupported types.

Previously, it would just pass back a partially-uninitialized tupdesc,
which doesn't seem like a safe or useful behavior.

Backpatch to v10 where this code came in.

Discussion: https://postgr.es/m/30830.1544384975@sss.pgh.pa.us

6 years agoAdd pg_dump test for empty OP class
Stephen Frost [Mon, 10 Dec 2018 15:13:52 +0000 (10:13 -0500)]
Add pg_dump test for empty OP class

This adds a pg_dump test for an empty operator class.

Author: Michael Paquier
Discussion: https://postgr.es/m/20181208011142[email protected]

6 years agoAdd additional partition tests to pg_dump
Stephen Frost [Mon, 10 Dec 2018 14:46:36 +0000 (09:46 -0500)]
Add additional partition tests to pg_dump

This adds a few tests for non-inherited constraints.

Author: Amit Langote
Discussion: https://postgr.es/m/20181208001735.GT3415%40tamriel.snowman.net

6 years agoRemove dead code in toast_fetch_datum_slice
Stephen Frost [Mon, 10 Dec 2018 14:31:38 +0000 (09:31 -0500)]
Remove dead code in toast_fetch_datum_slice

In toast_fetch_datum_slice(), we Assert() that what is passed in isn't
compressed, but we then later had a check to see what the length of if
what was passed in is compressed.  That later check is rather confusing
since toast_fetch_datum_slice() is only ever called with non-compressed
datums and the Assert() earlier makes it clear that one shouldn't be
passing in compressed datums.

Add a comment to make it clear that toast_fetch_datum_slice() is just
for non-compressed datums, and remove the dead code.

6 years agoEnsure cleanup of orphan archive status files
Michael Paquier [Mon, 10 Dec 2018 06:00:59 +0000 (15:00 +0900)]
Ensure cleanup of orphan archive status files

When a WAL segment is recycled, its ".ready" and ".done" status files
get also automatically removed, however this is not done in a durable
manner.  Hence, in a subsequent crash, it could be possible that a
".ready" status file is still around with its corresponding segment
already gone.

If the backend reaches such a state, the archive command would most
likely complain about a segment non-existing and would keep retrying,
causing WAL segments to bloat pg_wal/, potentially making Postgres crash
hard when running out of space.

As status files are removed after each individual segment, using
durable_unlink() does not completely close the window either, as a crash
could happen between the moment the WAL segment is recycled and the
moment its status files are removed.  This has also some performance
impact with the additional fsync() calls needed to make the removal in a
durable manner.  Doing the cleanup at recovery is not cost-free either
as this makes crash recovery potentially take longer than necessary.

So, instead, as per an idea of Stephen Frost, make the archiver aware of
orphan status files and remove them on-the-fly if the corresponding
segment goes missing.  Removal failures follow a model close to what
happens for WAL segments, where multiple attempts are done before giving
up temporarily, and where a successful orphan removal makes the archiver
move immediately to the next WAL segment thought as ready to be
archived.

Author: Michael Paquier
Reviewed-by: Nathan Bossart, Andres Freund, Stephen Frost, Kyotaro
Horiguchi
Discussion: https://postgr.es/m/20180928032827[email protected]

6 years agoAdd timestamp of last received message from standby to pg_stat_replication
Michael Paquier [Sun, 9 Dec 2018 07:35:06 +0000 (16:35 +0900)]
Add timestamp of last received message from standby to pg_stat_replication

The timestamp generated by the standby at message transmission has been
included in the protocol since its introduction for both the status
update message and hot standby feedback message, but it has never
appeared in pg_stat_replication.  Seeing this timestamp does not matter
much with a cluster which has a lot of activity, but on a mostly-idle
cluster, this makes monitoring able to react faster than the configured
timeouts.

Author: MyungKyu LIM
Reviewed-by: Michael Paquier, Masahiko Sawada
Discussion: https://postgr.es/m/1657809367.407321.1533027417725.JavaMail.jboss@ep2ml404

6 years agoDoc: document that we expect CHECK constraint conditions to be immutable.
Tom Lane [Fri, 7 Dec 2018 21:40:58 +0000 (16:40 -0500)]
Doc: document that we expect CHECK constraint conditions to be immutable.

This restriction is implicit in the check-only-once implementation we use
for table and domain constraints, but it wasn't spelled out anywhere, nor
was there any advice about how to alter a constraint's behavior safely.
Improve that.

I was also dissatisfied with the documentation of ALTER DOMAIN VALIDATE
CONSTRAINT, which entirely failed to explain the use of that feature; and
thence decided that ALTER TABLE VALIDATE CONSTRAINT could be documented
better as well.

Perhaps we should back-patch this, along with the related commit 36d442a25,
but for now I refrained.

Discussion: https://postgr.es/m/12539.1544107316@sss.pgh.pa.us

6 years agoDoc: remove obsolete statements about system OID columns in ALTER TABLE.
Tom Lane [Fri, 7 Dec 2018 19:50:46 +0000 (14:50 -0500)]
Doc: remove obsolete statements about system OID columns in ALTER TABLE.

Missed in commit 578b22971.

6 years agoIn PQprint(), write HTML table trailer before closing the output pipe.
Tom Lane [Fri, 7 Dec 2018 18:11:30 +0000 (13:11 -0500)]
In PQprint(), write HTML table trailer before closing the output pipe.

This is an astonishingly ancient bit of silliness, dating AFAICS to
commit edb519b14 of 27-Jul-1996 which added the pipe close stanza in
the wrong place.  It happens to be harmless given that the code above
this won't enable the pager if html3 output mode is selected.  Still,
somebody might try to relax that restriction someday, and in any case
it could confuse readers and static analysis tools, so let's fix it in
HEAD.

Per bug #15541 from Pan Bian.

Discussion: https://postgr.es/m/15541-c835d8b9a903f7ad@postgresql.org

6 years agoFix misapplication of pgstat_count_truncate to wrong relation.
Tom Lane [Fri, 7 Dec 2018 17:11:59 +0000 (12:11 -0500)]
Fix misapplication of pgstat_count_truncate to wrong relation.

The stanza of ExecuteTruncate[Guts] that truncates a target table's toast
relation re-used the loop local variable "rel" to reference the toast rel.
This was safe enough when written, but commit d42358efb added code below
that that supposed "rel" still pointed to the parent table.  Therefore,
the stats counter update was applied to the wrong relcache entry (the
toast rel not the user rel); and if we were unlucky and that relcache
entry had been flushed during reindex_relation, very bad things could
ensue.

(I'm surprised that CLOBBER_CACHE_ALWAYS testing hasn't found this.
I'm even more surprised that the problem wasn't detected during the
development of d42358efb; it must not have been tested in any case
with a toast table, as the incorrect stats counts are very obvious.)

To fix, replace use of "rel" in that code branch with a more local
variable.  Adjust test cases added by d42358efb so that some of them
use tables with toast tables.

Per bug #15540 from Pan Bian.  Back-patch to 9.5 where d42358efb came in.

Discussion: https://postgr.es/m/15540-01078812338195c0@postgresql.org

6 years agoClean up sloppy coding in publicationcmds.c's OpenTableList().
Tom Lane [Fri, 7 Dec 2018 16:02:39 +0000 (11:02 -0500)]
Clean up sloppy coding in publicationcmds.c's OpenTableList().

Remove dead code (which would be incorrect if it weren't dead),
per report from Pan Bian.  Add a CHECK_FOR_INTERRUPTS in the
inner loop over child relations, because there's little point
in having one in the outer loop if there's not one here too.
Minor stylistic adjustments and comment improvements.

Seems to be aboriginal to this code (cf commit 665d1fad9).
Back-patch to v10 where that came in, not because any of this
is significant, but just to keep the branches looking similar.

Discussion: https://postgr.es/m/15539-06d00ef6b1e2e1bb@postgresql.org

6 years agoDoc: make cross-reference to format() function more specific.
Tom Lane [Fri, 7 Dec 2018 15:41:26 +0000 (10:41 -0500)]
Doc: make cross-reference to format() function more specific.

Jeff Janes

Discussion: https://postgr.es/m/CAMkU=1w7Tn2M9BhK+rt8Shtz1AkU+ty7By8gj5C==z65=U4vyQ@mail.gmail.com

6 years agoFix some errhint and errdetail strings missing a period
Michael Paquier [Thu, 6 Dec 2018 22:47:42 +0000 (07:47 +0900)]
Fix some errhint and errdetail strings missing a period

As per the error message style guide of the documentation, those should
be full sentences.

Author: Daniel Gustafsson
Reviewed-by: Michael Paquier, Álvaro Herrera
Discussion: https://1E8D49B4-16BC-4420-B4ED-58501D9E076B@yesql.se

6 years agoImprove our response to invalid format strings, and detect more cases.
Tom Lane [Thu, 6 Dec 2018 20:08:44 +0000 (15:08 -0500)]
Improve our response to invalid format strings, and detect more cases.

Places that are testing for *printf failure ought to include the format
string in their error reports, since bad-format-string is one of the
more likely causes of such failure.  This both makes it easier to find
and repair the mistake, and provides at least some useful info to the
user who stumbles across such a problem.

Also, tighten snprintf.c to report EINVAL for an invalid flag or
final character in a format %-spec (including the case where the
%-spec is missing a final character altogether).  This seems like
better project policy, and it also allows removing an instruction
or two from the hot code path.

Back-patch the error reporting change in pvsnprintf, since it should be
harmless and may be helpful; but not the snprintf.c change.

Per discussion of bug #15511 from Ertuğrul Kahveci, which reported an
invalid translated format string.  These changes don't fix that error,
but they should improve matters next time we make such a mistake.

Discussion: https://postgr.es/m/15511-1d8b6a0bc874112f@postgresql.org

6 years agoImprove planner stats documentation
Stephen Frost [Thu, 6 Dec 2018 16:39:09 +0000 (11:39 -0500)]
Improve planner stats documentation

It was pointed out that in the planner stats documentation under
Extended Statistics, one of the sentences was a bit awkward.  Improve
that by rewording it slightly.

Discussion: https://postgr.es/m/154409976780.14137.2785644488950047100@wrigleys.postgresql.org

6 years agoCleanup minor pg_dump memory leaks
Stephen Frost [Thu, 6 Dec 2018 16:11:21 +0000 (11:11 -0500)]
Cleanup minor pg_dump memory leaks

In dumputils, we may have successfully parsed the acls when we discover
that we can't parse the reverse ACLs and then return- check and free
aclitems if that happens.

In dumpTableSchema, move ftoptions and srvname under the relkind !=
RELKIND_VIEW branch (since they're only used there) and then check if
they've been allocated and, if so, free them at the end of that block.

Pointed out by Pavel Raiskup, though I didn't use those patches.

Discussion: https://postgr.es/m/2183976[email protected]

6 years agoCleanup comments in xlog compression
Stephen Frost [Thu, 6 Dec 2018 16:05:39 +0000 (11:05 -0500)]
Cleanup comments in xlog compression

Skipping over the "hole" in full page images in the XLOG code was
described as being a form of compression, but this got a bit confusing
since we now have PGLZ-based compression happening, so adjust the
wording to discuss "removing" the "hole" and keeping the talk about
compression to where we're talking about using PGLZ-based compression of
the full page images.

Reviewed-By: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20181127234341[email protected]

6 years agoChange true/false to on/off.
Tatsuo Ishii [Thu, 6 Dec 2018 03:15:15 +0000 (12:15 +0900)]
Change true/false to on/off.

We prefer to use on/off than true/false for boolean configuration
parameters in the documentation, but there were a few places where
true/false were still used.

Dicussion: https://postgr.es/m/20181202.072508.618341295047874293.t-ishii%40sraoss.co.jp

6 years agoDon't mark partitioned indexes invalid unnecessarily
Alvaro Herrera [Wed, 5 Dec 2018 16:31:51 +0000 (13:31 -0300)]
Don't mark partitioned indexes invalid unnecessarily

When an indexes is created on a partitioned table using ONLY (don't
recurse to partitions), it gets marked invalid until index partitions
are attached for each table partition.  But there's no reason to do this
if there are no partitions ... and moreover, there's no way to get the
index to become valid afterwards, because all partitions that get
created/attached get their own index partition already attached to the
parent index, so there's no chance to do ALTER INDEX ... ATTACH PARTITION
that would make the parent index valid.

Fix by not marking the index as invalid to begin with.

This is very similar to 9139aa19423b, but the pg_dump aspect does not
appear to be relevant until we add FKs that can point to PKs on
partitioned tables.  (I tried to cause the pg_upgrade test to break by
leaving some of these bogus tables around, but wasn't able to.)

Making this change means that an index that was supposed to be invalid
in the insert_conflict regression test is no longer invalid; reorder the
DDL so that the test continues to verify the behavior we want it to.

Author: Álvaro Herrera
Reviewed-by: Amit Langote
Discussion: https://postgr.es/m/20181203225019[email protected]

6 years agoFix invalid value of synchronous_commit in description of flush_lag
Michael Paquier [Wed, 5 Dec 2018 01:02:47 +0000 (10:02 +0900)]
Fix invalid value of synchronous_commit in description of flush_lag

"remote_flush" has never been a valid user-facing value, but "on" is.

Author: Maksim Milyutin
Discussion: https://postgr.es/m/27b3b80c-3615-2d76-02c5-44566b53136c@gmail.com

6 years agoFix typo
Stephen Frost [Tue, 4 Dec 2018 16:04:54 +0000 (11:04 -0500)]
Fix typo

Backends don't typically exist uncleanly, but they can certainly exit
uncleanly, and it's exiting uncleanly that's being discussed here.

6 years agopostgres_fdw: Improve cost and size estimation for aggregate pushdown.
Etsuro Fujita [Tue, 4 Dec 2018 08:18:58 +0000 (17:18 +0900)]
postgres_fdw: Improve cost and size estimation for aggregate pushdown.

In commit 7012b132d07c2b4ea15b0b3cb1ea9f3278801d98, which added aggregate
pushdown to postgres_fdw, we didn't account for the evaluation cost and the
selectivity of HAVING quals attached to ForeignPaths performing aggregate
pushdown, as core had never accounted for that for AggPaths and GroupPaths.
And we didn't set these values of the locally-checked quals (ie, fpinfo's
local_conds_cost and local_conds_sel), which were initialized to zeros, but
since estimate_path_cost_size factors in these to estimate the result size
and the evaluation cost of such a ForeignPath when the use_remote_estimate
option is enabled, this caused it to produce underestimated results in that
case.

By commit 7b6c07547190f056b0464098bb5a2247129d7aa2 core was changed so that
it accounts for the evaluation cost and the selectivity of HAVING quals in
aggregation paths, so change the postgres_fdw's aggregate pushdown code as
well as such.  This not only fixes the underestimation issue mentioned
above, but improves the estimation using local statistics in that function
when that option is disabled.

This would be a bug fix rather than an improvement, but apply it to HEAD
only to avoid destabilizing existing plan choices.

Author: Etsuro Fujita
Discussion: https://postgr.es/m/5BFD3EAD.2060301%40lab.ntt.co.jp

6 years agoRefactor documentation about privileges to centralize the info.
Tom Lane [Mon, 3 Dec 2018 16:40:49 +0000 (11:40 -0500)]
Refactor documentation about privileges to centralize the info.

Expand section 5.6 "Privileges" to include the full definition of
each privilege type, and an explanation of aclitem privilege displays,
along with some helpful summary tables.  Most of this material came
out of the GRANT reference page, although some of it is new.
Adjust a bunch of links that were pointing to GRANT to point to 5.6.

Fabien Coelho and Tom Lane, reviewed by Bradley DeJong

Discussion: https://postgr.es/m/alpine.DEB.2.21.1807311735200.20743@lancre

6 years agoAdd some missing schema qualifications
Michael Paquier [Mon, 3 Dec 2018 05:21:52 +0000 (14:21 +0900)]
Add some missing schema qualifications

This does not improve the security and reliability of the touched areas,
but it makes the style more consistent.

Author: Michael Paquier
Reviewed-by- Noah Misch
Discussion: https://postgr.es/m/20180309075538[email protected]

6 years agoAdd PGXS options to control TAP and isolation tests, take two
Michael Paquier [Mon, 3 Dec 2018 00:27:35 +0000 (09:27 +0900)]
Add PGXS options to control TAP and isolation tests, take two

The following options are added for extensions:
- TAP_TESTS, to allow an extention to run TAP tests which are the ones
present in t/*.pl.  A subset of tests can always be run with the
existing PROVE_TESTS for developers.
- ISOLATION, to define a list of isolation tests.
- ISOLATION_OPTS, to pass custom options to isolation_tester.

A couple of custom Makefile rules have been accumulated across the tree
to cover the lack of facility in PGXS for a couple of releases when
using those test suites, which are all now replaced with the new flags,
without reducing the test coverage.  Note that tests of contrib/bloom/
are not enabled yet, as those are proving unstable in the buildfarm.

Author: Michael Paquier
Reviewed-by: Adam Berlin, Álvaro Herrera, Tom Lane, Nikolay Shaplov,
Arthur Zakirov
Discussion: https://postgr.es/m/20180906014849[email protected]

6 years agoEliminate parallel-make hazard in ecpg/preproc.
Tom Lane [Sat, 1 Dec 2018 22:19:51 +0000 (17:19 -0500)]
Eliminate parallel-make hazard in ecpg/preproc.

Re-making ecpglib's typename.o is dangerous because another make thread
could be doing that at the same time.  While we've not heard field
complaints traceable to this, it seems inevitable that it'd bite someone
eventually.  Instead, symlink typename.c into the preproc directory and
recompile it there.  That file is small enough that compiling it twice
isn't much of a penalty.  Furthermore, this way we get a .o file that's
made without shlib CFLAGS, which seems cleaner.

This requires adding more stuff to the module's -I list.  The MSVC
aspect of that is untested, but I'm sure the buildfarm will tell me
if I got it wrong.

Per a suggestion from Peter Eisentraut.  Although this is theoretically
a bug fix, the lack of field reports makes me feel we needn't back-patch.

Discussion: https://postgr.es/m/31364.1543511708@sss.pgh.pa.us

6 years agoRename ecpg's various "extern.h" files to have distinct names.
Tom Lane [Sat, 1 Dec 2018 21:34:00 +0000 (16:34 -0500)]
Rename ecpg's various "extern.h" files to have distinct names.

This should reduce confusion, and in particular make it safe to
copy typename.c into preproc/ and compile it there.

This doesn't affect anything outside ecpg, and particularly not
end users, because these files don't get installed; they just
exist to share declarations among the .c files of each subdirectory.

Discussion: https://postgr.es/m/31364.1543511708@sss.pgh.pa.us

6 years agoAdd a --socketdir option to pg_upgrade.
Tom Lane [Sat, 1 Dec 2018 20:45:11 +0000 (15:45 -0500)]
Add a --socketdir option to pg_upgrade.

This allows control of the directory in which the postmaster sockets
are created for the temporary postmasters started by pg_upgrade.
The default location remains the current working directory, which is
typically fine, but if it is deeply nested then its pathname might
be too long to be a socket name.

In passing, clean up some messiness in pg_upgrade's option handling,
particularly the confusing and undocumented way that configuration-only
datadirs were handled.  And fix check_required_directory's substantially
under-baked cleanup of directory pathnames.

Daniel Gustafsson, reviewed by Hironobu Suzuki, some code cleanup by me

Discussion: https://postgr.es/m/E72DD5C3-2268-48A5-A907-ED4B34BEC223@yesql.se

6 years agoFix tablespace path TAP test of pg_verify_checksums for msys
Michael Paquier [Fri, 30 Nov 2018 22:53:18 +0000 (07:53 +0900)]
Fix tablespace path TAP test of pg_verify_checksums for msys

TAP tests on msys need to run with the DTK perl, which understands msys
virtualized paths.  Postgres, however, does not understand such paths,
so before a path can be used safely with CREATE TABLESPACE, it needs to
be translated into a path on the underlying file system.

Per report from buildfarm member jacana.  Suggested fix is from Andrew
Dunstan.

Discussion: https://postgr.es/m/20181130053555[email protected]

6 years agoSilence compiler warning
Alvaro Herrera [Fri, 30 Nov 2018 13:20:49 +0000 (10:20 -0300)]
Silence compiler warning

My original coding was questionable anyway.

Reported-by: Sergei Kornilov
Discussion: https://postgr.es/m/9645101543575886@myt6-27270b78ac4f.qloud-c.yandex.net

6 years agoFix typo.
Amit Kapila [Fri, 30 Nov 2018 06:20:43 +0000 (11:50 +0530)]
Fix typo.

6 years agoFix various checksum check problems for pg_verify_checksums and base backups
Michael Paquier [Fri, 30 Nov 2018 01:34:45 +0000 (10:34 +0900)]
Fix various checksum check problems for pg_verify_checksums and base backups

Three issues are fixed in this patch:
- Base backups forgot to ignore files specific to EXEC_BACKEND, leading
to spurious warnings when checksums are enabled, per analysis from me.
- pg_verify_checksums forgot about files specific to EXEC_BACKEND,
leading to failures of the tool on any such build, particularly Windows.
This error was originally found by newly-introduced TAP tests in various
buildfarm members using EXEC_BACKEND.
- pg_verify_checksums forgot to count for temporary files and temporary
paths, which could be valid relation files, without checksums, per
report from Andres Freund.  More tests are added to cover this case.

A new test case which emulates corruption for a file in a different
tablespace is added, coming from from Michael Banck, while I have coded
the main code and refactored the test code.

Author: Michael Banck, Michael Paquier
Reviewed-by: Stephen Frost, David Steele
Discussion: https://postgr.es/m/20181021134206[email protected]

6 years agoSwitch pg_verify_checksums back to a blacklist
Michael Paquier [Fri, 30 Nov 2018 01:14:58 +0000 (10:14 +0900)]
Switch pg_verify_checksums back to a blacklist

This basically reverts commit d55241af705667d4503638e3f77d3689fd6be31,
leaving around a portion of the regression tests still adapted with
empty relation files, and corrupted cases.  This is also proving to be
failing to check properly relation files located in a non-default
tablespace path.

Per discussion with various folks, including Stephen Frost, David
Steele, Andres Freund, Michael Banck and myself.

Reported-by: Michael Banck
Discussion: https://postgr.es/m/20181021134206[email protected]
Backpatch-through: 11

6 years agoDocument handling of invalid/ambiguous timestamp input near DST boundaries.
Tom Lane [Thu, 29 Nov 2018 23:28:10 +0000 (18:28 -0500)]
Document handling of invalid/ambiguous timestamp input near DST boundaries.

The source code comments documented this, but the user-facing docs, not
so much.  Add a section to Appendix B that discusses it.

In passing, improve a couple other things in Appendix B --- notably,
a long-obsolete claim that time zone abbreviations are looked up in
a fixed table.

Per bug #15527 from Michael Davidson.

Discussion: https://postgr.es/m/15527-f1be0b4dc99ebbe7@postgresql.org

6 years agoAdd log_statement_sample_rate parameter
Alvaro Herrera [Thu, 29 Nov 2018 21:42:53 +0000 (18:42 -0300)]
Add log_statement_sample_rate parameter

This allows to set a lower log_min_duration_statement value without
incurring excessive log traffic (which reduces performance).  This can
be useful to analyze workloads with lots of short queries.

Author: Adrien Nayrat
Reviewed-by: David Rowley, Vik Fearing
Discussion: https://postgr.es/m/c30ee535-ee1e-db9f-fa97-146b9f62caed@anayrat.info

6 years agoEnsure static libraries have correct mod time even if ranlib messes it up.
Tom Lane [Thu, 29 Nov 2018 20:53:44 +0000 (15:53 -0500)]
Ensure static libraries have correct mod time even if ranlib messes it up.

In at least Apple's version of ranlib, the output file is updated to have
a mod time equal to the max of the timestamps of its components, and that
data only has seconds precision.  On a filesystem with sub-second file
timestamp precision --- say, APFS --- this can result in the finished
static library appearing older than its input files, which causes useless
rebuilds and possible outright failures in parallel makes.

We've only seen this reported in the field from people using Apple's
ranlib with a non-Apple make, because Apple's make doesn't know about
sub-second timestamps either so it doesn't decide rebuilds are needed.
But Apple's ranlib presumably shares code with at least some BSDen,
so it's not that unlikely that the same problem could arise elsewhere.

To fix, just "touch" the output file after ranlib finishes.

We seem to need this in only one place.  There are other calls of
ranlib in our makefiles, but they are working on intermediate files
whose timestamps are not actually important, or else on an installed
static library for which sub-second timestamp precision is unlikely
to matter either.  (Also, so far as I can tell, Apple's ranlib doesn't
mess up the file timestamp in the latter usage anyhow.)

In passing, change "ranlib" to "$(RANLIB)" in one place that was
bypassing the make macro for no good reason.

Per bug #15525 from Jack Kelly (via Alyssa Ross).
Back-patch to all supported branches.

Discussion: https://postgr.es/m/15525-a30da084f17a1faa@postgresql.org

6 years agodoc: Add appendix detailing some limits of PostgreSQL
Peter Eisentraut [Thu, 29 Nov 2018 12:58:28 +0000 (13:58 +0100)]
doc: Add appendix detailing some limits of PostgreSQL

This used to be on the web site but was removed.  The documentation is
a better place for it anyway.

Author: David Rowley <[email protected]>
Reviewed-by: John Naylor <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAKJS1f_dKdejdKB94nKZC9S5NzB-UZRcAKkE84e=JEEecDuotg@mail.gmail.com/

6 years agoAdd pg_partition_tree to documentation index
Michael Paquier [Thu, 29 Nov 2018 09:00:08 +0000 (18:00 +0900)]
Add pg_partition_tree to documentation index

This fixes an oversight from d5eec4ee.

Author: Michael Paquier
Reviewed-by: Amit Langote
Discussion: https://postgr.es/m/20181129072719[email protected]

6 years agoAdd support for NO_INSTALLCHECK in MSVC scripts
Michael Paquier [Thu, 29 Nov 2018 01:31:12 +0000 (10:31 +0900)]
Add support for NO_INSTALLCHECK in MSVC scripts

When fetching a list of tests for a given extension in contrib/ or
src/test/modules/, NO_INSTALLCHECK now gets checked first.  If present,
an empty list of tests is returned to let the caller know that tests
for this module need to be bypassed.

This actually fixes a set of issues with MSVC with modules using
REGRESS_OPTS, as an incorrect parsing caused the launched command
to eat the first test listed.  The actual effect on the tree is that
several modules listed a single test, so regressions have been running
with no actual tests.  pg_stat_statements, test_rls_hooks and commit_ts
were impacted by that.  Some other modules like test_decoding (or
snapshot_too_old) don't use yet PGXS rules, but their makefiles will
soon be refactored with an upcoming patch.

Author: Michael Paquier
Reviewed-by: Andrew Dunstan
Discussion: https://postgr.es/m/20181126054302[email protected]

6 years agoFix minor typo in dsa.c.
Thomas Munro [Thu, 29 Nov 2018 01:14:26 +0000 (14:14 +1300)]
Fix minor typo in dsa.c.

Author: Takeshi Ideriha
Discussion: https://postgr.es/m/4E72940DA2BF16479384A86D54D0988A6F3BF22D%40G01JPEXMBKW04

6 years agoAdd missing NO_INSTALLCHECK in commit_ts and test_rls_hooks
Michael Paquier [Thu, 29 Nov 2018 00:39:07 +0000 (09:39 +0900)]
Add missing NO_INSTALLCHECK in commit_ts and test_rls_hooks

This bypasses installcheck if specified, which makes sense for those
modules as they require non-default configuration, something which
typical users don't have.  Those have been missing from the start, still
no back-patch is done.

This will be used by an upcoming patch for MSVC scripts adding support
for NO_INSTALLCHECK as installcheck is the default mode for contrib and
modules for performance reasons in the buildfarm.

Author: Michael Paquier
Reviewed-by: Andrew Dunstan
Discussion: https://postgr.es/m/20181126054302[email protected]

6 years agoFix handling of synchronous replication for stopping WAL senders
Michael Paquier [Thu, 29 Nov 2018 00:12:19 +0000 (09:12 +0900)]
Fix handling of synchronous replication for stopping WAL senders

This fixes an oversight from c6c3334 which forgot that if a subset of
WAL senders are stopping and in a sync state, other WAL senders could
still be waiting for a WAL position to be synced while committing a
transaction.  However the subset of stopping senders would not release
waiters, potentially breaking synchronous replication guarantees.  This
commit makes sure that even WAL senders stopping are able to release
waiters and are tracked properly.

On 9.4, this can also trigger an assertion failure when setting for
example max_wal_senders to 1 where a WAL sender is not able to find
itself as in synchronous state when the instance stops.

Reported-by: Paul Guo
Author: Paul Guo, Michael Paquier
Discussion: https://postgr.es/m/CAEET0ZEv8VFqT3C-cQm6byOB4r4VYWcef1J21dOX-gcVhCSpmA@mail.gmail.com
Backpatch-through: 9.4

6 years agoHave BufFileSize() ereport() on FileSize() failure.
Peter Geoghegan [Wed, 28 Nov 2018 22:42:54 +0000 (14:42 -0800)]
Have BufFileSize() ereport() on FileSize() failure.

Move the responsibility for checking for and reporting a failure from
the only current BufFileSize() caller, logtape.c, to BufFileSize()
itself.  Code within buffile.c is generally responsible for interfacing
with fd.c to report irrecoverable failures.  This seems like a
convention that's worth sticking to.

Reorganizing things this way makes it easy to make the error message
raised in the event of BufFileSize() failure descriptive of the
underlying problem.  We're now clear on the distinction between
temporary file name and BufFile name, and can show errno, confident that
its value actually relates to the error being reported.  In passing, an
existing, similar buffile.c ereport() + errcode_for_file_access() site
is changed to follow the same conventions.

The API of the function BufFileSize() is changed by this commit, despite
already being in a stable release (Postgres 11).  This seems acceptable,
since the BufFileSize() ABI was changed by commit aa551830421, which
hasn't made it into a point release yet.  Besides, it's difficult to
imagine a third party BufFileSize() caller not just raising an error
anyway, since BufFile state should be considered corrupt when
BufFileSize() fails.

Per complaint from Tom Lane.

Discussion: https://postgr.es/m/26974.1540826748@sss.pgh.pa.us
Backpatch: 11-, where shared BufFiles were introduced.

6 years agoOnly allow one recovery target setting
Peter Eisentraut [Wed, 28 Nov 2018 11:36:49 +0000 (12:36 +0100)]
Only allow one recovery target setting

The previous recovery.conf regime accepted multiple recovery_target*
settings and used the last one.  This does not translate well to the
general GUC system.  Specifically, under EXEC_BACKEND, the settings
are written out not in any particular order, so the order in which
they were originally set is not available to new processes.

Rather than redesign the GUC system, it was decided to abandon the old
behavior and only allow one recovery target setting.  A second setting
will cause an error.  However, it is allowed to set the same parameter
multiple times or unset a parameter and set a different one.

Discussion: https://www.postgresql.org/message-id/flat/27802171543235530%40iva2-6ec8f0a6115e.qloud-c.yandex.net#701a59c837ad0bf8c244344aaf3ef5a4

6 years agoC comment: remove extra '*'
Bruce Momjian [Wed, 28 Nov 2018 12:34:10 +0000 (07:34 -0500)]
C comment:  remove extra '*'

Reported-by: Etsuro Fujita
Discussion: https://postgr.es/m/5BFE34DE.1080404@lab.ntt.co.jp

Author: Etsuro Fujita

Backpatch-through: 10

6 years agoDon't set PAM_RHOST for Unix sockets.
Thomas Munro [Wed, 28 Nov 2018 01:00:57 +0000 (14:00 +1300)]
Don't set PAM_RHOST for Unix sockets.

Since commit 2f1d2b7a we have set PAM_RHOST to "[local]" for Unix
sockets.  This caused Linux PAM's libaudit integration to make DNS
requests for that name.  It's not exactly clear what value PAM_RHOST
should have in that case, but it seems clear that we shouldn't set it
to an unresolvable name, so don't do that.

Back-patch to 9.6.  Bug #15520.

Author: Thomas Munro
Reviewed-by: Peter Eisentraut
Reported-by: Albert Schabhuetl
Discussion: https://postgr.es/m/15520-4c266f986998e1c5%40postgresql.org

6 years agoDo not decode TOAST data for table rewrites
Tomas Vondra [Wed, 28 Nov 2018 00:11:15 +0000 (01:11 +0100)]
Do not decode TOAST data for table rewrites

During table rewrites (VACUUM FULL and CLUSTER), the main heap is logged
using XLOG / FPI records, and thus (correctly) ignored in decoding.
But the associated TOAST table is WAL-logged as plain INSERT records,
and so was logically decoded and passed to reorder buffer.

That has severe consequences with TOAST tables of non-trivial size.
Firstly, reorder buffer has to keep all those changes, possibly spilling
them to a file, incurring I/O costs and disk space.

Secondly, ReoderBufferCommit() was stashing all those TOAST chunks into
a hash table, which got discarded only after processing the row from the
main heap.  But as the main heap is not decoded for rewrites, this never
happened, so all the TOAST data accumulated in memory, resulting either
in excessive memory consumption or OOM.

The fix is simple, as commit e9edc1ba already introduced infrastructure
(namely HEAP_INSERT_NO_LOGICAL flag) to skip logical decoding of TOAST
tables, but it only applied it to system tables.  So simply use it for
all TOAST data in raw_heap_insert().

That would however solve only the memory consumption issue - the TOAST
changes would still be decoded and added to the reorder buffer, and
spilled to disk (although without TOAST tuple data, so much smaller).
But we can solve that by tweaking DecodeInsert() to just ignore such
INSERT records altogether, using XLH_INSERT_CONTAINS_NEW_TUPLE flag,
instead of skipping them later in ReorderBufferCommit().

Review: Masahiko Sawada
Discussion: https://www.postgresql.org/message-id/flat/1a17c643-e9af-3dba-486b-fbe31bc1823a%402ndquadrant.com
Backpatch: 9.4-, where logical decoding was introduced

6 years agoUse wildcard to match parens after CREATE STATISTICS
Tomas Vondra [Tue, 27 Nov 2018 23:48:51 +0000 (00:48 +0100)]
Use wildcard to match parens after CREATE STATISTICS

CREATE STATISTICS completion was checking manually for the start and end
of the parenthesised list of types. That works, but we now have a better
way to do that as commit 121213d9d taught word_matches() to allow '*' in
the middle of an alternative. But it only applied that to tab completion
for EXPLAIN, ANALYZE and VACUUM. Use it for CREATE STATISTICS too.

Author: Dagfinn Ilmari Mannsåker
Discussion: https://www.postgresql.org/message-id/flat/d8jwooziy1s.fsf%40dalvik.ping.uio.no

6 years agoDon't count zero-filled buffers as 'read' in EXPLAIN.
Thomas Munro [Tue, 27 Nov 2018 22:42:32 +0000 (11:42 +1300)]
Don't count zero-filled buffers as 'read' in EXPLAIN.

If you extend a relation, it should count as a block written, not
read (we write a zero-filled block).  If you ask for a zero-filled
buffer, it shouldn't be counted as read or written.

Later we might consider counting zero-filled buffers with a separate
counter, if they become more common due to future work.

Author: Thomas Munro
Reviewed-by: Haribabu Kommi, Kyotaro Horiguchi, David Rowley
Discussion: https://postgr.es/m/CAEepm%3D3JytB3KPpvSwXzkY%2Bdwc5zC8P8Lk7Nedkoci81_0E9rA%40mail.gmail.com

6 years agoEnsure consistent sort order of large objects in pg_dump.
Andres Freund [Tue, 27 Nov 2018 20:16:55 +0000 (12:16 -0800)]
Ensure consistent sort order of large objects in pg_dump.

The primary purpose of this commit is to ensure pg_upgrade tests yield
comparable dumps pre/post upgrade, which got broken by 12a53c732 /
578b229718, as the order in pg_largeobject_metadata is likely to
differ pre/post upgrade.

It also seems like a generally good idea to make sure such dumps are
comparable, outside of pg_upgrade tests.

LO metadata already was already dumped in an ordered manner as the
metadata is dumped in a well defined order via
sortDumpableObjectsByTypeName() and sortDumpableObjects(). But large
object data is currently not tracked via that mechanism.

As Tom points out it seems possible that at some point dumpBlobs() was
assumed to dump out objects in a well defined order, due to the use of
DISTINCT, which at that time only was done using sorting.

Per complaint from Andrew Dunstan and discussion with him and Tom
Lane.

Author: Andres Freund
Discussion: https://postgr.es/m/2735.1543333649@sss.pgh.pa.us

6 years agoFix jit compilation bug on wide tables.
Andres Freund [Tue, 27 Nov 2018 18:07:03 +0000 (10:07 -0800)]
Fix jit compilation bug on wide tables.

The function generated to perform JIT compiled tuple deforming failed
when HeapTupleHeader's t_hoff was bigger than a signed int8. I'd
failed to realize that LLVM's getelementptr would treat an int8 index
argument as signed, rather than unsigned.  That means that a hoff
larger than 127 would result in a negative offset being applied.  Fix
that by widening the index to 32bit.

Add a testcase with a wide table. Don't drop it, as it seems useful to
verify other tools deal properly with wide tables.

Thanks to Justin Pryzby for both reporting a bug and then reducing it
to a reproducible testcase!

Reported-By: Justin Pryzby
Author: Andres Freund
Discussion: https://postgr.es/m/20181115223959[email protected]
Backpatch: 11, just as jit compilation was

6 years agoUpdate ssl test certificates and keys
Peter Eisentraut [Tue, 27 Nov 2018 14:16:14 +0000 (15:16 +0100)]
Update ssl test certificates and keys

Debian testing and newer now require that RSA and DHE keys are at
least 2048 bit long and no longer allow SHA-1 for signatures in
certificates.  This is currently causing the ssl tests to fail there
because the test certificates and keys have been created in violation
of those conditions.

Update the parameters to create the test files and create a new set of
test files.

Author: Kyotaro HORIGUCHI <[email protected]>
Reported-by: Michael Paquier <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/20180917131340.GE31460%40paquier.xyz

6 years agoFix ac218aa4f6 to work on versions before 9.5.
Andres Freund [Tue, 27 Nov 2018 07:26:05 +0000 (23:26 -0800)]
Fix ac218aa4f6 to work on versions before 9.5.

Unfortunately ac218aa4f6 missed the fact that a reference to
'pg_catalog.regnamespace'::regclass wouldn't work before that type is
known. Fix that, by replacing the regtype usage with a join to
pg_type.

Reported-By: Tom Lane
Author: Andres Freund
Discussion: https://postgr.es/m/8863.1543297423@sss.pgh.pa.us
Backpatch: 9.5-, like ac218aa4f6

6 years agoUpdate pg_upgrade test for reg* to include regrole and regnamespace.
Andres Freund [Tue, 27 Nov 2018 01:00:43 +0000 (17:00 -0800)]
Update pg_upgrade test for reg* to include regrole and regnamespace.

When the regrole (0c90f6769) and regnamespace (cb9fa802b) types were
added in 9.5, pg_upgrade's check for reg* types wasn't updated. While
regrole currently is safe, regnamespace is not.

It seems unlikely that anybody uses regnamespace inside catalog tables
across a pg_upgrade, but the tests should be correct nevertheless.

While at it, reorder the types checked in the query to be
alphabetical. Otherwise it's annoying to compare existing and tested
for types.

Author: Andres Freund
Discussion: https://postgr.es/m/037e152a-cb25-3bcb-4f35-bdc9988f8204@2ndQuadrant.com
Backpatch: 9.5-, as regrole/regnamespace

6 years agodoc: fix wording for plpgsql, add "and"
Bruce Momjian [Tue, 27 Nov 2018 00:41:19 +0000 (19:41 -0500)]
doc:  fix wording for plpgsql, add "and"

Reported-by: Anthony Greene
Discussion: https://postgr.es/m/CAPRNmnsSZ4QL75FUjcS8ND_oV+WjgyPbZ4ch2RUwmW6PWzF38w@mail.gmail.com

Backpatch-through: 9.4

6 years agoFix typo introduced in 578b229718.
Andres Freund [Mon, 26 Nov 2018 23:27:34 +0000 (15:27 -0800)]
Fix typo introduced in 578b229718.

Author: Andreas Karlsson
Discussion: https://postgr.es/m/0917c86f-e906-27c0-740e-abc581480823@proxel.se

6 years agoFix pg_upgrade for oid removal.
Andres Freund [Mon, 26 Nov 2018 22:20:36 +0000 (14:20 -0800)]
Fix pg_upgrade for oid removal.

pg_upgrade previously copied pg_largeobject_metadata over from the old
cluster. That doesn't work, because the table has oids before
578b229718. I missed that.

As most pieces of metadata for large objects already were dumped as
DDL (except for comments overwritten by pg_upgrade, due to the copy of
pg_largeobject_metadata) it seems reasonable to just also dump grants
for large objects.  If we ever consider this a relevant performance
problem, we'd need to fix the rest of the already emitted DDL
too.

There's still an open discussion about whether we'll want to force a
specific ordering for the dumped objects, as currently
pg_largeobjects_metadata potentially has a different ordering
before/after pg_upgrade, which can make automated testing a bit
harder.

Reported-By: Andrew Dunstan
Author: Andres Freund
Discussion: https://postgr.es/m/91a8a980-41bc-412b-fba2-2ba71a141c2b@2ndQuadrant.com

6 years agoFix translation of special characters in psql's LaTeX output modes.
Tom Lane [Mon, 26 Nov 2018 22:32:51 +0000 (17:32 -0500)]
Fix translation of special characters in psql's LaTeX output modes.

latex_escaped_print() mistranslated \ and failed to provide any translation
for # ^ and ~, all of which would typically lead to LaTeX document syntax
errors.  In addition it didn't translate < > and |, which would typically
render as unexpected characters.

To some extent this represents shortcomings in ancient versions of LaTeX,
which if memory serves had no easy way to render these control characters
as ASCII text.  But that's been fixed for, um, decades.  In any case there
is no value in emitting guaranteed-to-fail output for these characters.

Noted while fooling with test cases added by commit 9a98984f4.  Back-patch
the code change to all supported versions.

6 years agoAvoid locale-dependent output in numericlocale check.
Tom Lane [Mon, 26 Nov 2018 20:30:11 +0000 (15:30 -0500)]
Avoid locale-dependent output in numericlocale check.

I'd forgotten that in the buildfarm, parts of the regression tests
may run with psql exposed to a non-default LC_NUMERIC setting.
Hence we can't assume that C locale prevails, nor is there any
accessible way to force the setting for this single test step.
Lobotomize the test case added by commit 9a98984f4 so that it covers as
much as we can of print.c without having any locale-varying output.

6 years agoFix sample output for hash_metapage_info query
Alvaro Herrera [Mon, 26 Nov 2018 19:58:02 +0000 (16:58 -0300)]
Fix sample output for hash_metapage_info query

One output column was duplicated.  Couldn't resist fixing the version
number while at it.

Reported-by: Gianni Ciolli
6 years agoAdd CSV table output mode in psql.
Tom Lane [Mon, 26 Nov 2018 20:18:55 +0000 (15:18 -0500)]
Add CSV table output mode in psql.

"\pset format csv", or --csv, selects comma-separated values table format.
This is compliant with RFC 4180, except that we aren't too picky about
whether the record separator is LF or CRLF; also, the user may choose a
field separator other than comma.

This output format is directly compatible with the server's COPY CSV
format, and will also be useful as input to other programs.  It's
considerably safer for that purpose than the old recommendation to
use "unaligned" format, since the latter couldn't handle data
containing the field separator character.

Daniel Vérité, reviewed by Fabien Coelho and David Fetter, some
tweaking by me

Discussion: https://postgr.es/m/a8de371e-006f-4f92-ab72-2bbe3ee78f03@manitou-mail.org

6 years agoImprove regression test coverage for psql output formats.
Tom Lane [Mon, 26 Nov 2018 17:41:42 +0000 (12:41 -0500)]
Improve regression test coverage for psql output formats.

As penance for the "\pset format latex" silliness, add some regression
test coverage for the off-the-beaten-path output formats, which formerly
had exactly no coverage, except for some poorly-thought-out (unreadable,
repetitive, and incomplete) tests for asciidoc format.

I make no claims for the behavior exposed here actually being correct;
these test cases are just designed to ensure full code coverage in
fe_utils/print.c.  This brings the line coverage for that file up
from ~60% to ~93%.

6 years agoFix breakage of "\pset format latex".
Tom Lane [Mon, 26 Nov 2018 17:31:20 +0000 (12:31 -0500)]
Fix breakage of "\pset format latex".

Commit eaf746a5b unintentionally made psql's "latex" output format
inaccessible, since not only "latex" but all abbreviations of it
were considered ambiguous against "latex-longtable".  Let's go
back to the longstanding behavior that all shortened versions
mean "latex", and you have to write at least "latex-" to get
"latex-longtable".  This leaves the only difference from pre-v12
behavior being that "\pset format a" is considered ambiguous.

The fact that the regression tests didn't expose this is pretty bad,
but fixing it is material for a separate commit.

Discussion: https://postgr.es/m/cb7e1caf-3ea6-450d-af28-f524903a030c@manitou-mail.org

6 years agoClarify that cross-row constraints are unsupported
Alvaro Herrera [Mon, 26 Nov 2018 15:27:07 +0000 (12:27 -0300)]
Clarify that cross-row constraints are unsupported

Maybe we'll implement them later, or maybe not, but let's make the statu
quo clear for now.

Author: Lætitia Avrot, Patrick Francelle
Reviewers: too many to list
Discussion: https://postgr.es/m/CAB_COdhUuzNFOJfc7SNNso5rOuVA3ui93KMVunEM8Yih+K5A6A@mail.gmail.com

6 years agoRevert "Fix typo in documentation of toast storage"
Michael Paquier [Mon, 26 Nov 2018 07:43:19 +0000 (16:43 +0900)]
Revert "Fix typo in documentation of toast storage"

This reverts commit 058ef3a, per complains from Magnus Hagander and Vik
Fearing.

6 years agoFix typo in documentation of toast storage
Michael Paquier [Mon, 26 Nov 2018 06:49:23 +0000 (15:49 +0900)]
Fix typo in documentation of toast storage

Author: Nawaz Ahmed
Discussion: https://postgr.es/m/154319327168.1315.1846953598601966513@wrigleys.postgresql.org

6 years agoRevert all new recent changes to add PGXS options for TAP and isolation
Michael Paquier [Mon, 26 Nov 2018 02:12:11 +0000 (11:12 +0900)]
Revert all new recent changes to add PGXS options for TAP and isolation

A set of failures in buildfarm machines are proving that this is not
quite ready yet because of another set of issues:
- MSVC scripts assume that REGRESS_OPTS can only use top_builddir.  Some
test suites actually finish by using top_srcdir, like pg_stat_statements
which cause the regression tests to never run.
- Trying to enforce top_builddir does not work either when using VPATH
as this is not recognized properly.
- TAP tests of bloom are unstable on various platforms, causing various
failures.

6 years agoFix regression test handling of test_decoding with MSVC
Michael Paquier [Mon, 26 Nov 2018 01:49:49 +0000 (10:49 +0900)]
Fix regression test handling of test_decoding with MSVC

The set of scripts in charge of running the regression tests for MSVC
run currently under the assumption that only $(top_builddir) can used in
option values defined in REGRESS_OPTS, and those options need to have a
specific format as well to be correctly parsed, so fix the Makefile
values so as those are correctly set.

Per complains from buildfarm member dory and whelk, with some extra
testing done on my side with MSVC to check this patch.

6 years agoDisable temporarily TAP tests for contrib/bloom/
Michael Paquier [Mon, 26 Nov 2018 00:42:21 +0000 (09:42 +0900)]
Disable temporarily TAP tests for contrib/bloom/

The recent commit 03faa4a8 has enabled those tests, however several
buildfarm members are complaining about their stability on Windows and
macOS.  This will keep the buildfarm green, while investigating the
root problem.

Discussion: https://postgr.es/m/20181126003351[email protected]

6 years agoAdd PGXS options to control TAP and isolation tests
Michael Paquier [Sun, 25 Nov 2018 23:39:19 +0000 (08:39 +0900)]
Add PGXS options to control TAP and isolation tests

The following options are added for extensions:
- TAP_TESTS, to allow an extention to run TAP tests which are the ones
present in t/*.pl.  A subset of tests can always be run with the
existing PROVE_TESTS for developers.
- ISOLATION, to define a list of isolation tests.
- ISOLATION_OPTS, to pass custom options to isolation_tester.

A couple of custom Makefile targets have been accumulated across the
tree to cover the lack of facility in PGXS for a couple of releases when
using those test suites, which are all now replaced with the new flags,
without reducing the test coverage.  This also fixes an issue with
contrib/bloom/, which had a custom target to trigger its TAP tests of
its own not part of the main check runs.

Author: Michael Paquier
Reviewed-by: Adam Berlin, Álvaro Herrera, Tom Lane, Nikolay Shaplov,
Arthur Zakirov
Discussion: https://postgr.es/m/20180906014849[email protected]

6 years agoIntegrate recovery.conf into postgresql.conf
Peter Eisentraut [Sun, 25 Nov 2018 15:31:16 +0000 (16:31 +0100)]
Integrate recovery.conf into postgresql.conf

recovery.conf settings are now set in postgresql.conf (or other GUC
sources).  Currently, all the affected settings are PGC_POSTMASTER;
this could be refined in the future case by case.

Recovery is now initiated by a file recovery.signal.  Standby mode is
initiated by a file standby.signal.  The standby_mode setting is
gone.  If a recovery.conf file is found, an error is issued.

The trigger_file setting has been renamed to promote_trigger_file as
part of the move.

The documentation chapter "Recovery Configuration" has been integrated
into "Server Configuration".

pg_basebackup -R now appends settings to postgresql.auto.conf and
creates a standby.signal file.

Author: Fujii Masao <[email protected]>
Author: Simon Riggs <[email protected]>
Author: Abhijit Menon-Sen <[email protected]>
Author: Sergei Kornilov <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/607741529606767@web3g.yandex.ru/

6 years agoFix assertion failure for SSL connections.
Thomas Munro [Sun, 25 Nov 2018 03:21:41 +0000 (16:21 +1300)]
Fix assertion failure for SSL connections.

Commit cfdf4dc4 added an assertion that every WaitLatch() or similar
handles postmaster death.  One place did not, but was missed in
review and testing due to the need for an SSL connection.  Fix, by
asking for WL_EXIT_ON_PM_DEATH.

Reported-by: Christoph Berg
Discussion: https://postgr.es/m/20181124143845.GA15039%40msg.df7cb.de

6 years agoFix hstore hash function for empty hstores upgraded from 8.4.
Andrew Gierth [Sat, 24 Nov 2018 09:59:49 +0000 (09:59 +0000)]
Fix hstore hash function for empty hstores upgraded from 8.4.

Hstore data generated on pg 8.4 and pg_upgraded to current versions
remains in its original on-disk format unless modified. The same goes
for values generated by the addon hstore-new module on pre-9.0
versions. (The hstoreUpgrade function converts old values on the fly
when read in, but the on-disk value is not modified by this.)

Since old-format empty hstores (and hstore-new hstores) have
representations compatible with the new format, hstoreUpgrade thought
it could get away without modifying such values; but this breaks
hstore_hash (and the new hstore_hash_extended) which assumes
bit-perfect matching between semantically identical hstore values.
Only one bit actually differs (the "new version" flag in the count
field) but that of course is enough to break the hash.

Fix by making hstoreUpgrade unconditionally convert all old values to
new format.

Backpatch all the way, even though this changes a hash value in some
cases, because in those cases the hash value is already failing - for
example, a hash join between old- and new-format empty hstores will be
failing to match, or a hash index on an hstore column containing an
old-format empty value will be failing to find the value since it will
be searching for a hash derived from a new-format datum. (There are no
known field reports of this happening, probably because hashing of
hstores has only been useful in limited circumstances and there
probably isn't much upgraded data being used this way.)

Per concerns arising from discussion of commit eb6f29141be. Original
bug is my fault.

Discussion: https://postgr.es/m/60b1fd3b-7332-40f0-7e7f-f2f04f777747%402ndquadrant.com

6 years agoAvoid crashes in contrib/intarray gist__int_ops (bug #15518)
Andrew Gierth [Fri, 23 Nov 2018 23:56:39 +0000 (23:56 +0000)]
Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

6 years agoAdjust new test case for more portability.
Tom Lane [Sat, 24 Nov 2018 04:49:25 +0000 (23:49 -0500)]
Adjust new test case for more portability.

Early returns from the buildfarm say that most critters are good with
commit cbdb8b4c0, but gaur gives unexpected results with the test case
involving a float8 that's one-ULP-less-than-2^63.  It appears that that
platform's version of rint() rounds that value up to 2^63 instead of
leaving it be.  This is possibly a bug, and it's also possible that no
other platform anybody is using anywhere behaves likewise.  Still, the
point of the test is not to insist that everybody's rint() behaves exactly
the same.  Let's use two-ULPs-less-than-2^63 instead, which I've tested
to act the same on gaur as on more modern hardware.

(This is, more or less, exactly the portability issue I'd feared might
arise...)

Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org

6 years agoFix float-to-integer coercions to handle edge cases correctly.
Tom Lane [Sat, 24 Nov 2018 01:57:11 +0000 (20:57 -0500)]
Fix float-to-integer coercions to handle edge cases correctly.

ftoi4 and its sibling coercion functions did their overflow checks in
a way that looked superficially plausible, but actually depended on an
assumption that the MIN and MAX comparison constants can be represented
exactly in the float4 or float8 domain.  That fails in ftoi4, ftoi8,
and dtoi8, resulting in a possibility that values near the MAX limit will
be wrongly converted (to negative values) when they need to be rejected.

Also, because we compared before rounding off the fractional part,
the other three functions threw errors for values that really ought
to get rounded to the min or max integer value.

Fix by doing rint() first (requiring an assumption that it handles
NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already),
and by comparing to values that should coerce to float exactly, namely
INTxx_MIN and -INTxx_MIN.  Also remove some random cosmetic discrepancies
between these six functions.

Per bug #15519 from Victor Petrovykh.  This should get back-patched,
but first let's see what the buildfarm thinks of it --- I'm not too
sure about portability of some of the regression test cases.

Patch by me; thanks to Andrew Gierth for analysis and discussion.

Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org

6 years agoAdd a 64-bit hash function for type hstore.
Tom Lane [Fri, 23 Nov 2018 18:37:34 +0000 (13:37 -0500)]
Add a 64-bit hash function for type hstore.

There's some question about the correctness of the hash function, but
if it's wrong, the 32-bit version is also wrong.

Amul Sul, reviewed by Hironobu Suzuki

Discussion: https://postgr.es/m/CAAJ_b947JjnNr9Cp45iNjSqKf6PA5mCTmKsRwPjows93YwQrmw@mail.gmail.com

6 years agoAdd a 64-bit hash function for type citext.
Tom Lane [Fri, 23 Nov 2018 18:24:45 +0000 (13:24 -0500)]
Add a 64-bit hash function for type citext.

Amul Sul, reviewed by Hironobu Suzuki

Discussion: https://postgr.es/m/CAAJ_b947JjnNr9Cp45iNjSqKf6PA5mCTmKsRwPjows93YwQrmw@mail.gmail.com

6 years agoClamp semijoin selectivity to be not more than inner-join selectivity.
Tom Lane [Fri, 23 Nov 2018 17:48:49 +0000 (12:48 -0500)]
Clamp semijoin selectivity to be not more than inner-join selectivity.

We should never estimate the output of a semijoin to be more rows than
we estimate for an inner join with the same input rels and join condition;
it's obviously impossible for that to happen.  However, given the
relatively poor quality of our semijoin selectivity estimates ---
particularly, but not only, in cases where we punt and return a default
estimate --- we did often deliver such estimates.  To improve matters,
calculate both estimates inside eqjoinsel() and take the smaller one.

The bulk of this patch is just mechanical refactoring to avoid repetitive
information lookup when we call both eqjoinsel_semi and eqjoinsel_inner.
The actual new behavior is just

selec = Min(selec, inner_rel->rows * selec_inner);

which looks a bit odd but is correct because of our different definitions
for inner and semi join selectivity.

There is one ensuing plan change in the regression tests, but it looks
reasonable enough (and checking the actual row counts shows that the
estimate moved closer to reality, not further away).

Per bug #15160 from Alexey Ermakov.  Although this is arguably a bug fix,
I won't risk destabilizing plan choices in stable branches by
back-patching.

Tom Lane, reviewed by Melanie Plageman

Discussion: https://postgr.es/m/152395805004.19366.3107109716821067806@wrigleys.postgresql.org

6 years agoSilence compiler warnings
Alvaro Herrera [Fri, 23 Nov 2018 16:01:05 +0000 (13:01 -0300)]
Silence compiler warnings

Commit cfdf4dc4fc96 left a few unnecessary assignments, one of which
caused compiler warnings, as reported by Erik Rijkers.  Remove them all.

Discussion: https://postgr.es/m/df0dcca2025b3d90d946ecc508ca9678@xs4all.nl

6 years agoRemove bogus file.
Tom Lane [Fri, 23 Nov 2018 15:20:52 +0000 (10:20 -0500)]
Remove bogus file.

6 years agoDon't allow partitioned indexes in pg_global tablespace
Alvaro Herrera [Fri, 23 Nov 2018 11:44:15 +0000 (08:44 -0300)]
Don't allow partitioned indexes in pg_global tablespace

Missing in dfa608141982.

Author: David Rowley
Discussion: https://postgr.es/m/CAKJS1f-M3NMTCpv=vDfkoqHbMPFf=3-Z1ud=+1DHH00tC+zLaQ@mail.gmail.com

6 years agodoc: Fix typo
Peter Eisentraut [Fri, 23 Nov 2018 10:41:27 +0000 (11:41 +0100)]
doc: Fix typo

6 years agoAdd WL_EXIT_ON_PM_DEATH pseudo-event.
Thomas Munro [Fri, 23 Nov 2018 07:16:41 +0000 (20:16 +1300)]
Add WL_EXIT_ON_PM_DEATH pseudo-event.

Users of the WaitEventSet and WaitLatch() APIs can now choose between
asking for WL_POSTMASTER_DEATH and then handling it explicitly, or asking
for WL_EXIT_ON_PM_DEATH to trigger immediate exit on postmaster death.
This reduces code duplication, since almost all callers want the latter.

Repair all code that was previously ignoring postmaster death completely,
or requesting the event but ignoring it, or requesting the event but then
doing an unconditional PostmasterIsAlive() call every time through its
event loop (which is an expensive syscall on platforms for which we don't
have USE_POSTMASTER_DEATH_SIGNAL support).

Assert that callers of WaitLatchXXX() under the postmaster remember to
ask for either WL_POSTMASTER_DEATH or WL_EXIT_ON_PM_DEATH, to prevent
future bugs.

The only process that doesn't handle postmaster death is syslogger.  It
waits until all backends holding the write end of the syslog pipe
(including the postmaster) have closed it by exiting, to be sure to
capture any parting messages.  By using the WaitEventSet API directly
it avoids the new assertion, and as a by-product it may be slightly
more efficient on platforms that have epoll().

Author: Thomas Munro
Reviewed-by: Kyotaro Horiguchi, Heikki Linnakangas, Tom Lane
Discussion: https://postgr.es/m/CAEepm%3D1TCviRykkUb69ppWLr_V697rzd1j3eZsRMmbXvETfqbQ%40mail.gmail.com,
            https://postgr.es/m/CAEepm=2LqHzizbe7muD7-2yHUbTOoF7Q+qkSD5Q41kuhttRTwA@mail.gmail.com

6 years agoClarify documentation about PASSWORD in CREATE/ALTER ROLE
Michael Paquier [Fri, 23 Nov 2018 00:10:24 +0000 (09:10 +0900)]
Clarify documentation about PASSWORD in CREATE/ALTER ROLE

The documentation of CREATE/ALTER ROLE has been missing two things
related to PASSWORD:
- The password value provided needs to be quoted, some places of the
documentation marked the field with quotes, but not others, which led to
confusion.
- PASSWORD NULL was not provided consistently, with ENCRYPTED being not
compatible with it.

Reported-by: Steven Winfield
Author: Michael Paquier
Reviewed-by: David G. Johnston
Discussion: https://postgr.es/m/154282901979.1316.7418475422120496802@wrigleys.postgresql.org