BUG #5738: btree index search bug

Поиск
Список
Период
Сортировка
Искать

BUG #5738: btree index search bug

От:
"spche" <spche@163.com>
Дата:
The following bug has been logged online:

Bug reference:      5738
Logged by:          spche
Email address:      spche@163.com
PostgreSQL version: 9.01
Operating system:   Winxp
Description:        btree index search bug
Details: 

create table a (a int);
create index a_a on a(a);

insert into a values(1);
insert into a values(2);

insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;
insert into a select * from a;

delete from a where a=3;

CREATE or replace FUNCTION aa() RETURNS integer AS $$
DECLARE
    curs2 cursor for SELECT a FROM a where a=3;
    rowv1 integer DEFAULT 0;
    rowv2 integer DEFAULT 32;
    cou1 integer DEFAULT 0;
BEGIN
		
    insert into a values(3);
		OPEN curs2;
		FETCH curs2 INTO rowv1;
		
		IF FOUND THEN
    	cou1 := cou1 + 1 ;
		END IF;
		insert into a values(3);
		insert into a values(3);
		insert into a values(3);
		--update a set a=4 where a=3;
		
		FETCH curs2 INTO rowv2;
		IF FOUND THEN
    	cou1 := cou1 + 1 ;
		END IF;
		
		FETCH curs2 INTO rowv2;
		IF FOUND THEN
    	cou1 := cou1 + 1 ;
		END IF;
		
		FETCH curs2 INTO rowv2;
		IF FOUND THEN
    	cou1 := cou1 + 1 ;
		END IF;
		
		close curs2;
    RETURN cou1;
END;
$$ LANGUAGE plpgsql;
select aa();


the result is 1; the index scan is not updated;
because static bool
_bt_readpage(IndexScanDesc scan, ScanDirection dir, OffsetNumber offnum)
copy a old version, and not update when new version come.

Re: BUG #5738: btree index search bug

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"spche"  writes:
> Description:        btree index search bug

I see no bug here.  The cursor is opened at a time when there is one
row with a=3, so it can find only that one row because of its snapshot.

			regards, tom lane
FAQ