aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-06-04 20:35:21 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-06-04 20:35:21 +0000
commit8f2ea8b7b53a02078ba0393e6892ac5356a3631e (patch)
tree536f02e4a6eec0304d76688d65cffbcea9679c9b /src/backend/commands/tablecmds.c
parentaf44cac6ef46e225ae963c5e1f9e2e91a0112e04 (diff)
downloadpostgresql-8f2ea8b7b53a02078ba0393e6892ac5356a3631e.tar.gz
postgresql-8f2ea8b7b53a02078ba0393e6892ac5356a3631e.zip
Resurrect heap_deformtuple(), this time implemented as a singly nested
loop over the fields instead of a loop around heap_getattr. This is considerably faster (O(N) instead of O(N^2)) when there are nulls or varlena fields, since those prevent use of attcacheoff. Replace loops over heap_getattr with heap_deformtuple in situations where all or most of the fields have to be fetched, such as printtup and tuptoaster. Profiling done more than a year ago shows that this should be a nice win for situations involving many-column tables.
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 71f5ad0c001..492532363a5 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.109 2004/06/02 21:01:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.110 2004/06/04 20:35:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2342,10 +2342,10 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
newslot = MakeTupleTableSlot();
ExecSetSlotDescriptor(newslot, newTupDesc, false);
- /* Preallocate values/nulls arrays (+1 in case natts==0) */
+ /* Preallocate values/nulls arrays */
i = Max(newTupDesc->natts, oldTupDesc->natts);
- values = (Datum *) palloc(i * sizeof(Datum) + 1);
- nulls = (char *) palloc(i * sizeof(char) + 1);
+ values = (Datum *) palloc(i * sizeof(Datum));
+ nulls = (char *) palloc(i * sizeof(char));
memset(values, 0, i * sizeof(Datum));
memset(nulls, 'n', i * sizeof(char));
@@ -2363,24 +2363,14 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
* Extract data from old tuple. We can force to null any
* columns that are deleted according to the new tuple.
*/
- int natts = oldTupDesc->natts;
- bool isNull;
+ int natts = newTupDesc->natts;
+
+ heap_deformtuple(tuple, oldTupDesc, values, nulls);
for (i = 0; i < natts; i++)
{
if (newTupDesc->attrs[i]->attisdropped)
nulls[i] = 'n';
- else
- {
- values[i] = heap_getattr(tuple,
- i + 1,
- oldTupDesc,
- &isNull);
- if (isNull)
- nulls[i] = 'n';
- else
- nulls[i] = ' ';
- }
}
/*
@@ -2393,6 +2383,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
foreach(l, tab->newvals)
{
NewColumnValue *ex = lfirst(l);
+ bool isNull;
values[ex->attnum - 1] = ExecEvalExpr(ex->exprstate,
econtext,