-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add support for ALTER VIEW and CREATE OR ALTER VIEW syntax on schema bound views in Babelfish #3570
Add support for ALTER VIEW and CREATE OR ALTER VIEW syntax on schema bound views in Babelfish #3570
Conversation
Pull Request Test Coverage Report for Build 13938113398Details
💛 - Coveralls |
13d2b2a
to
60a96a9
Compare
@@ -149,7 +149,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner) | |||
|
|||
/* create sysdatabases under current DB's DBO schema */ | |||
appendStringInfo(&query, "CREATE VIEW dummy.sysdatabases AS SELECT * FROM sys.sysdatabases; "); | |||
appendStringInfo(&query, "ALTER VIEW dummy.sysdatabases OWNER TO dummy; "); |
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.
What's the purpose for this line ?
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.
If we use ALTER VIEW, it will raise syntax error near OWNER while doing initbbf because of different ALTER VIEW behavior between PG and tsql. So we use ALTER TABLE instead to avoid that, as PG can use ALTER TABLE as well to change the ownership of view. (Postgresql Alter Table)
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.
Pls add a comment into the code for this behavior and the purpose for this change.
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.
Added comments in the code
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.
Please add test cases for postgres endpoint. ALTER VIEW ... should continue to work as before for postgres endpoint.
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.
Added test cases to check psql ALTER VIEW
83e22c8
to
c95c503
Compare
* Update the acl info of view in pg_class given its oid and acl info | ||
*/ | ||
static void | ||
pg_class_update_acl(Oid newViewOid, Acl *oldViewAcl) |
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.
let's also add a test that verifies that the acl is properly updated when we do ALTER 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.
Added .mix
test file to test ACL changes.
@@ -4376,6 +4377,25 @@ storeOriginalQueryForBatchLevelStatement(TSqlParser::Batch_level_statementContex | |||
originalQueryCopy.replace(startIndex, endIndex - startIndex, "CREATE"); | |||
return pstrdup(originalQueryCopy.c_str()); | |||
} | |||
else if (ctx->create_or_alter_view() && ctx->create_or_alter_view()->ALTER()) |
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.
what is the purpose of these changes?
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.
After the alter operation is complete, the definition that gets stored in catalogs is something like Alter view v1 as select 1;
instead of Create view v1 as select 1;
. This change allows storing correct definitions after ALTER/CREATE OR ALTER VIEW
operations. Appropriate tests are added in the test files. SQL server does the same, it stores the definitions as CREATE VIEW
instead of ALTER 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.
Pls add the comments into the code as well.
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.
Added comments in the code
StartTransactionCommand(); | ||
|
||
if (isCompleteQuery) | ||
EventTriggerDDLCommandStart(parsetree); |
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.
Which is the test case for this ?
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.
Without this code, DDL event triggers won't fire for ALTER VIEW operations. Currently we do not support DDL triggers for T-SQL, but tested it out from from PSQL endpoint. This code can be used later, once we support DDL triggers in T-SQL. Added comment in the code.
else | ||
{ | ||
/* Save ACL before dropping the view */ | ||
oldViewAcl = get_old_view_acl(oldViewOid); |
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.
To me it seems like get_old_view_acl can potentially return NULL. There is even a check for it in pg_class_update_acl. Then it would cause a crash once you hit pfree(oldViewAcl)
.
So either add a check that get_old_view_acl
cannot return NULL - throw an error (then the case in pg_class_update_acl is not needed), or ensure that pfree isn't called on NULL.
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.
Older version views may have NULL ACL, added check to pfree(oldViewAcl) only if oldViewAcl is non null
originalView.objectId = oldViewOid; | ||
originalView.classId = RelationRelationId; | ||
originalView.objectSubId = 0; | ||
performDeletion(&originalView, DROP_RESTRICT, 0); |
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.
DROP_RESTRICT means this will fail if there's any objects dependent on the view. Could we test this - create an object dependent on a view and attempt to alter the underlying 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.
Added to test case
d5efe07
to
35e9a8e
Compare
-Changed subcmd ALTER VIEW to ALTER TABLE in dbcmds.c -Removed usage of PG dialect to generate subcmds -Added acl tests and addressed comments -Added test case for dependent check -added assert for relacl null condition -Added more test cases to check psql alter view syntax Task : BABEL-2017
35e9a8e
to
c64ba1f
Compare
c6c0176
into
babelfish-for-postgresql:BABEL_5_X_DEV
…bound views in Babelfish Cherry-Pick commit from PR from #3570 Currently, Babelfish does not support ALTER VIEW and CREATE OR ALTER VIEW syntax statement in the TSQL dialect. With this change, Babelfish will support ALTER VIEW operations, allowing users to modify existing views. We assume views to not have any dependencies for alter to succeed. For dependent procedures, alter view will continue to work and will not be affected. Permissions on views won't be affected The change was made to enhance Babelfish's compatibility with SQL Server by supporting the ALTER VIEW statement. This allows users to modify views in a manner consistent with SQL Server. [NOTE]: ALTER VIEW for views having dependencies will be supported once Babelfish supports weak schema bound views. Engine PR - babelfish-for-postgresql/postgresql_modified_for_babelfish#547 Signed off by: Rahul Parande <[email protected]> Issues Resolved: JIRA - BABEL-2017
Description
Currently, Babelfish does not support ALTER VIEW and CREATE OR ALTER VIEW syntax statement in the TSQL dialect. With this change, Babelfish will support ALTER VIEW operations, allowing users to modify existing views.
The change was made to enhance Babelfish's compatibility with SQL Server by supporting the ALTER VIEW statement. This allows users to modify views in a manner consistent with SQL Server.
[NOTE]: ALTER VIEW for views having dependencies will be supported once Babelfish supports weak schema bound views.
Engine PR - babelfish-for-postgresql/postgresql_modified_for_babelfish#545
Signed off by: Rahul Parande [email protected]
Issues Resolved
JIRA - BABEL-2017
Test Scenarios Covered
Minor version upgrade tests -
Major version upgrade tests -
Performance tests -
Tooling impact -
Client tests -
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.