diff options
author | Amit Kapila <akapila@postgresql.org> | 2019-01-28 11:31:44 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2019-01-28 11:31:44 +0530 |
commit | a23676503b746b7f1588cd2ab0c60411032d32da (patch) | |
tree | ac7f172ec94771441558639e0725e6d56d6e7b47 /src/backend/access/heap/hio.c | |
parent | ac88d2962a96a9c7e83d5acfc28fe49a72812086 (diff) |
Revert "Avoid creation of the free space map for small heap relations."
This reverts commit ac88d2962a96a9c7e83d5acfc28fe49a72812086.
Diffstat (limited to 'src/backend/access/heap/hio.c')
-rw-r--r-- | src/backend/access/heap/hio.c | 47 |
1 files changed, 17 insertions, 30 deletions
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c index 4c3e774eee2..3da0b49ccc4 100644 --- a/src/backend/access/heap/hio.c +++ b/src/backend/access/heap/hio.c @@ -239,14 +239,8 @@ RelationAddExtraBlocks(Relation relation, BulkInsertState bistate) * Immediately update the bottom level of the FSM. This has a good * chance of making this page visible to other concurrently inserting * backends, and we want that to happen without delay. - * - * Since we know the table will end up with extraBlocks additional - * pages, we pass the final number to avoid possible unnecessary - * system calls and to make sure the FSM is created when we add the - * first new page. */ - RecordPageWithFreeSpace(relation, blockNum, freespace, - firstBlock + extraBlocks); + RecordPageWithFreeSpace(relation, blockNum, freespace); } while (--extraBlocks > 0); @@ -383,9 +377,20 @@ RelationGetBufferForTuple(Relation relation, Size len, * We have no cached target page, so ask the FSM for an initial * target. */ - targetBlock = GetPageWithFreeSpace(relation, - len + saveFreeSpace, - false); + targetBlock = GetPageWithFreeSpace(relation, len + saveFreeSpace); + + /* + * If the FSM knows nothing of the rel, try the last page before we + * give up and extend. This avoids one-tuple-per-page syndrome during + * bootstrapping or in a recently-started system. + */ + if (targetBlock == InvalidBlockNumber) + { + BlockNumber nblocks = RelationGetNumberOfBlocks(relation); + + if (nblocks > 0) + targetBlock = nblocks - 1; + } } loop: @@ -479,14 +484,6 @@ loop: { /* use this page as future insert target, too */ RelationSetTargetBlock(relation, targetBlock); - - /* - * In case we used an in-memory map of available blocks, reset it - * for next use. - */ - if (targetBlock < HEAP_FSM_CREATION_THRESHOLD) - FSMClearLocalMap(); - return buffer; } @@ -546,12 +543,9 @@ loop: /* * Check if some other backend has extended a block for us while - * we were waiting on the lock. We only check the FSM -- if there - * isn't one we don't recheck the number of blocks. + * we were waiting on the lock. */ - targetBlock = GetPageWithFreeSpace(relation, - len + saveFreeSpace, - true); + targetBlock = GetPageWithFreeSpace(relation, len + saveFreeSpace); /* * If some other waiter has already extended the relation, we @@ -631,12 +625,5 @@ loop: */ RelationSetTargetBlock(relation, BufferGetBlockNumber(buffer)); - /* - * In case we used an in-memory map of available blocks, reset it for next - * use. We do this unconditionally since after relation extension we - * can't skip this based on the targetBlock. - */ - FSMClearLocalMap(); - return buffer; } |