Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1ecb9b

Browse files
committed
Fix interaction of partitioned tables with BulkInsertState.
When copying into a partitioned table, the target heap may change fromone tuple to next. We must ask ReadBufferBI() to get a new bufferevery time such change occurs. To do that, use new functionReleaseBulkInsertStatePin(). This fixes the bug that tuples ended upbeing inserted into the wrong partition, which occurred exactlybecause the wrong buffer was used.Amit Langote, per a suggestion from Robert Haas. Some cosmeticadjustments by me.Reports by 高增琦 (Gao Zengqi), Venkata B Nagothi, andRagnar Ouchterlony.Discussion:http://postgr.es/m/CAFmBtr32FDOqofo8yG-4mjzL1HnYHxXK5S9OGFJ%3D%3DcJpgEW4vA%40mail.gmail.comDiscussion:http://postgr.es/m/CAEyp7J9WiX0L3DoiNcRrY-9iyw%3DqP%2Bj%3DDLsAnNFF1xT2J1ggfQ%40mail.gmail.comDiscussion:http://postgr.es/m/16d73804-c9cd-14c5-463e-5caad563ff77%40agama.tvDiscussion:http://postgr.es/m/CA+TgmoaiZpDVUUN8LZ4jv1qFE_QyR+H9ec+79f5vNczYarg5Zg@mail.gmail.com
1 parent3eaf03b commitb1ecb9b

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,17 @@ FreeBulkInsertState(BulkInsertState bistate)
23242324
pfree(bistate);
23252325
}
23262326

2327+
/*
2328+
* ReleaseBulkInsertStatePin - release a buffer currently held in bistate
2329+
*/
2330+
void
2331+
ReleaseBulkInsertStatePin(BulkInsertStatebistate)
2332+
{
2333+
if (bistate->current_buf!=InvalidBuffer)
2334+
ReleaseBuffer(bistate->current_buf);
2335+
bistate->current_buf=InvalidBuffer;
2336+
}
2337+
23272338

23282339
/*
23292340
*heap_insert- insert tuple into a heap

‎src/backend/commands/copy.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ CopyFrom(CopyState cstate)
23072307
uint64processed=0;
23082308
booluseHeapMultiInsert;
23092309
intnBufferedTuples=0;
2310+
intprev_leaf_part_index=-1;
23102311

23112312
#defineMAX_BUFFERED_TUPLES 1000
23122313
HeapTuple*bufferedTuples=NULL;/* initialize to silence warning */
@@ -2561,6 +2562,17 @@ CopyFrom(CopyState cstate)
25612562
Assert(leaf_part_index >=0&&
25622563
leaf_part_index<cstate->num_partitions);
25632564

2565+
/*
2566+
* If this tuple is mapped to a partition that is not same as the
2567+
* previous one, we'd better make the bulk insert mechanism gets a
2568+
* new buffer.
2569+
*/
2570+
if (prev_leaf_part_index!=leaf_part_index)
2571+
{
2572+
ReleaseBulkInsertStatePin(bistate);
2573+
prev_leaf_part_index=leaf_part_index;
2574+
}
2575+
25642576
/*
25652577
* Save the old ResultRelInfo and switch to the one corresponding
25662578
* to the selected partition.

‎src/include/access/heapam.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ extern void setLastTid(const ItemPointer tid);
147147

148148
externBulkInsertStateGetBulkInsertState(void);
149149
externvoidFreeBulkInsertState(BulkInsertState);
150+
externvoidReleaseBulkInsertStatePin(BulkInsertStatebistate);
150151

151152
externOidheap_insert(Relationrelation,HeapTupletup,CommandIdcid,
152153
intoptions,BulkInsertStatebistate);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp