* Write the tuples stored in 'buffer' out to the table. */
| 460 | * Write the tuples stored in 'buffer' out to the table. |
| 461 | */ |
| 462 | static inline void |
| 463 | CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo, |
| 464 | CopyMultiInsertBuffer *buffer) |
| 465 | { |
| 466 | MemoryContext oldcontext; |
| 467 | int i; |
| 468 | uint64 save_cur_lineno; |
| 469 | CopyFromState cstate = miinfo->cstate; |
| 470 | EState *estate = miinfo->estate; |
| 471 | CommandId mycid = miinfo->mycid; |
| 472 | int ti_options = miinfo->ti_options; |
| 473 | bool line_buf_valid = cstate->line_buf_valid; |
| 474 | int nused = buffer->nused; |
| 475 | ResultRelInfo *resultRelInfo = buffer->resultRelInfo; |
| 476 | TupleTableSlot **slots = buffer->slots; |
| 477 | |
| 478 | /* |
| 479 | * Print error context information correctly, if one of the operations |
| 480 | * below fails. |
| 481 | */ |
| 482 | cstate->line_buf_valid = false; |
| 483 | save_cur_lineno = cstate->cur_lineno; |
| 484 | |
| 485 | /* |
| 486 | * table_multi_insert may leak memory, so switch to short-lived memory |
| 487 | * context before calling it. |
| 488 | */ |
| 489 | oldcontext = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); |
| 490 | table_multi_insert(resultRelInfo->ri_RelationDesc, |
| 491 | slots, |
| 492 | nused, |
| 493 | mycid, |
| 494 | ti_options, |
| 495 | buffer->bistate); |
| 496 | MemoryContextSwitchTo(oldcontext); |
| 497 | |
| 498 | for (i = 0; i < nused; i++) |
| 499 | { |
| 500 | /* |
| 501 | * If there are any indexes, update them for all the inserted tuples, |
| 502 | * and run AFTER ROW INSERT triggers. |
| 503 | */ |
| 504 | if (resultRelInfo->ri_NumIndices > 0) |
| 505 | { |
| 506 | List *recheckIndexes; |
| 507 | |
| 508 | cstate->cur_lineno = buffer->linenos[i]; |
| 509 | recheckIndexes = |
| 510 | ExecInsertIndexTuples(resultRelInfo, |
| 511 | buffer->slots[i], estate, false, false, |
| 512 | NULL, NIL); |
| 513 | ExecARInsertTriggers(estate, resultRelInfo, |
| 514 | slots[i], recheckIndexes, |
| 515 | cstate->transition_capture); |
| 516 | list_free(recheckIndexes); |
| 517 | } |
| 518 | |
| 519 | /* |
no test coverage detected