From: Tom Lane <tgl@sss.pgh.pa.us>
To: a.schmitz@cityweb.de
Cc: Oleg Bartunov <oleg@sai.msu.su>
Cc: Teodor Sigaev <teodor@stack.net>
Cc: pgsql-hackers@postgreSQL.org
Subject: CLUSTER loses nulls (was Re: [ADMIN] Still a bug in the VACUUM)
Date: Fri, 28 Feb 2003 18:54:13 -0500
Message-ID: <8187.1046476453@sss.pgh.pa.us> (raw)
In-Reply-To: <6523.1046464854@sss.pgh.pa.us>
References: <200302141552.32907.a.schmitz@cityweb.de>
<200302151251.09162.a.schmitz@cityweb.de>
<16338.1045325038@sss.pgh.pa.us>
<200302281016.29799.a.schmitz@cityweb.de>
<6523.1046464854@sss.pgh.pa.us>
I said:
> I was able to reproduce a problem as follows: run the tsearch regression
> test, then do "cluster wowidx on test_txtidx". This appears to lose
> one row:
Ahh ... it took me way too long to realize what was happening. The
problem is simply that GiST indexes do not index nulls (at least not in
the first column of an index). So if you CLUSTER, you lose any rows
that contain NULLs in the indexed column --- they're not in the index,
so they're not seen by the indexscan that copies the data over to the
new table.
Having CLUSTER lose data is obviously not acceptable :-(. I can see two
possible solutions:
* Make CLUSTER error out if the target index is not of an 'amindexnulls'
index AM. This would amount to restricting CLUSTER to b-trees, which is
annoying.
* If the index is not amindexnulls and the first target column is not
marked attnotnull, make an extra seqscan pass over the source table to
look for rows containing nulls. Copy these rows separately. This would
work but adds a good deal of overhead.
Approach #2 is even worse for functional indexes --- attnotnull is not
helpful. We'd have to actually evaluate the function at every single
row to see if it yields NULL there. Yech.
It occurs to me also that the same kind of pitfall exists for partial
indexes: cluster on a partial index, you lose. However, I don't have
a problem with simply refusing to cluster on partial indexes.
Comments? Anyone want to do the legwork to fix this?
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, a.schmitz@cityweb.de, oleg@sai.msu.su, teodor@stack.net, pgsql-hackers@postgreSQL.org
Subject: Re: CLUSTER loses nulls (was Re: [ADMIN] Still a bug in the VACUUM)
In-Reply-To: <8187.1046476453@sss.pgh.pa.us>
References: <200302141552.32907.a.schmitz@cityweb.de> <200302151251.09162.a.schmitz@cityweb.de> <16338.1045325038@sss.pgh.pa.us> <200302281016.29799.a.schmitz@cityweb.de> <6523.1046464854@sss.pgh.pa.us> <8187.1046476453@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox