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

Improve logic to include originalUniqueKey in sharedUniqueKeys #1453

Merged
merged 4 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go/logic/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,9 @@ func (this *Inspector) getSharedUniqueKeys(originalUniqueKeys, ghostUniqueKeys [
// the ALTER is on the name itself...
for _, originalUniqueKey := range originalUniqueKeys {
for _, ghostUniqueKey := range ghostUniqueKeys {
if originalUniqueKey.Columns.EqualsByNames(&ghostUniqueKey.Columns) {
if originalUniqueKey.Columns.IsSubsetOf(&ghostUniqueKey.Columns) {
uniqueKeys = append(uniqueKeys, originalUniqueKey)
break
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion go/logic/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestInspectGetSharedUniqueKeys(t *testing.T) {
origUniqKeys := []*sql.UniqueKey{
{Columns: *sql.NewColumnList([]string{"id", "item_id"})},
{Columns: *sql.NewColumnList([]string{"id", "org_id"})},
{Columns: *sql.NewColumnList([]string{"id"})},
}
ghostUniqKeys := []*sql.UniqueKey{
{Columns: *sql.NewColumnList([]string{"id", "item_id"})},
Expand All @@ -24,7 +25,8 @@ func TestInspectGetSharedUniqueKeys(t *testing.T) {
}
inspector := &Inspector{}
sharedUniqKeys := inspector.getSharedUniqueKeys(origUniqKeys, ghostUniqKeys)
require.Len(t, sharedUniqKeys, 2)
require.Len(t, sharedUniqKeys, 3)
require.Equal(t, "id,item_id", sharedUniqKeys[0].Columns.String())
require.Equal(t, "id,org_id", sharedUniqKeys[1].Columns.String())
require.Equal(t, "id", sharedUniqKeys[2].Columns.String())
}
4 changes: 2 additions & 2 deletions localtests/fail-no-shared-uk/create.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
drop table if exists gh_ost_test;
create table gh_ost_test (
id int auto_increment,
id int not null,
i int not null,
ts timestamp,
primary key(id)
) auto_increment=1;
);

drop event if exists gh_ost_test;
delimiter ;;
Expand Down
2 changes: 1 addition & 1 deletion localtests/fail-no-shared-uk/extra_args
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--alter="drop primary key, add primary key (id, i)"
--alter="drop primary key, add primary key (i)"
22 changes: 22 additions & 0 deletions localtests/shared-uk/create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
drop table if exists gh_ost_test;
create table gh_ost_test (
id int auto_increment,
i int not null,
ts timestamp,
primary key(id)
) auto_increment=1;

drop event if exists gh_ost_test;
delimiter ;;
create event gh_ost_test
on schedule every 1 second
starts current_timestamp
ends current_timestamp + interval 60 second
on completion not preserve
enable
do
begin
insert into gh_ost_test values (null, 11, now());
insert into gh_ost_test values (null, 13, now());
insert into gh_ost_test values (null, 17, now());
end ;;
1 change: 1 addition & 0 deletions localtests/shared-uk/extra_args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--alter="drop primary key, add primary key (id, i)"
Loading