Skip to content

sql: Benchmark has_schema_privilege, has_sequence_privilege, has_table_privilege#75855

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ecwall:builtin-benchmark
Feb 17, 2022
Merged

sql: Benchmark has_schema_privilege, has_sequence_privilege, has_table_privilege#75855
craig[bot] merged 1 commit intocockroachdb:masterfrom
ecwall:builtin-benchmark

Conversation

@ecwall
Copy link
Copy Markdown
Contributor

@ecwall ecwall commented Feb 2, 2022

fixes #66173

These builtins have been changed to use HasPrivilege instead of executing SQL
queries internally.

Release notes: None

@ecwall ecwall requested review from a team and otan February 2, 2022 13:30
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner
Copy link
Copy Markdown
Contributor

ajwerner commented Feb 2, 2022

You'll need to update the expectations file. Also, consider adding cases where you set up more than one of each of the things.

// prevents database exists error
Setup: `DROP DATABASE IF EXISTS d; CREATE DATABASE d`,
Stmt: `SELECT has_database_privilege('d', 'CREATE')`,
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you add more tests to see how it scales with number of databases/schemas/sequences?

basically, in the setup, it can create multiple entities, and the Stmt to test can be something like

SELECT has_database_privilege(name, 'CREATE') FROM crdb_internal.databases;

for schemas, something like

SELECT has_schema_privilege(nspame, 'CREATE') FROM pg_catalog.pg_namespace

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Talked about the tests not supporting has_database_privilege offline. Updated the others.

@otan otan removed their request for review February 8, 2022 20:26
@ecwall
Copy link
Copy Markdown
Contributor Author

ecwall commented Feb 9, 2022

Error described in #76296 needs to be resolved

@ecwall ecwall changed the title sql: Benchmark has_database_privilege, has_schema_privilege, has_sequence_privilege sql: Benchmark has_schema_privilege, has_sequence_privilege, has_table_privilege Feb 14, 2022
@ecwall ecwall requested a review from rafiss February 14, 2022 21:44
},

{
Name: "has_schema_privilege multiple",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit instead of multiple, state how many schemas are being created

we should probably test 1,3,5 schemas and see the relative increases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a way to create tables/schemas/etc using generate_series (or something similar) to avoid copying and pasting?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we can use the sql language to iterate and do multiple DDLs but perhaps you could extend make a helper function to create a string for setup

has_table_privilege

fixes #66173

These builtins have been changed to use HasPrivilege instead of executing SQL
queries internally.

Release note: None
var results resultSet
var wg sync.WaitGroup
concurrency := ((system.NumCPU()*4 - 1) / r.numNodes) + 1 // arbitrary
concurrency := ((system.NumCPU() - 1) / r.numNodes) + 1 // arbitrary
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Spoke with @ajwerner on slack about this. Removing the *4 makes the tests run much faster with larger (>4) rewrite iterations.

@ecwall ecwall requested a review from RichardJCai February 16, 2022 18:09
Copy link
Copy Markdown
Contributor

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

Nice!

Comment on lines +63 to +69
1,ORMQueries/has_schema_privilege_5
2,ORMQueries/has_sequence_privilege_1
4,ORMQueries/has_sequence_privilege_3
6,ORMQueries/has_sequence_privilege_5
2,ORMQueries/has_table_privilege_1
4,ORMQueries/has_table_privilege_3
6,ORMQueries/has_table_privilege_5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤮 😢

@ecwall
Copy link
Copy Markdown
Contributor Author

ecwall commented Feb 16, 2022

bors r=RichardJCai

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Feb 16, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Feb 17, 2022

Build succeeded:

@craig craig bot merged commit 27ed9d6 into cockroachdb:master Feb 17, 2022
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.

sql: improve perf of has_database_privilege, has_schema_privilege and has_sequence_privilege

5 participants