-
Notifications
You must be signed in to change notification settings - Fork 71
Support for weak binding views to allow dropping of underlying objects #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: BABEL_5_X_DEV__PG_17_X
Are you sure you want to change the base?
Changes from all commits
7149fc4
e8b57d6
a63802e
e443af6
00bb61a
301e7cc
f292acc
413f6d2
e9b3925
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,11 @@ | |
#include "catalog/dependency.h" | ||
#include "catalog/namespace.h" | ||
#include "catalog/objectaddress.h" | ||
#include "catalog/pg_depend_d.h" | ||
#include "catalog/pg_namespace.h" | ||
#include "catalog/pg_proc.h" | ||
#include "commands/defrem.h" | ||
#include "commands/tablecmds.h" | ||
#include "miscadmin.h" | ||
#include "parser/parser.h" | ||
#include "parser/parse_type.h" | ||
|
@@ -131,6 +133,13 @@ RemoveObjects(DropStmt *stmt) | |
table_close(relation, NoLock); | ||
|
||
add_exact_object_address(&address, objects); | ||
|
||
/* Check for strong views and handle weak views */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not move the open table into the hook implement ? |
||
if ((stmt->removeType == OBJECT_FUNCTION) && view_dependency_hook) | ||
{ | ||
if (!(*view_dependency_hook)(&address, NULL, NULL)) | ||
continue; | ||
} | ||
} | ||
|
||
/* Here we really delete them. */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15822,6 +15822,50 @@ dumpTable(Archive *fout, const TableInfo *tbinfo) | |
free(namecopy); | ||
} | ||
|
||
/* | ||
* Create a dummy AS clause for a view. This is used when the real view | ||
* definition has to be postponed because of circular dependencies. | ||
* We must duplicate the view's external properties -- column names and types | ||
* (including collation) -- so that it works for subsequent references. | ||
* | ||
* This returns a new buffer which must be freed by the caller. | ||
*/ | ||
static PQExpBuffer | ||
createDummyViewAsClause(Archive *fout, const TableInfo *tbinfo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not reuse the createDummyViewAsClause def from community ? |
||
{ | ||
PQExpBuffer result = createPQExpBuffer(); | ||
int j; | ||
|
||
appendPQExpBufferStr(result, "SELECT"); | ||
|
||
for (j = 0; j < tbinfo->numatts; j++) | ||
{ | ||
if (j > 0) | ||
appendPQExpBufferChar(result, ','); | ||
appendPQExpBufferStr(result, "\n "); | ||
|
||
appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]); | ||
|
||
/* | ||
* Must add collation if not default for the type, because CREATE OR | ||
* REPLACE VIEW won't change it | ||
*/ | ||
if (OidIsValid(tbinfo->attcollation[j])) | ||
{ | ||
CollInfo *coll; | ||
|
||
coll = findCollationByOid(tbinfo->attcollation[j]); | ||
if (coll) | ||
appendPQExpBuffer(result, " COLLATE %s", | ||
fmtQualifiedDumpable(coll)); | ||
} | ||
|
||
appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j])); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/* | ||
* Create the AS clause for a view or materialized view. The semicolon is | ||
* stripped because a materialized view must add a WITH NO DATA clause. | ||
|
@@ -15833,6 +15877,7 @@ createViewAsClause(Archive *fout, const TableInfo *tbinfo) | |
{ | ||
PQExpBuffer query = createPQExpBuffer(); | ||
PQExpBuffer result = createPQExpBuffer(); | ||
PQExpBuffer dummyResult = createPQExpBuffer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dummyresult doesn't need to be created as createPQExpBuffer. |
||
PGresult *res; | ||
int len; | ||
|
||
|
@@ -15856,8 +15901,21 @@ createViewAsClause(Archive *fout, const TableInfo *tbinfo) | |
len = PQgetlength(res, 0, 0); | ||
|
||
if (len == 0) | ||
pg_fatal("definition of view \"%s\" appears to be empty (length zero)", | ||
tbinfo->dobj.name); | ||
{ | ||
/* | ||
* Handle broken views (with empty definitions) | ||
* Instead of failing, create a dummy SELECT that preserves the structure | ||
*/ | ||
PQclear(res); | ||
destroyPQExpBuffer(query); | ||
|
||
/* Use createDummyViewAsClause to generate a compatible structure */ | ||
dummyResult = createDummyViewAsClause(fout, tbinfo); | ||
appendPQExpBuffer(result, "%s", dummyResult->data); | ||
destroyPQExpBuffer(dummyResult); | ||
|
||
return result; | ||
} | ||
|
||
/* Strip off the trailing semicolon so that other things may follow. */ | ||
Assert(PQgetvalue(res, 0, 0)[len - 1] == ';'); | ||
|
@@ -15869,50 +15927,6 @@ createViewAsClause(Archive *fout, const TableInfo *tbinfo) | |
return result; | ||
} | ||
|
||
/* | ||
* Create a dummy AS clause for a view. This is used when the real view | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why move the whole function definition ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
* definition has to be postponed because of circular dependencies. | ||
* We must duplicate the view's external properties -- column names and types | ||
* (including collation) -- so that it works for subsequent references. | ||
* | ||
* This returns a new buffer which must be freed by the caller. | ||
*/ | ||
static PQExpBuffer | ||
createDummyViewAsClause(Archive *fout, const TableInfo *tbinfo) | ||
{ | ||
PQExpBuffer result = createPQExpBuffer(); | ||
int j; | ||
|
||
appendPQExpBufferStr(result, "SELECT"); | ||
|
||
for (j = 0; j < tbinfo->numatts; j++) | ||
{ | ||
if (j > 0) | ||
appendPQExpBufferChar(result, ','); | ||
appendPQExpBufferStr(result, "\n "); | ||
|
||
appendPQExpBuffer(result, "NULL::%s", tbinfo->atttypnames[j]); | ||
|
||
/* | ||
* Must add collation if not default for the type, because CREATE OR | ||
* REPLACE VIEW won't change it | ||
*/ | ||
if (OidIsValid(tbinfo->attcollation[j])) | ||
{ | ||
CollInfo *coll; | ||
|
||
coll = findCollationByOid(tbinfo->attcollation[j]); | ||
if (coll) | ||
appendPQExpBuffer(result, " COLLATE %s", | ||
fmtQualifiedDumpable(coll)); | ||
} | ||
|
||
appendPQExpBuffer(result, " AS %s", fmtId(tbinfo->attnames[j])); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/* | ||
* dumpTableSchema | ||
* write the declaration (not data) of one user-defined table or view | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding this .h ?