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

Function CopyMultiInsertInfoFlush

src/backend/commands/copyfrom.c:595–636  ·  view source on GitHub ↗

* Write out all stored tuples in all buffers out to the tables. * * Once flushed we also trim the tracked buffers list down to size by removing * the buffers created earliest first. * * Callers should pass 'curr_rri' as the ResultRelInfo that's currently being * used. When cleaning up old buffers we'll never remove the one for * 'curr_rri'. */

Source from the content-addressed store, hash-verified

593 * 'curr_rri'.
594 */
595static inline void
596CopyMultiInsertInfoFlush(CopyMultiInsertInfo *miinfo, ResultRelInfo *curr_rri)
597{
598 ListCell *lc;
599
600 foreach(lc, miinfo->multiInsertBuffers)
601 {
602 CopyMultiInsertBuffer *buffer = (CopyMultiInsertBuffer *) lfirst(lc);
603
604 CopyMultiInsertBufferFlush(miinfo, buffer);
605 }
606
607 miinfo->bufferedTuples = 0;
608 miinfo->bufferedBytes = 0;
609
610 /*
611 * Trim the list of tracked buffers down if it exceeds the limit. Here we
612 * remove buffers starting with the ones we created first. It seems less
613 * likely that these older ones will be needed than the ones that were
614 * just created.
615 */
616 while (list_length(miinfo->multiInsertBuffers) > MAX_PARTITION_BUFFERS)
617 {
618 CopyMultiInsertBuffer *buffer;
619
620 buffer = (CopyMultiInsertBuffer *) linitial(miinfo->multiInsertBuffers);
621
622 /*
623 * We never want to remove the buffer that's currently being used, so
624 * if we happen to find that then move it to the end of the list.
625 */
626 if (buffer->resultRelInfo == curr_rri)
627 {
628 miinfo->multiInsertBuffers = list_delete_first(miinfo->multiInsertBuffers);
629 miinfo->multiInsertBuffers = lappend(miinfo->multiInsertBuffers, buffer);
630 buffer = (CopyMultiInsertBuffer *) linitial(miinfo->multiInsertBuffers);
631 }
632
633 CopyMultiInsertBufferCleanup(miinfo, buffer);
634 miinfo->multiInsertBuffers = list_delete_first(miinfo->multiInsertBuffers);
635 }
636}
637
638/*
639 * Cleanup allocated buffers and free memory

Callers 1

CopyFromFunction · 0.85

Calls 6

list_lengthFunction · 0.85
list_delete_firstFunction · 0.85
lappendFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected