diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-01-24 08:50:16 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-01-24 08:50:16 -0500 |
commit | b1ecb9b3fcfb76edb3461ce561d049c8fb9e710d (patch) | |
tree | 666e52f6925f8ea96cd838bd145dd2b79daa630c /src/backend/access/heap/heapam.c | |
parent | 3eaf03b5d331b7a06d79e5ad2be7e36c4a9c3d72 (diff) | |
download | postgresql-b1ecb9b3fcfb76edb3461ce561d049c8fb9e710d.tar.gz postgresql-b1ecb9b3fcfb76edb3461ce561d049c8fb9e710d.zip |
Fix interaction of partitioned tables with BulkInsertState.
When copying into a partitioned table, the target heap may change from
one tuple to next. We must ask ReadBufferBI() to get a new buffer
every time such change occurs. To do that, use new function
ReleaseBulkInsertStatePin(). This fixes the bug that tuples ended up
being inserted into the wrong partition, which occurred exactly
because the wrong buffer was used.
Amit Langote, per a suggestion from Robert Haas. Some cosmetic
adjustments by me.
Reports by 高增琦 (Gao Zengqi), Venkata B Nagothi, and
Ragnar Ouchterlony.
Discussion: http://postgr.es/m/CAFmBtr32FDOqofo8yG-4mjzL1HnYHxXK5S9OGFJ%3D%3DcJpgEW4vA%40mail.gmail.com
Discussion: http://postgr.es/m/CAEyp7J9WiX0L3DoiNcRrY-9iyw%3DqP%2Bj%3DDLsAnNFF1xT2J1ggfQ%40mail.gmail.com
Discussion: http://postgr.es/m/16d73804-c9cd-14c5-463e-5caad563ff77%40agama.tv
Discussion: http://postgr.es/m/CA+TgmoaiZpDVUUN8LZ4jv1qFE_QyR+H9ec+79f5vNczYarg5Zg@mail.gmail.com
Diffstat (limited to 'src/backend/access/heap/heapam.c')
-rw-r--r-- | src/backend/access/heap/heapam.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 1ce42ea9702..5fd7f1e1a20 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -2324,6 +2324,17 @@ FreeBulkInsertState(BulkInsertState bistate) pfree(bistate); } +/* + * ReleaseBulkInsertStatePin - release a buffer currently held in bistate + */ +void +ReleaseBulkInsertStatePin(BulkInsertState bistate) +{ + if (bistate->current_buf != InvalidBuffer) + ReleaseBuffer(bistate->current_buf); + bistate->current_buf = InvalidBuffer; +} + /* * heap_insert - insert tuple into a heap |