summaryrefslogtreecommitdiff
path: root/src/backend/commands/indexcmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-01-03 23:21:32 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-01-03 23:21:32 +0000
commitdc6b4deb9717a9f03b2f93baca9f93f13786e26b (patch)
tree586c04579f3337cc8fdbbc342eefbb0bdf21e607 /src/backend/commands/indexcmds.c
parentd02f0aaa3b7313cabd9e64deb34ab630832730ce (diff)
Require ownership permission for CREATE INDEX, per bug report.
Disallow CREATE INDEX on system catalogs, non-tables (views, sequences, etc). Disallow CREATE/DROP TRIGGER on system catalogs, non-tables. Disallow ALTER TABLE ADD/DROP CONSTRAINT on system catalogs. Disallow FOREIGN KEY reference to non-table. None of these things can actually work in the present system structure, but the code was letting them pass without complaint.
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r--src/backend/commands/indexcmds.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index a22e111ef4a..4aa14844358 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.61 2001/11/20 02:46:13 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.62 2002/01/03 23:19:36 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -73,6 +73,7 @@ DefineIndex(char *heapRelationName,
Oid *classObjectId;
Oid accessMethodId;
Oid relationId;
+ Relation rel;
HeapTuple tuple;
Form_pg_am accessMethodForm;
IndexInfo *indexInfo;
@@ -90,12 +91,25 @@ DefineIndex(char *heapRelationName,
INDEX_MAX_KEYS);
/*
- * compute heap relation id
+ * Open heap relation, acquire a suitable lock on it, remember its OID
*/
- if ((relationId = RelnameFindRelid(heapRelationName)) == InvalidOid)
- elog(ERROR, "DefineIndex: relation \"%s\" not found",
+ rel = heap_openr(heapRelationName, ShareLock);
+
+ /* Note: during bootstrap may see uncataloged relation */
+ if (rel->rd_rel->relkind != RELKIND_RELATION &&
+ rel->rd_rel->relkind != RELKIND_UNCATALOGED)
+ elog(ERROR, "DefineIndex: relation \"%s\" is not a table",
heapRelationName);
+ relationId = RelationGetRelid(rel);
+
+ heap_close(rel, NoLock);
+
+ if (!IsBootstrapProcessingMode() &&
+ IsSystemRelationName(heapRelationName) &&
+ !IndexesAreActive(relationId, false))
+ elog(ERROR, "Existing indexes are inactive. REINDEX first");
+
/*
* look up the access method, verify it can handle the requested
* features
@@ -131,9 +145,6 @@ DefineIndex(char *heapRelationName,
CheckPredicate(cnfPred, rangetable, relationId);
}
- if (!IsBootstrapProcessingMode() && IsSystemRelationName(heapRelationName) && !IndexesAreActive(relationId, false))
- elog(ERROR, "Existing indexes are inactive. REINDEX first");
-
/*
* Prepare arguments for index_create, primarily an IndexInfo
* structure