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

parser: support GLOBAL IndexOption #55259

Merged
merged 9 commits into from
Aug 9, 2024

Conversation

mjonss
Copy link
Contributor

@mjonss mjonss commented Aug 7, 2024

What problem does this PR solve?

Issue Number: ref #52994

Problem Summary:
To not surprise our users and create MySQL incompatibilities, we should require explicit mentioning of 'GLOBAL' when creating a Global Unique Index.

This also makes it easier to allow non-unique indexes as well as unique indexes already containing all partitioning columns to be GLOBAL.

Currently ALTER TABLE t PARTITION BY ... would implicitly create a Global Index of UNIQUE Indexes if they don't include all partitioning columns.
With this PR we are adding an optional UPDATE INDEXES clause after the partitioning definitions:
UPDATE INDEXES ( index_name {GLOBAL|LOCAL} [, index_name {GLOBAL|LOCAL}[,...]] ) to make every index change explicit.

What changed and how does it work?

Parser:

  • Added "GLOBAL" as IndexOption
  • Added "GLOBAL" as option for ColumnOption in combination with {PRIMARY|UNIQUE} KEY, where it will use the StrValue set to "Global" instead of adding yet another struct member.
  • Added "UPDATE INDEXES (...)" as option for ALTER TABLE t PARTITION BY ... [UPDATE INDEXES (...)] to allow [re]partitioning a table and convert unique indexes that does not include all partitioning columns into global indexes.

Executor:

  • Including /*T![global_index] GLOBAL */ as IndexOption in SHOW CREATE TABLE

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added the release-note-none Denotes a PR that doesn't merit a release note. label Aug 7, 2024
@mjonss mjonss requested a review from Defined2014 August 7, 2024 08:47
@ti-chi-bot ti-chi-bot bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 7, 2024
Copy link

tiprow bot commented Aug 7, 2024

Hi @mjonss. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mjonss mjonss requested a review from tangenta August 7, 2024 08:48
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Aug 7, 2024
@tangenta
Copy link
Contributor

tangenta commented Aug 7, 2024

Is there a convenient way to convert between local and global index like

ALTER TABLE t ALTER INDEX c1 [GLOBAL | LOCAL];

?

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.2699%. Comparing base (4cfc182) to head (e70b269).
Report is 14 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #55259        +/-   ##
================================================
+ Coverage   72.7812%   75.2699%   +2.4887%     
================================================
  Files          1570       1572         +2     
  Lines        439488     444945      +5457     
================================================
+ Hits         319865     334910     +15045     
+ Misses        99907      90003      -9904     
- Partials      19716      20032       +316     
Flag Coverage Δ
integration 49.4944% <6.8181%> (?)
unit 74.7032% <100.0000%> (+2.8932%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9567% <ø> (ø)
parser ∅ <ø> (∅)
br 52.5621% <ø> (+6.6967%) ⬆️

@mjonss
Copy link
Contributor Author

mjonss commented Aug 7, 2024

Is there a convenient way to convert between local and global index like

ALTER TABLE t ALTER INDEX c1 [GLOBAL | LOCAL];

?

@tangenta Good question, I have not thought of it, I would consider the indexes to be different, so you should probably create a new index and drop the old one instead, which would also have less impact of DDL handling, since it would need to recreate the full index and it is not a simple metadata only change like VISIBLE/INVISIBLE IndexOption.

@mjonss mjonss requested a review from tangenta August 7, 2024 15:18
@mjonss
Copy link
Contributor Author

mjonss commented Aug 7, 2024

After some consideration and discussion with the PM, I changed from:
ALTER TABLE t PARTITION BY ... [CONVERT TO GLOBAL INDEX]
to
ALTER TABLE t PARTITION BY ... [UPDATE INDEXES ()]
where list of index changes is a comma separated list of:
IndexName {GLOBAL|LOCAL}

to be able to more explicitly change which indexes to change to GLOBAL (and to LOCAL if you repartition a table).
This will also allow to make non-unique indexes and unique indexes that includes all partitioning columns to be GLOBAL in the future.

$$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey, PrimaryKeyTp: $3.(model.PrimaryKeyType)}
$$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey, PrimaryKeyTp: $3.(model.PrimaryKeyType), StrValue: $4}
}
| "UNIQUE" "GLOBAL"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not tested in UT and should this be GlobalOrLocalOpt instead of GLOBAL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I will update it or add the possibility of LOCAL as well in case of conflicts.

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 explicitly added "GLOBAL" and "LOCAL", as well as kept the "UNIQUE" %prec lowerThanKey to avoid conflicts.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 8, 2024
Copy link

ti-chi-bot bot commented Aug 8, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-07 09:01:58.823353018 +0000 UTC m=+429048.690452106: ☑️ agreed by tangenta.
  • 2024-08-08 10:08:58.063465884 +0000 UTC m=+519467.930564973: ☑️ agreed by Defined2014.

@mjonss
Copy link
Contributor Author

mjonss commented Aug 8, 2024

/retest

Copy link

tiprow bot commented Aug 8, 2024

@mjonss: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mjonss
Copy link
Contributor Author

mjonss commented Aug 8, 2024

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Aug 8, 2024
@mjonss
Copy link
Contributor Author

mjonss commented Aug 8, 2024

/retest

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@Defined2014
Copy link
Contributor

Defined2014 commented Aug 9, 2024

/hold
Should we merge it now or after branch v8.3 is created(Aug 13th)?

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 9, 2024
@easonn7
Copy link

easonn7 commented Aug 9, 2024

/approve

Copy link

ti-chi-bot bot commented Aug 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, Defined2014, easonn7, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Aug 9, 2024
@Defined2014
Copy link
Contributor

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 9, 2024
@ti-chi-bot ti-chi-bot bot merged commit e1f2b77 into pingcap:master Aug 9, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants