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

Commit5b5cef9

Browse files
committed
Enable ALTER TABLE ADD PRIMARY KEY for pg_dump, for performance reasons
so index is not on table during COPY.> > AFAICT, the patch I posted to -patches a little while to enable the> > usage of ALTER TABLE ADD PRIMARY KEY by pg_dump hasn't been applied, nor> > is it in the unapplied patches list. I was under the impression that> > this was in the queue for application -- did it just get lost?Neil Conway <neilconway@rogers.com>
1 parent62e6eb9 commit5b5cef9

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.242 2002/02/27 20:59:05 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.243 2002/03/06 20:48:42 momjian Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -4259,7 +4259,7 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
42594259

42604260

42614261

4262-
/*put the CONSTRAINTS inside the table def */
4262+
/*Put the CONSTRAINTS inside the table def */
42634263
for (k=0;k<tblinfo[i].ncheck;k++)
42644264
{
42654265
if (actual_atts+k>0)
@@ -4269,36 +4269,15 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
42694269
tblinfo[i].check_expr[k]);
42704270
}
42714271

4272-
/* Primary Key */
4273-
if (tblinfo[i].pkIndexOid!=NULL)
4274-
{
4275-
PQExpBufferconsDef;
4276-
4277-
/* Find the corresponding index */
4278-
for (k=0;k<numIndexes;k++)
4279-
{
4280-
if (strcmp(indinfo[k].indexreloid,
4281-
tblinfo[i].pkIndexOid)==0)
4282-
break;
4283-
}
4284-
4285-
if (k >=numIndexes)
4286-
{
4287-
write_msg(NULL,"dumpTables(): failed sanity check, could not find index (%s) for primary key constraint\n",
4288-
tblinfo[i].pkIndexOid);
4289-
exit_nicely();
4290-
}
4291-
4292-
consDef=getPKconstraint(&tblinfo[i],&indinfo[k]);
4293-
4294-
if ((actual_atts+tblinfo[i].ncheck)>0)
4295-
appendPQExpBuffer(q,",\n\t");
4296-
4297-
appendPQExpBuffer(q,"%s",consDef->data);
4298-
4299-
destroyPQExpBuffer(consDef);
4300-
}
4301-
4272+
/*
4273+
* Primary Key: In versions of PostgreSQL prior to 7.2, we
4274+
* needed to include the primary key in the table definition.
4275+
* However, this is not ideal because it creates an index
4276+
* on the table, which makes COPY slower. As of release 7.2,
4277+
* we can add primary keys to a table after is has been created,
4278+
* using ALTER TABLE ; see dumpIndexes() for more information.
4279+
* Therefore, we ignore primary keys in this function.
4280+
*/
43024281

43034282
appendPQExpBuffer(q,"\n)");
43044283

@@ -4454,27 +4433,19 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
44544433
/* Handle PK indexes */
44554434
if (strcmp(indinfo[i].indisprimary,"t")==0)
44564435
{
4457-
#if0
4458-
4459-
/*
4460-
* PK: Enable this code when ALTER TABLE supports PK
4461-
* constraints.
4462-
*/
4463-
44644436
PQExpBufferconsDef=getPKconstraint(&tblinfo[tableInd],&indinfo[i]);
44654437

44664438
resetPQExpBuffer(q);
44674439

44684440
appendPQExpBuffer(q,"Alter Table %s Add %s;",
4469-
fmtId(tblinfo[tableInd].relname,force_quotes),
4441+
fmtId(tblinfo[tableInd].relname,force_quotes),
44704442
consDef->data);
44714443

4472-
ArchiveEntry(fout,indinfo[i].oid,tblinfo[tableInd].primary_key_name,
4444+
ArchiveEntry(fout,indinfo[i].indexreloid,tblinfo[tableInd].primary_key_name,
44734445
"CONSTRAINT",NULL,q->data,"",
44744446
"",tblinfo[tableInd].usename,NULL,NULL);
44754447

44764448
destroyPQExpBuffer(consDef);
4477-
#endif
44784449

44794450
/*
44804451
* Don't need to do anything else for this system-generated

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp