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

Commit b635ac0

Browse files
committed
Fix performance problem with new COPY DEFAULT code
9f8377f added code to allow COPY FROM insert a column's default value when the input matches the DEFAULT string specified in the COPY command. Here we fix some inefficient code which needlessly palloc0'd an array to store if we should use the default value or input value for the given column. This array was being palloc0'd and pfree'd once per row. It's much more efficient to allocate this once and just reset the values once per row. Reported-by: Masahiko Sawada Author: Masahiko Sawada Discussion: https://postgr.es/m/CAD21AoDvDmUQeJtZrau1ovnT_smN940%3DKp6mszNGK3bq9yRN6g%40mail.gmail.com Backpatch-through: 16, where 9f8377f was introduced.
1 parent f6a8454 commit b635ac0

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/backend/commands/copyfrom.c

+1
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ BeginCopyFrom(ParseState *pstate,
16091609
}
16101610
}
16111611

1612+
cstate->defaults = (bool *) palloc0(tupDesc->natts * sizeof(bool));
16121613

16131614
/* initialize progress */
16141615
pgstat_progress_start_command(PROGRESS_COMMAND_COPY,

src/backend/commands/copyfromparse.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
871871
/* Initialize all values for row to NULL */
872872
MemSet(values, 0, num_phys_attrs * sizeof(Datum));
873873
MemSet(nulls, true, num_phys_attrs * sizeof(bool));
874-
cstate->defaults = (bool *) palloc0(num_phys_attrs * sizeof(bool));
874+
MemSet(cstate->defaults, false, num_phys_attrs * sizeof(bool));
875875

876876
if (!cstate->opts.binary)
877877
{
@@ -1040,8 +1040,6 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext,
10401040
&nulls[defmap[i]]);
10411041
}
10421042

1043-
pfree(cstate->defaults);
1044-
10451043
return true;
10461044
}
10471045

0 commit comments

Comments
 (0)