The following bug has been logged online:
Bug reference: 2830
Logged by:
Email address: martin.pihlak@gmail.com
PostgreSQL version: 8.2.0, older
Operating system: Ubuntu 6.10 2.6.17-10-386, libc6 2.4-1ubuntu12
Description: Wrong results for prepared statements while clustering
target table
Details:
Prepared SELECT/UPDATE/DELETE statements produce wrong results if executed
while target table is being clustered. Only seems to happens when CLUSTER
and statement are executed in different sessions. Tested on 8.0.6, 8.0.8,
8.1.4 and 8.2.0, reproducible with the following test case:
create table test(i integer);
-- generate large enough table, so that clustering takes more than 1 sec
insert into test select * from generate_series(1,1000000);
create index test_idx on test(i);
prepare c as select count(*) from test;
\! psql -c "cluster test_idx on test" &
-- sleep to make sure we stay behind cluster
\! sleep 1
-- should produce same values
execute c;
select count(1) from test;
Executing 'c' after CLUSTER returns 0 instead of 1000000.