diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-03-26 19:14:47 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-03-26 19:14:57 -0400 |
commit | 2f0903ea196503fc8af373a9de46b1e01a23508c (patch) | |
tree | 9eceb4a64d9f6585508fcb2a2c003110cf040cc2 /src/backend/executor | |
parent | 895f93701fd78b6faab6b437685357298a91dfe3 (diff) | |
download | postgresql-2f0903ea196503fc8af373a9de46b1e01a23508c.tar.gz postgresql-2f0903ea196503fc8af373a9de46b1e01a23508c.zip |
Improve performance of ExecEvalWholeRowVar.
In commit b8d7f053c, we needed to fix ExecEvalWholeRowVar to not change
the state of the slot it's copying. The initial quick hack at that
required two rounds of tuple construction, which is not very nice.
To fix, add another primitive to tuptoaster.c that does precisely what
we need. (I initially tried to do this by refactoring one of the
existing functions into two pieces; but it looked like that might hurt
performance for the existing case, and the amount of code that could
be shared is not very large, so I gave up on that.)
Discussion: https://postgr.es/m/26088.1490315792@sss.pgh.pa.us
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execExprInterp.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c index 02fb29cde3f..982d16c6c88 100644 --- a/src/backend/executor/execExprInterp.c +++ b/src/backend/executor/execExprInterp.c @@ -58,7 +58,7 @@ */ #include "postgres.h" -#include "access/htup_details.h" +#include "access/tuptoaster.h" #include "catalog/pg_type.h" #include "executor/execExpr.h" #include "executor/nodeSubplan.h" @@ -3508,24 +3508,24 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext) } /* - * Copy the slot tuple and make sure any toasted fields get detoasted. + * Build a composite datum, making sure any toasted fields get detoasted. * - * (The intermediate copy is a tad annoying here, but we currently have no - * primitive that will do the right thing. Note it is critical that we - * not change the slot's state, so we can't use ExecFetchSlotTupleDatum.) + * (Note: it is critical that we not change the slot's state here.) */ - tuple = ExecCopySlotTuple(slot); - dtuple = (HeapTupleHeader) - DatumGetPointer(heap_copy_tuple_as_datum(tuple, - slot->tts_tupleDescriptor)); - heap_freetuple(tuple); + tuple = toast_build_flattened_tuple(slot->tts_tupleDescriptor, + slot->tts_values, + slot->tts_isnull); + dtuple = tuple->t_data; /* * Label the datum with the composite type info we identified before. + * + * (Note: we could skip doing this by passing op->d.wholerow.tupdesc to + * the tuple build step; but that seems a tad risky so let's not.) */ HeapTupleHeaderSetTypeId(dtuple, op->d.wholerow.tupdesc->tdtypeid); HeapTupleHeaderSetTypMod(dtuple, op->d.wholerow.tupdesc->tdtypmod); - *op->resnull = false; *op->resvalue = PointerGetDatum(dtuple); + *op->resnull = false; } |