diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-09-19 19:57:42 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-09-19 19:57:42 +0000 |
commit | 28847ae77d8947f32fa96cb68f7f3d1b5ca2ae30 (patch) | |
tree | 42307f4937ec42c1c2d696636a2134faa91e7860 /src/backend/commands/indexcmds.c | |
parent | 580e08a98b219b4ac69f68ce706858d8708afd46 (diff) | |
download | postgresql-28847ae77d8947f32fa96cb68f7f3d1b5ca2ae30.tar.gz postgresql-28847ae77d8947f32fa96cb68f7f3d1b5ca2ae30.zip |
Seems like a bad idea that REINDEX TABLE supports (or thinks it does)
reindexing system tables without ignoring system indexes, when the
other two varieties of REINDEX disallow it. Make all three act the same,
and simplify downstream code accordingly.
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r-- | src/backend/commands/indexcmds.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 45f4c3b4f7d..3021eeaf4c3 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.106 2003/08/17 19:58:04 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.107 2003/09/19 19:57:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -658,17 +658,41 @@ void ReindexTable(RangeVar *relation, bool force) { Oid heapOid; - char relkind; + HeapTuple tuple; heapOid = RangeVarGetRelid(relation, false); - relkind = get_rel_relkind(heapOid); + tuple = SearchSysCache(RELOID, + ObjectIdGetDatum(heapOid), + 0, 0, 0); + if (!HeapTupleIsValid(tuple)) /* shouldn't happen */ + elog(ERROR, "cache lookup failed for relation %u", heapOid); - if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE) + if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_RELATION && + ((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_TOASTVALUE) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("relation \"%s\" is not a table", relation->relname))); + if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) && + !IsToastClass((Form_pg_class) GETSTRUCT(tuple))) + { + if (!allowSystemTableMods) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("permission denied: \"%s\" is a system table", + relation->relname), + errhint("Do REINDEX in standalone postgres with -O -P options."))); + if (!IsIgnoringSystemIndexes()) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("permission denied: \"%s\" is a system table", + relation->relname), + errhint("Do REINDEX in standalone postgres with -P -O options."))); + } + + ReleaseSysCache(tuple); + /* * In-place REINDEX within a transaction block is dangerous, because * if the transaction is later rolled back we have no way to undo |