diff options
author | Andres Freund <andres@anarazel.de> | 2019-03-24 18:55:34 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2019-03-24 18:58:37 -0700 |
commit | 919e48b943014b1d4ab5d83e48dbc9f8e87e7be4 (patch) | |
tree | 165263705cd2f2590d02fc5a48d8e57cae78e786 | |
parent | 940311e4bb32a5fe99155052e41179c88b5d48af (diff) | |
download | postgresql-919e48b943014b1d4ab5d83e48dbc9f8e87e7be4.tar.gz postgresql-919e48b943014b1d4ab5d83e48dbc9f8e87e7be4.zip |
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
-rw-r--r-- | src/backend/commands/createas.c | 24 | ||||
-rw-r--r-- | src/backend/commands/matview.c | 23 |
2 files changed, 23 insertions, 24 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 36e3d44aad6..3bdb67c697c 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -27,6 +27,7 @@ #include "access/heapam.h" #include "access/reloptions.h" #include "access/htup_details.h" +#include "access/tableam.h" #include "access/sysattr.h" #include "access/xact.h" #include "access/xlog.h" @@ -572,25 +573,24 @@ static bool intorel_receive(TupleTableSlot *slot, DestReceiver *self) { DR_intorel *myState = (DR_intorel *) self; - HeapTuple tuple; /* - * get the heap tuple out of the tuple table slot, making sure we have a - * writable copy + * Note that the input slot might not be of the type of the target + * relation. That's supported by table_insert(), but slightly less + * efficient than inserting with the right slot - but the alternative + * would be to copy into a slot of the right type, which would not be + * cheap either. This also doesn't allow accessing per-AM data (say a + * tuple's xmin), but since we don't do that here... */ - tuple = ExecCopySlotHeapTuple(slot); - heap_insert(myState->rel, - tuple, - myState->output_cid, - myState->hi_options, - myState->bistate); + table_insert(myState->rel, + slot, + myState->output_cid, + myState->hi_options, + myState->bistate); /* We know this is a newly created relation, so there are no indexes */ - /* Free the copied tuple. */ - heap_freetuple(tuple); - return true; } diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index 5a47be4b33c..5b2cbc7c89c 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -477,25 +477,24 @@ static bool transientrel_receive(TupleTableSlot *slot, DestReceiver *self) { DR_transientrel *myState = (DR_transientrel *) self; - HeapTuple tuple; /* - * get the heap tuple out of the tuple table slot, making sure we have a - * writable copy + * Note that the input slot might not be of the type of the target + * relation. That's supported by table_insert(), but slightly less + * efficient than inserting with the right slot - but the alternative + * would be to copy into a slot of the right type, which would not be + * cheap either. This also doesn't allow accessing per-AM data (say a + * tuple's xmin), but since we don't do that here... */ - tuple = ExecCopySlotHeapTuple(slot); - heap_insert(myState->transientrel, - tuple, - myState->output_cid, - myState->hi_options, - myState->bistate); + table_insert(myState->transientrel, + slot, + myState->output_cid, + myState->hi_options, + myState->bistate); /* We know this is a newly created relation, so there are no indexes */ - /* Free the copied tuple. */ - heap_freetuple(tuple); - return true; } |