77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.36 1999/03/28 20:31:56 vadim Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.37 1999/04/12 16:56:08 vadim Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -100,11 +100,12 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, Relation heapRel
100100if (!PageIsEmpty (page )&& offset <=maxoff )
101101{
102102TupleDesc itupdesc ;
103- BTItem btitem ;
103+ BTItem cbti ;
104104HeapTupleData htup ;
105105BTPageOpaque opaque ;
106106Buffer nbuf ;
107107BlockNumber blkno ;
108+ bool chtup = true;
108109
109110itupdesc = RelationGetDescr (rel );
110111nbuf = InvalidBuffer ;
@@ -121,8 +122,22 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, Relation heapRel
121122 */
122123while (_bt_isequal (itupdesc ,page ,offset ,natts ,itup_scankey ))
123124{/* they're equal */
124- btitem = (BTItem )PageGetItem (page ,PageGetItemId (page ,offset ));
125- htup .t_self = btitem -> bti_itup .t_tid ;
125+ /*
126+ * Have to check is inserted heap tuple deleted one
127+ * (i.e. just moved to another place by vacuum)!
128+ */
129+ if (chtup )
130+ {
131+ htup .t_self = btitem -> bti_itup .t_tid ;
132+ heap_fetch (heapRel ,SnapshotDirty ,& htup ,& buffer );
133+ if (htup .t_data == NULL )/* YES! */
134+ break ;
135+ /* Live tuple was inserted */
136+ ReleaseBuffer (buffer );
137+ chtup = false;
138+ }
139+ cbti = (BTItem )PageGetItem (page ,PageGetItemId (page ,offset ));
140+ htup .t_self = cbti -> bti_itup .t_tid ;
126141heap_fetch (heapRel ,SnapshotDirty ,& htup ,& buffer );
127142if (htup .t_data != NULL )/* it is a duplicate */
128143{