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

Add primary key to selectors table #10586

Merged
merged 1 commit into from
Feb 23, 2022
Merged

Add primary key to selectors table #10586

merged 1 commit into from
Feb 23, 2022

Conversation

zhangbutao
Copy link
Contributor

@zhangbutao zhangbutao commented Jan 13, 2022

Percona-XtraDB-Cluster prohibit insert on table without primary key. And if adding primary key also help to select specific row.
Fixes #10585

Documentation

(x) No documentation is needed.

Release notes

(x) No release notes entries required.

@cla-bot
Copy link

cla-bot bot commented Jan 13, 2022

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: zhangbutao.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@@ -69,6 +69,7 @@
List<SelectorRecord> getSelectors(@Bind("environment") String environment);

@SqlUpdate("CREATE TABLE IF NOT EXISTS selectors (\n" +
" id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n" +
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use https://flywaydb.org/ to handle the schema changes. Also this is very vendor specific syntax. I am not sure what RDBMS vendors we support here.

Copy link
Member

Choose a reason for hiding this comment

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

See in-flight PR #9812 for Flyway.

I beleive we plan to support Postgres, MySQL and Oracle only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the syntax of primary key to make more generic. I don't know if it's a reasonable fix here, but i see resource_groups table also has similar primary key syntax.

@cla-bot
Copy link

cla-bot bot commented Jan 13, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@@ -1,10 +1,12 @@
CREATE TABLE IF NOT EXISTS selectors (
id BIGINT NOT NULL AUTO_INCREMENT,
Copy link
Member

Choose a reason for hiding this comment

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

I believe these files should never be mutated. @hashhar can we have a test?
For example use previous version to populate the DB state and use current to update it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Firstly, these tables will not be changed after trino first startup unless updated artificially. And if we update table by adding primary key, mysql will automatically update the historical rows with adding the primary key value. So , there is nothing effect on previous version DB state.

Copy link
Member

Choose a reason for hiding this comment

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

The whole https://github.com/trinodb/trino/tree/master/plugin/trino-resource-group-managers/src/main/resources/db/migration/mysql is used with Flyway, it's a reply-log of DB schema changes, and so individual changes shouldn't change.

@hashhar does Flyway record checksum of the changes files, would it detect an accidental modification?

Copy link
Member

Choose a reason for hiding this comment

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

does Flyway record checksum of the changes files, would it detect an accidental modification?

It does.

Copy link
Member

Choose a reason for hiding this comment

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

What happens then?

Copy link
Member

Choose a reason for hiding this comment

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

does Flyway record checksum of the changes files, would it detect an accidental modification?

It does.

@aalbu we need a test ensuring no accidental modifications are done.
Could be as benign as someone reformatting large number of files, or Flyway changes checksum result in a corner case. #10586 (comment) would catch any such issue, let's plan on doing it.

cc @hashhar

@zhangbutao
Copy link
Contributor Author

If adding primary key is a reasonable optimization, how to do it? Should i add a new sql file named like V6__add_primary_key_selectors.sql with contents alter table selectors add id int unsigned not Null auto_increment primary key ? cc @findepi @hashhar

@hashhar
Copy link
Member

hashhar commented Jan 24, 2022

@zhangbutao Rebase on current master to include changes merged in #9812.

Add all migrations as new files (and maybe for all supported databases - wdyt @nineinchnick @aalbu ), also notice that now only Flyway is used for managing database state so you don't need the changes to the Jdbi objects.

Separate we'll look into adding tests which ensure that changes to older migrations are caught.

@findepi
Copy link
Member

findepi commented Jan 24, 2022

Add all migrations as new files (and maybe for all supported databases - wdyt @nineinchnick @aalbu ),

👍

now only Flyway is used for managing database state so you don't need the changes to the Jdbi objects.

do we still need those jdbi annotations?

Separate we'll look into adding tests which ensure that changes to older migrations are caught.

@nineinchnick @aalbu @hashhar do we have an issue?

@aalbu
Copy link
Member

aalbu commented Jan 25, 2022

Separate we'll look into adding tests which ensure that changes to older migrations are caught.

@nineinchnick @aalbu @hashhar do we have an issue?

#10776

@aalbu
Copy link
Member

aalbu commented Jan 25, 2022

Add all migrations as new files (and maybe for all supported databases - wdyt @nineinchnick @aalbu )

Agreed, we should mirror the changes for all supported databases.

@cla-bot
Copy link

cla-bot bot commented Jan 25, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@zhangbutao
Copy link
Contributor Author

I have added new migrations files for all supported databases and no changes to the Jdbi objects. What else need I do? I have sent cla email to [email protected] , please check. thx
cc @hashhar @findepi @aalbu

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

nit: add newlines to all migrations.

LGTM otherwise.

@hashhar
Copy link
Member

hashhar commented Jan 27, 2022

@cla-bot check

cc: @martint

@cla-bot
Copy link

cla-bot bot commented Jan 27, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@cla-bot
Copy link

cla-bot bot commented Jan 27, 2022

The cla-bot has been summoned, and re-checked this pull request!

@cla-bot
Copy link

cla-bot bot commented Jan 27, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@hashhar
Copy link
Member

hashhar commented Feb 8, 2022

@cla-bot check

@cla-bot
Copy link

cla-bot bot commented Feb 8, 2022

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

@cla-bot
Copy link

cla-bot bot commented Feb 8, 2022

The cla-bot has been summoned, and re-checked this pull request!

@cla-bot cla-bot bot added the cla-signed label Feb 23, 2022
@zhangbutao
Copy link
Contributor Author

Gentle ping. Can someone merge this request?

Some databases like Percona XtraDB Cluster prohibit inserts into tables
without primary keys. This change also makes this table consistent with
other tables in the resource groups database.
@hashhar hashhar merged commit 93bfb11 into trinodb:master Feb 23, 2022
@github-actions github-actions bot added this to the 372 milestone Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Add primary key to selectors table
6 participants