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

feat(query): show grants support mget table/db name by table/db id. #14862

Merged
merged 9 commits into from
Mar 9, 2024

Conversation

TCeason
Copy link
Collaborator

@TCeason TCeason commented Mar 6, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Speed up show grants.

Under debug mode:
role1 owns 10 thounds table:

$ bendsql --query='show grants for role role1' --time                                                                                                                                          
28.317

After optimize, double Speed bonus

$ bendsql --query='show grants for role role1' --time                                                                                                                                          
15.020

Under release :

$ bendsql --query='show grants for role role1' --time                                                                                                                                                                                      
2.635

After optimize,

$ bendsql --query='show grants for role role1' --time                                                                                                                                                                                       
2.166

In this pr add two api in schema_api:

mget_database_names_by_ids;
mget_table_names_by_ids;

  • Fixes #[Link the issue here]

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Mar 6, 2024
@TCeason TCeason marked this pull request as draft March 6, 2024 16:09
@TCeason TCeason force-pushed the optimize branch 6 times, most recently from 7fafc25 to 989ca14 Compare March 7, 2024 05:04
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 16 files at r1, all commit messages.
Reviewable status: 1 of 16 files reviewed, 7 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, and @TCeason)


src/meta/api/src/schema_api.rs line 212 at r1 (raw file):

    ) -> Result<(TableIdent, Arc<TableMeta>), KVAppError>;

    async fn list_tables_name_by_id(

It is a mget operation. Not a list.

mget gets values by keys. list gets values by a common prefix.


src/meta/api/src/schema_api.rs line 218 at r1 (raw file):

    async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String, KVAppError>;
    async fn list_dbs_name_by_id(&self, db_id: Vec<MetaId>) -> Result<Vec<String>, KVAppError>;

It is mget not list.


src/query/catalog/src/catalog/interface.rs line 195 at r1 (raw file):

    async fn list_tables_name_by_id(
        &self,
        table_id: Vec<MetaId>,

It should be table_ids:

Suggestion:

        table_ids: Vec<MetaId>,

src/query/catalog/src/catalog/interface.rs line 204 at r1 (raw file):

    async fn list_dbs_name_by_id(
        &self,
        db_id: Vec<MetaId>,

db_ids


src/query/catalog/src/catalog/session_catalog.rs line 250 at r1 (raw file):

    async fn list_tables_name_by_id(
        &self,
        table_id: Vec<MetaId>,

table_ids


src/query/catalog/src/catalog/session_catalog.rs line 263 at r1 (raw file):

    async fn list_dbs_name_by_id(
        &self,
        db_id: Vec<MetaId>,

db_ids

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 16 files at r1, 1 of 12 files at r2, all commit messages.
Reviewable status: 3 of 16 files reviewed, 5 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, and @TCeason)


src/meta/api/src/schema_api.rs line 212 at r3 (raw file):

    ) -> Result<(TableIdent, Arc<TableMeta>), KVAppError>;

    async fn mget_tables_name_by_id(

Suggestion:

    async fn mget_table_names_by_id(

src/meta/api/src/schema_api.rs line 218 at r3 (raw file):

    async fn get_table_name_by_id(&self, table_id: MetaId) -> Result<String, KVAppError>;
    async fn mget_dbs_name_by_id(&self, db_ids: Vec<MetaId>) -> Result<Vec<String>, KVAppError>;

Suggestion:

    async fn mget_database_names_by_id(&self, db_ids: Vec<MetaId>) -> Result<Vec<String>, KVAppError>;

src/query/catalog/src/catalog/session_catalog.rs line 252 at r3 (raw file):

        table_ids: Vec<MetaId>,
    ) -> databend_common_exception::Result<Vec<String>> {
        self.inner.mget_tables_name_by_id(table_ids).await

Suggestion:

mget_table_names_by_id

src/query/catalog/src/catalog/session_catalog.rs line 261 at r3 (raw file):

    // List the dbs name by meta ids.
    async fn mget_dbs_name_by_id(

Suggestion:

mget_database_names_by_id

@TCeason
Copy link
Collaborator Author

TCeason commented Mar 7, 2024

mget_dbs_name_by_id

Done

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 12 files at r4, all commit messages.
Reviewable status: 8 of 16 files reviewed, 2 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, and @TCeason)


src/query/catalog/src/catalog/session_catalog.rs line 261 at r3 (raw file):

    // List the dbs name by meta ids.
    async fn mget_dbs_name_by_id(

This method name should be updated too.

@TCeason
Copy link
Collaborator Author

TCeason commented Mar 7, 2024

Reviewed 6 of 12 files at r4, all commit messages.
Reviewable status: 8 of 16 files reviewed, 2 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, and @TCeason)

src/query/catalog/src/catalog/session_catalog.rs line 261 at r3 (raw file):

    // List the dbs name by meta ids.
    async fn mget_dbs_name_by_id(

This method name should be updated too.

Already modify in the lastest commit.

@TCeason TCeason requested a review from drmingdrmer March 7, 2024 14:40
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 16 files at r1, 5 of 12 files at r5, all commit messages.
Reviewable status: 9 of 16 files reviewed, 4 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, and @TCeason)


src/query/catalog/src/catalog/session_catalog.rs line 261 at r3 (raw file):

Previously, TCeason wrote…

Already modify in the lastest commit.

No. They are not modified :(

@TCeason
Copy link
Collaborator Author

TCeason commented Mar 8, 2024

mget_dbs_name_by_id

O, I got, mget_database_names_by_ids

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

The meta-data part LGTM.

Reviewed 11 of 12 files at r6, all commit messages.
Reviewable status: 15 of 16 files reviewed, 4 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, @sundy-li, and @TCeason)

Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r7, all commit messages.
Reviewable status: 15 of 16 files reviewed, 4 unresolved discussions (waiting on @BohuTANG, @everpcpc, @flaneur2020, @sundy-li, and @TCeason)

@sundy-li sundy-li added this pull request to the merge queue Mar 9, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 9, 2024
@BohuTANG BohuTANG merged commit e54cd2f into datafuselabs:main Mar 9, 2024
71 of 72 checks passed
@TCeason TCeason mentioned this pull request Mar 11, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants