1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Support automatically-updatable views.

This patch makes "simple" views automatically updatable, without the need
to create either INSTEAD OF triggers or INSTEAD rules.  "Simple" views
are those classified as updatable according to SQL-92 rules.  The rewriter
transforms INSERT/UPDATE/DELETE commands on such views directly into an
equivalent command on the underlying table, which will generally have
noticeably better performance than is possible with either triggers or
user-written rules.  A view that has INSTEAD OF triggers or INSTEAD rules
continues to operate the same as before.

For the moment, security_barrier views are not considered simple.
Also, we do not support WITH CHECK OPTION.  These features may be
added in future.

Dean Rasheed, reviewed by Amit Kapila
This commit is contained in:
Tom Lane
2012-12-08 18:25:48 -05:00
parent d12d9f595e
commit a99c42f291
20 changed files with 2492 additions and 94 deletions

View File

@ -28,6 +28,7 @@
#include "miscadmin.h"
#include "parser/keywords.h"
#include "postmaster/syslogger.h"
#include "rewrite/rewriteHandler.h"
#include "storage/fd.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
@ -523,3 +524,33 @@ pg_collation_for(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
PG_RETURN_TEXT_P(cstring_to_text(generate_collation_name(collid)));
}
/*
* information_schema support functions
*
* Test whether a view (identified by pg_class OID) is insertable-into or
* updatable. The latter requires delete capability too. This is an
* artifact of the way the SQL standard defines the information_schema views:
* if we defined separate functions for update and delete, we'd double the
* work required to compute the view columns.
*
* These rely on relation_is_updatable(), which is in rewriteHandler.c.
*/
Datum
pg_view_is_insertable(PG_FUNCTION_ARGS)
{
Oid viewoid = PG_GETARG_OID(0);
int req_events = (1 << CMD_INSERT);
PG_RETURN_BOOL(relation_is_updatable(viewoid, req_events));
}
Datum
pg_view_is_updatable(PG_FUNCTION_ARGS)
{
Oid viewoid = PG_GETARG_OID(0);
int req_events = (1 << CMD_UPDATE) | (1 << CMD_DELETE);
PG_RETURN_BOOL(relation_is_updatable(viewoid, req_events));
}