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

Commit90c35a9

Browse files
committed
Code cleanup for REINDEX DATABASE/SCHEMA/SYSTEM.
Fix some minor infelicities. Some of these things were introduced incommitfe263d1, and some are older.
1 parentac09142 commit90c35a9

File tree

3 files changed

+34
-56
lines changed

3 files changed

+34
-56
lines changed

‎src/backend/commands/indexcmds.c

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,37 +1780,37 @@ ReindexTable(RangeVar *relation)
17801780
}
17811781

17821782
/*
1783-
*ReindexObject
1784-
*Recreate indexes ofobject whose type is definedby objectKind.
1783+
*ReindexMultipleTables
1784+
*Recreate indexes oftables selectedbyobjectName/objectKind.
17851785
*
17861786
* To reduce the probability of deadlocks, each table is reindexed in a
17871787
* separate transaction, so we can release the lock on it right away.
17881788
* That means this must not be called within a user transaction block!
17891789
*/
1790-
Oid
1791-
ReindexObject(constchar*objectName,ReindexObjectTypeobjectKind)
1790+
void
1791+
ReindexMultipleTables(constchar*objectName,ReindexObjectTypeobjectKind)
17921792
{
17931793
OidobjectOid;
17941794
RelationrelationRelation;
17951795
HeapScanDescscan;
1796-
ScanKeyData*scan_keys=NULL;
1796+
ScanKeyDatascan_keys[1];
17971797
HeapTupletuple;
17981798
MemoryContextprivate_context;
17991799
MemoryContextold;
18001800
List*relids=NIL;
18011801
ListCell*l;
1802-
intnum_keys;
1802+
intnum_keys;
18031803

18041804
AssertArg(objectName);
18051805
Assert(objectKind==REINDEX_OBJECT_SCHEMA||
18061806
objectKind==REINDEX_OBJECT_SYSTEM||
18071807
objectKind==REINDEX_OBJECT_DATABASE);
18081808

18091809
/*
1810-
* Get OID of object to reindex, being the database currently being
1811-
*usedby session for a database or for system catalogs, or the schema
1812-
*definedby caller. At the same time do permission checks that need
1813-
*differentprocessing depending on the object type.
1810+
* Get OID of object to reindex, being the database currently being used
1811+
* by session for a database or for system catalogs, or the schema defined
1812+
* by caller. At the same time do permission checks that need different
1813+
* processing depending on the object type.
18141814
*/
18151815
if (objectKind==REINDEX_OBJECT_SCHEMA)
18161816
{
@@ -1824,11 +1824,11 @@ ReindexObject(const char *objectName, ReindexObjectType objectKind)
18241824
{
18251825
objectOid=MyDatabaseId;
18261826

1827-
if (strcmp(objectName,get_database_name(MyDatabaseId))!=0)
1827+
if (strcmp(objectName,get_database_name(objectOid))!=0)
18281828
ereport(ERROR,
18291829
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
18301830
errmsg("can only reindex the currently open database")));
1831-
if (!pg_database_ownercheck(MyDatabaseId,GetUserId()))
1831+
if (!pg_database_ownercheck(objectOid,GetUserId()))
18321832
aclcheck_error(ACLCHECK_NOT_OWNER,ACL_KIND_DATABASE,
18331833
objectName);
18341834
}
@@ -1840,42 +1840,19 @@ ReindexObject(const char *objectName, ReindexObjectType objectKind)
18401840
* abort cleanup logic.
18411841
*/
18421842
private_context=AllocSetContextCreate(PortalContext,
1843-
(objectKind==REINDEX_OBJECT_SCHEMA) ?
1844-
"ReindexSchema" :"ReindexDatabase",
1843+
"ReindexMultipleTables",
18451844
ALLOCSET_DEFAULT_MINSIZE,
18461845
ALLOCSET_DEFAULT_INITSIZE,
18471846
ALLOCSET_DEFAULT_MAXSIZE);
18481847

18491848
/*
1850-
* We always want to reindex pg_class first when reindexing system
1851-
* catalogs or a database. This ensures that if there is any corruption
1852-
* in pg_class' indexes, they will be fixed before we process any other
1853-
* tables. This is critical because reindexing itself will try to
1854-
* update pg_class.
1855-
*/
1856-
if (objectKind==REINDEX_OBJECT_DATABASE||
1857-
objectKind==REINDEX_OBJECT_SYSTEM||
1858-
(objectKind==REINDEX_OBJECT_SCHEMA&&
1859-
IsSystemNamespace(objectOid)))
1860-
{
1861-
old=MemoryContextSwitchTo(private_context);
1862-
relids=lappend_oid(relids,RelationRelationId);
1863-
MemoryContextSwitchTo(old);
1864-
}
1865-
1866-
/*
1867-
* Define the search keys to find the objects to reindex. For a schema,
1868-
* we search target relations using relnamespace and relkind, something
1869-
* not necessary for a database-wide operation.
1849+
* Define the search keys to find the objects to reindex. For a schema, we
1850+
* select target relations using relnamespace, something not necessary for
1851+
* a database-wide operation.
18701852
*/
18711853
if (objectKind==REINDEX_OBJECT_SCHEMA)
18721854
{
1873-
/*
1874-
* Return all objects in schema. We filter out
1875-
* inappropriate objects as we walk through results.
1876-
*/
18771855
num_keys=1;
1878-
scan_keys=palloc(sizeof(ScanKeyData));
18791856
ScanKeyInit(&scan_keys[0],
18801857
Anum_pg_class_relnamespace,
18811858
BTEqualStrategyNumber,F_OIDEQ,
@@ -1898,8 +1875,8 @@ ReindexObject(const char *objectName, ReindexObjectType objectKind)
18981875
Oidrelid=HeapTupleGetOid(tuple);
18991876

19001877
/*
1901-
* Only regular tables and matviews can have indexes,
1902-
*so filter out anyother kind ofobject.
1878+
* Only regular tables and matviews can have indexes, so ignore any
1879+
* other kind ofrelation.
19031880
*/
19041881
if (classtuple->relkind!=RELKIND_RELATION&&
19051882
classtuple->relkind!=RELKIND_MATVIEW)
@@ -1911,20 +1888,25 @@ ReindexObject(const char *objectName, ReindexObjectType objectKind)
19111888
continue;
19121889

19131890
/* Check user/system classification, and optionally skip */
1914-
if (!IsSystemClass(relid,classtuple)&&
1915-
objectKind==REINDEX_OBJECT_SYSTEM)
1891+
if (objectKind==REINDEX_OBJECT_SYSTEM&&
1892+
!IsSystemClass(relid,classtuple))
19161893
continue;
19171894

1895+
/* Save the list of relation OIDs in private context */
1896+
old=MemoryContextSwitchTo(private_context);
1897+
19181898
/*
1919-
* Already have it in the case of system catalogs being all
1920-
* reindexed, of a database or of a system catalog being reindexed
1921-
* as a schema.
1899+
* We always want to reindex pg_class first if it's selected to be
1900+
* reindexed. This ensures that if there is any corruption in
1901+
* pg_class' indexes, they will be fixed before we process any other
1902+
* tables. This is critical because reindexing itself will try to
1903+
* update pg_class.
19221904
*/
1923-
if (HeapTupleGetOid(tuple)==RelationRelationId)
1924-
continue;
1905+
if (relid==RelationRelationId)
1906+
relids=lcons_oid(relid,relids);
1907+
else
1908+
relids=lappend_oid(relids,relid);
19251909

1926-
old=MemoryContextSwitchTo(private_context);
1927-
relids=lappend_oid(relids,relid);
19281910
MemoryContextSwitchTo(old);
19291911
}
19301912
heap_endscan(scan);
@@ -1953,8 +1935,4 @@ ReindexObject(const char *objectName, ReindexObjectType objectKind)
19531935
StartTransactionCommand();
19541936

19551937
MemoryContextDelete(private_context);
1956-
if (scan_keys)
1957-
pfree(scan_keys);
1958-
1959-
returnobjectOid;
19601938
}

‎src/backend/tcop/utility.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ standard_ProcessUtility(Node *parsetree,
756756
(stmt->kind==REINDEX_OBJECT_SCHEMA) ?"REINDEX SCHEMA" :
757757
(stmt->kind==REINDEX_OBJECT_SYSTEM) ?"REINDEX SYSTEM" :
758758
"REINDEX DATABASE");
759-
ReindexObject(stmt->name,stmt->kind);
759+
ReindexMultipleTables(stmt->name,stmt->kind);
760760
break;
761761
default:
762762
elog(ERROR,"unrecognized object type: %d",

‎src/include/commands/defrem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern ObjectAddress DefineIndex(Oid relationId,
3131
boolquiet);
3232
externOidReindexIndex(RangeVar*indexRelation);
3333
externOidReindexTable(RangeVar*relation);
34-
externOidReindexObject(constchar*databaseName,ReindexObjectTypekind);
34+
externvoidReindexMultipleTables(constchar*objectName,ReindexObjectTypeobjectKind);
3535
externchar*makeObjectName(constchar*name1,constchar*name2,
3636
constchar*label);
3737
externchar*ChooseRelationName(constchar*name1,constchar*name2,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp