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-11-13 15:41:12
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Jon Nelson <jnelson+pgsql(at)jamponi(dot)net> writes:
> OK. This is a highly distilled example that shows the behavior.

> CREATE TEMPORARY TABLE foo AS SELECT x AS A, chr(x % 75 + 32) AS b,
> ''::text AS c from generate_series(1,500) AS x;
> UPDATE foo SET c = 'foo' WHERE b = 'A' ;
> CREATE INDEX foo_b_idx on foo (b);
> [ and the rest of the transaction can't use that index ]

OK, this is an artifact of the "HOT update" optimization.  Before
creating the index, you did updates on the table that would have been
executed differently if the index had existed.  When the index does get
created, its entries for those updates are incomplete, so the index
can't be used in transactions that could in principle see the unmodified

You could avoid this effect either by creating the index before you do
any updates on the table, or by not wrapping the entire process into a
single transaction.

			regards, tom lane

In response to


pgsql-performance by date

Next:From: Jon NelsonDate: 2010-11-13 16:14:54
Subject: Re: temporary tables, indexes, and query plans
Previous:From: Tom LaneDate: 2010-11-13 14:57:29
Subject: Re: do temporary tables have hint bits?

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