Skip site navigation (1) Skip section navigation (2)

Re: temporary tables, indexes, and query plans

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jon Nelson <jnelson+pgsql(at)jamponi(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: temporary tables, indexes, and query plans
Date: 2010-10-27 21:45:53
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Jon Nelson <jnelson+pgsql(at)jamponi(dot)net> writes:
> The sequence goes exactly like this:

> CREATE TEMPORARY TABLE (20 columns, mostly text, a few int).
> COPY (approx 8 million rows, ~900 MB)[1]
> UPDATE (2.8 million of the rows)
> UPDATE (7 rows)
> UPDATE (250 rows)
> UPDATE (3500 rows)
> UPDATE (3100 rows)
> a bunch of UPDATE (1 row)
> ...

> Experimentally, I noticed that performance was not especially great.
> So, I added some indexes (three indexes on one column each). One index
> is UNIQUE.
> The first UPDATE can't use any of the indexes. The rest should be able to.

Please ... there is *nothing* exact about that.  It's not even clear
what the datatypes of the indexed columns are, let alone what their
statistics are, or whether there's something specific about how you're
declaring the table or the indexes.

Here's an exact test case, which is something I just tried to see if
I could easily reproduce your results:

create temp table foo (f1 int, f2 text, f3 text);
insert into foo select x, 'xyzzy', x::text from generate_series(1,1000000) x;
update foo set f2 = 'bogus' where f1 < 500000;
explain update foo set f2 = 'zzy' where f1 = 42;
create index fooi on foo(f1);
explain update foo set f2 = 'zzy' where f1 = 42;
analyze foo;
explain update foo set f2 = 'zzy' where f1 = 42;

I get a seqscan, a bitmap index scan, then a plain indexscan, which
is about what I'd expect.  Clearly there's something you're doing
that deviates from this, but you are failing to provide the detail
necessary to figure out what the critical difference is.

			regards, tom lane

In response to


pgsql-performance by date

Next:From: Tom LaneDate: 2010-10-27 21:49:42
Subject: Re: Select count(*), the sequel
Previous:From: André VolpatoDate: 2010-10-27 20:56:52
Subject: Re: AIX slow buffer reads

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group