Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb635ac0

Browse files
committed
Fix performance problem with new COPY DEFAULT code
9f8377f added code to allow COPY FROM insert a column's default valuewhen the input matches the DEFAULT string specified in the COPY command.Here we fix some inefficient code which needlessly palloc0'd an array tostore if we should use the default value or input value for the givencolumn. This array was being palloc0'd and pfree'd once per row. It'smuch more efficient to allocate this once and just reset the values onceper row.Reported-by: Masahiko SawadaAuthor: Masahiko SawadaDiscussion:https://postgr.es/m/CAD21AoDvDmUQeJtZrau1ovnT_smN940%3DKp6mszNGK3bq9yRN6g%40mail.gmail.comBackpatch-through: 16, where9f8377f was introduced.
1 parentf6a8454 commitb635ac0

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

‎src/backend/commands/copyfrom.c

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 3 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp