Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit475cb15

Browse files
committed
Squash some more CLUSTER bugs. Never has worked on multiple-column
indexes, apparently, nor on functional indexes with more than one inputcolumn (force of natts = 1 was in the wrong branch of IF statement).Coredumped if source relation contained any uncommitted tuples, due tofailure to test for success return from heap_fetch. Fetched tuplewas passed directly to heap_insert, which clobbers the TID and commitstatus in the tuple header it's given, which meant that the sourcerelation's tuples all got trashed as the copy proceeded. Abort partwaythrough, and you're left with a lot of missing tuples.I wonder what else is lurking here ...
1 parentbe4ae8f commit475cb15

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

‎src/backend/commands/cluster.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.52 2000/05/11 03:54:17 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.53 2000/05/12 16:10:09 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -258,11 +258,11 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
258258
Assert(pg_proc_Tuple);
259259
pg_proc_Form= (Form_pg_proc)GETSTRUCT(pg_proc_Tuple);
260260
namecpy(&(finfo->funcName),&(pg_proc_Form->proname));
261+
natts=1;/* function result is a single column */
261262
}
262263
else
263264
{
264265
finfo= (FuncIndexInfo*)NULL;
265-
natts=1;
266266
}
267267

268268
index_create(RelationGetRelationName(NewHeap),
@@ -273,7 +273,8 @@ copy_index(Oid OIDOldIndex, Oid OIDNewHeap)
273273
natts,
274274
Old_pg_index_Form->indkey,
275275
Old_pg_index_Form->indclass,
276-
(uint16)0, (Datum)NULL,NULL,
276+
(uint16)0, (Datum*)NULL,
277+
(Node*)NULL,/* XXX where's the predicate? */
277278
Old_pg_index_Form->indislossy,
278279
Old_pg_index_Form->indisunique,
279280
Old_pg_index_Form->indisprimary);
@@ -313,8 +314,20 @@ rebuildheap(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex)
313314
LocalHeapTuple.t_datamcxt=NULL;
314315
LocalHeapTuple.t_data=NULL;
315316
heap_fetch(LocalOldHeap,SnapshotNow,&LocalHeapTuple,&LocalBuffer);
316-
heap_insert(LocalNewHeap,&LocalHeapTuple);
317-
ReleaseBuffer(LocalBuffer);
317+
if (LocalHeapTuple.t_data!=NULL) {
318+
/*
319+
* We must copy the tuple because heap_insert() will overwrite
320+
* the commit-status fields of the tuple it's handed, and the
321+
* retrieved tuple will actually be in a disk buffer! Thus,
322+
* the source relation would get trashed, which is bad news
323+
* if we abort later on. (This was a bug in releases thru 7.0)
324+
*/
325+
HeapTuplecopiedTuple=heap_copytuple(&LocalHeapTuple);
326+
327+
ReleaseBuffer(LocalBuffer);
328+
heap_insert(LocalNewHeap,copiedTuple);
329+
heap_freetuple(copiedTuple);
330+
}
318331
pfree(ScanResult);
319332
}
320333

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp