Skip to content
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

Bug fixes and performance overhead reduction for GRANT .. ON SCHEMA #2020

Conversation

shalinilohia50
Copy link
Contributor

@shalinilohia50 shalinilohia50 commented Nov 15, 2023

Description

Bug fixes and performance overhead reduction for GRANT .. ON SCHEMA

  1. Server crash when using empty bracketed name. schema::[]
  2. Server crash when using empty quoted identifier. schema::""
  3. When granting permission to yourself, we need a different error message.
  4. Error message in not-supported multi-keyword permission should (i) be in uppercase (ii) have a space between keywords
  5. Not-supported object type in error message should be in uppercase
  6. Specified collation for column names using NAME datatype
  7. Merged the permissions in a single column instead of having multiple rows for each permission.
  8. GRANT ON SCHEMA:: TO PUBLIC does not take effect

Issues Resolved

JIRA: BABEL-4344
Co-authored-by: Anju Bharti
Signed-off-by: Shalini Lohia [email protected]

Test Scenarios Covered

  • Use case based - Added

  • Boundary conditions -

  • Arbitrary inputs -

  • Negative test cases -

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • Client tests -

Check List

  • Commits are signed per the DCO using --signoff

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.


bbf_schema_rel = table_open(get_bbf_schema_perms_oid(),
AccessShareLock);
ScanKeyInit(&key[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all usage of ScanKeyInit will choose "C" collation (default collation) for the lookup. Do we have sufficient test cases to prove that it works fine in term of case-insensitive searches/update/delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are always storing the downcase string in the catalog. The search/update/delete always happen on the downcase value. We have tested for Upper case, down case and mixed case string.

contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
CStringGetDatum(grantee));

scan = table_beginscan_catalog(bbf_schema_rel, 4, key);
tuple_bbf_schema = heap_getnext(scan, ForwardScanDirection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to free this tuple?

contrib/babelfishpg_tsql/src/pl_exec-2.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec-2.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec-2.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_handler.c Outdated Show resolved Hide resolved
if ((rol_spec->rolename != NULL) && !check_bbf_schema_for_entry(logical_schema, obj, permissions[i], rol_spec->rolename))
add_entry_to_bbf_schema(logical_schema, obj, permissions[i], rol_spec->rolename, obj_type);
int16 old_priv = get_bbf_schema_privilege(logical_schema, obj,rol_spec->rolename);
if(old_priv!= 31 || (old_priv|(31)) != old_priv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is 31?

contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/catalog.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/catalog.c Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_handler.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_handler.c Outdated Show resolved Hide resolved
int i = 0;
char *permissions[] = {"select", "insert", "update", "references", "delete"};
for(i = 0; i < 5; i++)
if((rol_spec->rolename != NULL) && (strcmp(rol_spec->rolename, "public") != 0) && !check_bbf_schema_for_entry(logical_schema, obj,rol_spec->rolename))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment what the following code is trying to do.

contrib/babelfishpg_tsql/src/pl_handler.c Outdated Show resolved Hide resolved
Comment on lines 3721 to 3727
if ((rol_spec->rolename != NULL) && (strcmp(rol_spec->rolename, "public") != 0) && !check_bbf_schema_for_entry(logical_schema, obj, rol_spec->rolename))
add_entry_to_bbf_schema(logical_schema, obj, privilege_maskInt, rol_spec->rolename, obj_type);
else if((rol_spec->rolename != NULL) && (strcmp(rol_spec->rolename, "public") != 0))
{
int16 old_priv = get_bbf_schema_privilege(logical_schema, obj, rol_spec->rolename);
if(old_priv!= privilege_maskInt || ((old_priv)|(privilege_maskInt)) != old_priv)
update_bbf_schema_entry(logical_schema, obj, privilege_maskInt, old_priv, rol_spec->rolename, obj_type, grant->is_grant);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code appears in 7-8 places in the code. Please generalize and decouple this in a separate function (probably inline).

contrib/babelfishpg_tsql/src/pl_exec-2.c Outdated Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec-2.c Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_exec-2.c Show resolved Hide resolved
contrib/babelfishpg_tsql/src/pl_handler.c Outdated Show resolved Hide resolved
@@ -106,19 +106,19 @@ GO
REVOKE ALL ON OBJECT::t1 TO guest;
GO

REVOKE ALL ON OBJECT::seq_tinyint TO guest;
REVOKE ALL ON OBJECT::seq_tinyint FROM guest;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing from TO to FROM? This should both be supported right?

@shalinilohia50 shalinilohia50 deleted the fix-babel-4344 branch November 21, 2023 16:01
Copy link
Contributor

@KushaalShroff KushaalShroff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer: #2031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants