Re: COPY and indices?

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: hamann(dot)w(at)t-online(dot)de
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: COPY and indices?
Date: 2012-03-13 15:15:53
Message-ID: CAOR=d=2YPLXQGi7RF+vL1ge59tR-oTsMS5qJETWNDw9QoevJdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Mar 13, 2012 at 12:51 AM, <hamann(dot)w(at)t-online(dot)de> wrote:
>
> Scott Marlowe wrote:
> 2012/3/12 François Beausoleil <francois(at)teksol(dot)info>:
>> Hi all,
>>
>> When using COPY FROM STDIN to stream thousands of rows (20k and more hourly), what happens with indices? Are they updated only once after the operation, or are they updated once per row? Note that I'm not replacing the table's data: I'm appending to what's already there. I suspect batching writes will be faster than writing each individual row using an INSERT statement.
>
> Copy is faster, but if a single row fails (dup key etc) the whole copy fails.
>
> Hi Scott,
>
> my impression: it would be even faster to drop the indices, do the bulk copy,
> and rebuild the indices after the fact.

That depends. If you've got 100M rows already in place and you're
adding 1000 rows, it's likely cheaper to leave the indexes in place.
OTOH, if you've 1M rows already in place and are adding 100M it's
almost certainly cheaper to drop the indexes and recreate them. So
dropping and recreating the indexes isn't necessarily faster,
depending on how big the table already is.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jerry Richards 2012-03-13 16:07:53 Allowing Other Users to Alter a Table
Previous Message François Beausoleil 2012-03-13 14:57:06 Re: COPY and indices?