diff options
author | Bruce Momjian <bruce@momjian.us> | 2000-09-12 04:49:17 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2000-09-12 04:49:17 +0000 |
commit | 264c0682077fe9ec5c9bd366f756451db397d4fb (patch) | |
tree | 22ae0abba34aab4e25024f081b52781f33022963 /src/backend/commands/command.c | |
parent | c0af8babe305c732db26c0aac35800811aeb9303 (diff) | |
download | postgresql-264c0682077fe9ec5c9bd366f756451db397d4fb.tar.gz postgresql-264c0682077fe9ec5c9bd366f756451db397d4fb.zip |
This patch implements a different "relkind"
for views. Views are now have a "relkind" of
RELKIND_VIEW instead of RELKIND_RELATION.
Also, views no longer have actual heap storage
files.
The following changes were made
1. CREATE VIEW sets the new relkind
2. The executor complains if a DELETE or
INSERT references a view.
3. DROP RULE complains if an attempt is made
to delete a view SELECT rule.
4. CREATE RULE "_RETmytable" AS ON SELECT TO mytable DO INSTEAD ...
1. checks to make sure mytable is empty.
2. sets the relkind to RELKIND_VIEW.
3. deletes the heap storage files.
5. LOCK myview is not allowed. :)
6. the regression test type_sanity was changed to
account for the new relkind value.
7. CREATE INDEX ON myview ... is not allowed.
8. VACUUM myview is not allowed.
VACUUM automatically skips views when do the entire
database.
9. TRUNCATE myview is not allowed.
THINGS LEFT TO THINK ABOUT
o pg_views
o pg_dump
o pgsql (\d \dv)
o Do we really want to be able to inherit from views?
o Is 'DROP TABLE myview' OK?
--
Mark Hollomon
Diffstat (limited to 'src/backend/commands/command.c')
-rw-r--r-- | src/backend/commands/command.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index d0de9e2e4de..d0faa943cfd 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.100 2000/09/12 04:33:18 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.101 2000/09/12 04:49:06 momjian Exp $ * * NOTES * The PerformAddAttribute() code, like most of the relation @@ -533,6 +533,9 @@ AlterTableAlterColumn(const char *relationName, #endif rel = heap_openr(relationName, AccessExclusiveLock); + if ( rel->rd_rel->relkind == RELKIND_VIEW ) + elog(ERROR, "ALTER TABLE: %s is a view", relationName); + myrelid = RelationGetRelid(rel); heap_close(rel, NoLock); @@ -1133,6 +1136,10 @@ AlterTableAddConstraint(char *relationName, rel = heap_openr(relationName, AccessExclusiveLock); + /* make sure it is not a view */ + if (rel->rd_rel->relkind == RELKIND_VIEW) + elog(ERROR, "ALTER TABLE: cannot add constraint to a view"); + /* * Scan all of the rows, looking for a false match */ @@ -1251,19 +1258,20 @@ AlterTableAddConstraint(char *relationName, elog(ERROR, "ALTER TABLE / ADD CONSTRAINT: Unable to reference temporary table from permanent table constraint."); } - /* check to see if the referenced table is a view. */ - if (is_viewr(fkconstraint->pktable_name)) - elog(ERROR, "ALTER TABLE: Cannot add constraints to views."); - /* * Grab an exclusive lock on the pk table, so that someone * doesn't delete rows out from under us. */ pkrel = heap_openr(fkconstraint->pktable_name, AccessExclusiveLock); - if (pkrel == NULL) - elog(ERROR, "referenced table \"%s\" not found", + if (pkrel == NULL) + elog(ERROR, "referenced table \"%s\" not found", + fkconstraint->pktable_name); + + if (pkrel->rd_rel->relkind != RELKIND_RELATION) + elog(ERROR, "referenced table \"%s\" not a relation", fkconstraint->pktable_name); + /* * Grab an exclusive lock on the fk table, and then scan @@ -1277,6 +1285,9 @@ AlterTableAddConstraint(char *relationName, elog(ERROR, "table \"%s\" not found", relationName); + if (rel->rd_rel->relkind != RELKIND_RELATION) + elog(ERROR, "referencing table \"%s\" not a relation", relationName); + /* First we check for limited correctness of the constraint */ rel_attrs = pkrel->rd_att->attrs; @@ -1503,6 +1514,7 @@ AlterTableCreateToastTable(const char *relationName, bool silent) * allow to create TOAST tables for views. But why not - someone * can insert into a view, so it shouldn't be impossible to hide * huge data there :-) + * Not any more. */ if (((Form_pg_class) GETSTRUCT(reltup))->relkind != RELKIND_RELATION) { @@ -1702,6 +1714,9 @@ LockTableCommand(LockStmt *lockstmt) rel = heap_openr(lockstmt->relname, NoLock); + if (rel->rd_rel->relkind != RELKIND_RELATION) + elog(ERROR, "LOCK TABLE: %s is not a table", lockstmt->relname); + if (is_view(rel)) elog(ERROR, "LOCK TABLE: cannot lock a view"); |