*really* bad insert performance on table with unique index

From: Jon Nelson <jnelson+pgsql(at)jamponi(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: *really* bad insert performance on table with unique index
Date: 2012-02-02 17:28:09
Message-ID: CAKuK5J3VjrXJGW+noBo=fk8vBX5tFVpbnb7oKsdPpucOxUq6LA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

I created a table with two columns: an id SERIAL (primary key) and a
text (not null), and then added a unique index on the text field.
Then I ran the following query (with a huge work_mem - 20GB):

insert into tableA (text_field) select distinct other_text_field from
some_huge_set_of_tables

After 36 hours it had only written 3 GB (determined by looking at what
files it was writing to).
I started over with a TRUNCATE, and then removed the index and tried again.
This time it took 3807270.780 ms (a bit over an hour).
Total number of records: approx 227 million, comprising 16GB of storage.

Why the huge discrepancy?

--
Jon

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Alessandro Gagliardi 2012-02-02 19:38:13 Re: From Simple to Complex
Previous Message Gudmundur Johannesson 2012-02-02 16:41:37 Re: Index with all necessary columns - Postgres vs MSSQL