MCPcopy Create free account
hub / github.com/apache/cloudberry / CopyMultiInsertBufferCleanup

Function CopyMultiInsertBufferCleanup

src/backend/commands/copyfrom.c:548–583  ·  view source on GitHub ↗

* Drop used slots and free member for this buffer. * * The buffer must be flushed before cleanup. */

Source from the content-addressed store, hash-verified

546 * The buffer must be flushed before cleanup.
547 */
548static inline void
549CopyMultiInsertBufferCleanup(CopyMultiInsertInfo *miinfo,
550 CopyMultiInsertBuffer *buffer)
551{
552 int i;
553
554 /* Ensure buffer was flushed */
555 Assert(buffer->nused == 0);
556
557 /* Remove back-link to ourself */
558 buffer->resultRelInfo->ri_CopyMultiInsertBuffer = NULL;
559
560 FreeBulkInsertState(buffer->bistate);
561
562 /* Since we only create slots on demand, just drop the non-null ones. */
563 for (i = 0; i < MAX_BUFFERED_TUPLES && buffer->slots[i] != NULL; i++)
564 ExecDropSingleTupleTableSlot(buffer->slots[i]);
565
566 if (RelationIsNonblockRelation(buffer->resultRelInfo->ri_RelationDesc))
567 {
568 /*
569 * CBDB: do not call table_finish_bulk_insert for AO/AOCO or PAX tables.
570 * https://github.com/apache/cloudberry/issues/547
571 * Do not clean up context or resource here, table_finish_bulk_insert
572 * routine will be called more than once during COPY FROM if
573 * the partition buffer is flushed but COPY is not finished.
574 */
575 pfree(buffer);
576 return;
577 }
578
579 table_finish_bulk_insert(buffer->resultRelInfo->ri_RelationDesc,
580 miinfo->ti_options);
581
582 pfree(buffer);
583}
584
585/*
586 * Write out all stored tuples in all buffers out to the tables.

Callers 2

CopyMultiInsertInfoFlushFunction · 0.85

Calls 4

FreeBulkInsertStateFunction · 0.85
table_finish_bulk_insertFunction · 0.85
pfreeFunction · 0.50

Tested by

no test coverage detected