Index: src/backend/commands/cluster.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/cluster.c,v retrieving revision 1.86 diff -c -r1.86 cluster.c *** src/backend/commands/cluster.c 2002/08/11 21:17:34 1.86 --- src/backend/commands/cluster.c 2002/08/21 03:47:10 *************** *** 45,55 **** IndexInfo *indexInfo; Oid accessMethodOID; Oid *classOID; } IndexAttrs; static Oid make_new_heap(Oid OIDOldHeap, const char *NewName); static void copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex); ! static List *get_indexattr_list(Relation OldHeap); static void recreate_indexattr(Oid OIDOldHeap, List *indexes); static void swap_relfilenodes(Oid r1, Oid r2); --- 45,56 ---- IndexInfo *indexInfo; Oid accessMethodOID; Oid *classOID; + bool isclustered; } IndexAttrs; static Oid make_new_heap(Oid OIDOldHeap, const char *NewName); static void copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex); ! static List *get_indexattr_list(Relation OldHeap, Oid OldIndex); static void recreate_indexattr(Oid OIDOldHeap, List *indexes); static void swap_relfilenodes(Oid r1, Oid r2); *************** *** 121,127 **** RelationGetRelationName(OldHeap)); /* Save the information of all indexes on the relation. */ ! indexes = get_indexattr_list(OldHeap); /* Drop relcache refcnts, but do NOT give up the locks */ index_close(OldIndex); --- 122,128 ---- RelationGetRelationName(OldHeap)); /* Save the information of all indexes on the relation. */ ! indexes = get_indexattr_list(OldHeap, OIDOldIndex); /* Drop relcache refcnts, but do NOT give up the locks */ index_close(OldIndex); *************** *** 274,280 **** * return a list of IndexAttrs structures. */ static List * ! get_indexattr_list(Relation OldHeap) { List *indexes = NIL; List *indlist; --- 275,281 ---- * return a list of IndexAttrs structures. */ static List * ! get_indexattr_list(Relation OldHeap, Oid OldIndex) { List *indexes = NIL; List *indlist; *************** *** 305,310 **** --- 306,317 ---- memcpy(attrs->classOID, indexForm->indclass, sizeof(Oid) * attrs->indexInfo->ii_NumIndexAttrs); + /* We'll set indisclustered at index creation time on the + * index we are currently clustering, and reset it on other + * indexes. + */ + attrs->isclustered = (OldIndex == indexOID ? true : false); + /* Name and access method of each index come from pg_class */ classTuple = SearchSysCache(RELOID, ObjectIdGetDatum(indexOID), *************** *** 343,348 **** --- 350,358 ---- Oid newIndexOID; char newIndexName[NAMEDATALEN]; ObjectAddress object; + Form_pg_index index; + HeapTuple tuple; + Relation pg_index; /* Create the new index under a temporary name */ snprintf(newIndexName, NAMEDATALEN, "pg_temp_%u", attrs->indexOID); *************** *** 363,368 **** --- 373,392 ---- swap_relfilenodes(attrs->indexOID, newIndexOID); CommandCounterIncrement(); + + /* Set indisclustered to the correct value. Only one index is + * allowed to be clustered. + */ + pg_index = heap_openr(IndexRelationName, RowExclusiveLock); + tuple = SearchSysCacheCopy(INDEXRELID, + ObjectIdGetDatum(attrs->indexOID), + 0, 0, 0); + index = (Form_pg_index) GETSTRUCT(tuple); + index->indisclustered = attrs->isclustered; + simple_heap_update(pg_index, &tuple->t_self, tuple); + CatalogUpdateIndexes(pg_index, tuple); + heap_freetuple(tuple); + heap_close(pg_index, NoLock); /* Destroy new index with old filenode */ object.classId = RelOid_pg_class; Index: src/test/regress/expected/cluster.out =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/test/regress/expected/cluster.out,v retrieving revision 1.2 diff -c -r1.2 cluster.out *** src/test/regress/expected/cluster.out 2002/08/11 21:17:35 1.2 --- src/test/regress/expected/cluster.out 2002/08/21 03:47:34 *************** *** 274,276 **** --- 274,287 ---- clstr_tst_s_rf_a_seq | S | f (11 rows) + -- Verify that indisclustered is correctly set + SELECT pg_class.relname FROM pg_index, pg_class, pg_class AS pg_class_2 + WHERE pg_class.oid=indexrelid + AND indrelid=pg_class_2.oid + AND pg_class_2.relname = 'clstr_tst' + AND indisclustered; + relname + ------------- + clstr_tst_c + (1 row) + Index: src/test/regress/sql/cluster.sql =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/test/regress/sql/cluster.sql,v retrieving revision 1.3 diff -c -r1.3 cluster.sql *** src/test/regress/sql/cluster.sql 2002/08/11 21:17:35 1.3 --- src/test/regress/sql/cluster.sql 2002/08/21 03:47:35 *************** *** 79,81 **** --- 79,88 ---- SELECT relname, relkind, EXISTS(SELECT 1 FROM pg_class WHERE oid = c.reltoastrelid) AS hastoast FROM pg_class c WHERE relname LIKE 'clstr_tst%' ORDER BY relname; + + -- Verify that indisclustered is correctly set + SELECT pg_class.relname FROM pg_index, pg_class, pg_class AS pg_class_2 + WHERE pg_class.oid=indexrelid + AND indrelid=pg_class_2.oid + AND pg_class_2.relname = 'clstr_tst' + AND indisclustered;