Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 919e48b

Browse files
committed
tableam: Use in CREATE TABLE AS and CREATE MATERIALIZED VIEW.
Previously those directly performed a heap_insert(). Use table_insert() instead. The input slot of those routines is not of the target relation - we could fix that by copying if necessary, but that'd not be beneficial for performance. As those codepaths don't access any AM specific tuple fields (say xmin/xmax), there's no need to use an AM specific slot. Author: Andres Freund Reviewed-By: Haribabu Kommi Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
1 parent 940311e commit 919e48b

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/backend/commands/createas.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "access/heapam.h"
2828
#include "access/reloptions.h"
2929
#include "access/htup_details.h"
30+
#include "access/tableam.h"
3031
#include "access/sysattr.h"
3132
#include "access/xact.h"
3233
#include "access/xlog.h"
@@ -572,25 +573,24 @@ static bool
572573
intorel_receive(TupleTableSlot *slot, DestReceiver *self)
573574
{
574575
DR_intorel *myState = (DR_intorel *) self;
575-
HeapTuple tuple;
576576

577577
/*
578-
* get the heap tuple out of the tuple table slot, making sure we have a
579-
* writable copy
578+
* Note that the input slot might not be of the type of the target
579+
* relation. That's supported by table_insert(), but slightly less
580+
* efficient than inserting with the right slot - but the alternative
581+
* would be to copy into a slot of the right type, which would not be
582+
* cheap either. This also doesn't allow accessing per-AM data (say a
583+
* tuple's xmin), but since we don't do that here...
580584
*/
581-
tuple = ExecCopySlotHeapTuple(slot);
582585

583-
heap_insert(myState->rel,
584-
tuple,
585-
myState->output_cid,
586-
myState->hi_options,
587-
myState->bistate);
586+
table_insert(myState->rel,
587+
slot,
588+
myState->output_cid,
589+
myState->hi_options,
590+
myState->bistate);
588591

589592
/* We know this is a newly created relation, so there are no indexes */
590593

591-
/* Free the copied tuple. */
592-
heap_freetuple(tuple);
593-
594594
return true;
595595
}
596596

src/backend/commands/matview.c

+11-12
Original file line numberDiff line numberDiff line change
@@ -477,25 +477,24 @@ static bool
477477
transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
478478
{
479479
DR_transientrel *myState = (DR_transientrel *) self;
480-
HeapTuple tuple;
481480

482481
/*
483-
* get the heap tuple out of the tuple table slot, making sure we have a
484-
* writable copy
482+
* Note that the input slot might not be of the type of the target
483+
* relation. That's supported by table_insert(), but slightly less
484+
* efficient than inserting with the right slot - but the alternative
485+
* would be to copy into a slot of the right type, which would not be
486+
* cheap either. This also doesn't allow accessing per-AM data (say a
487+
* tuple's xmin), but since we don't do that here...
485488
*/
486-
tuple = ExecCopySlotHeapTuple(slot);
487489

488-
heap_insert(myState->transientrel,
489-
tuple,
490-
myState->output_cid,
491-
myState->hi_options,
492-
myState->bistate);
490+
table_insert(myState->transientrel,
491+
slot,
492+
myState->output_cid,
493+
myState->hi_options,
494+
myState->bistate);
493495

494496
/* We know this is a newly created relation, so there are no indexes */
495497

496-
/* Free the copied tuple. */
497-
heap_freetuple(tuple);
498-
499498
return true;
500499
}
501500

0 commit comments

Comments
 (0)