TRUNCATE+COPY optimization and --jobs=1 in pg_restore

From: Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: TRUNCATE+COPY optimization and --jobs=1 in pg_restore
Date: 2010-02-10 02:56:54
Message-ID: 20100210115654.47E4.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

We have an optimization to bulkload date in pg_restore, but the code
only works in parallel restore (--jobs >= 2). Why don't we do the
same optimization in the serial restore (--jobs = 1) ?

We checks is_parallel to decide to use BEGIN-TRUNCATE-COPY:
if (is_parallel && te->created)
but we can always do it unless --single-transaction, right?
if (!ropt->single_txn && te->created)

[ in restore_toc_entry() ]
/*
* In parallel restore, if we created the table earlier in
* the run then we wrap the COPY in a transaction and
* precede it with a TRUNCATE. If archiving is not on
* this prevents WAL-logging the COPY. This obtains a
* speedup similar to that from using single_txn mode in
* non-parallel restores.
*/
if (is_parallel && te->created) <==== HERE
{
/*
* Parallel restore is always talking directly to a
* server, so no need to see if we should issue BEGIN.
*/
StartTransaction(AH);

/*
* If the server version is >= 8.4, make sure we issue
* TRUNCATE with ONLY so that child tables are not
* wiped.
*/
ahprintf(AH, "TRUNCATE TABLE %s%s;\n\n",
(PQserverVersion(AH->connection) >= 80400 ?
"ONLY " : ""),
fmtId(te->tag));
}

Regards,
---
Takahiro Itagaki
NTT Open Source Software Center

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message M Z 2010-02-10 03:35:33 Re: CVS checkout source code for different branches
Previous Message M Z 2010-02-10 02:51:52 Re: CVS checkout source code for different branches