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

allow adding new primary key to table with > 1 row iff it has auto_increment #1343

Merged
merged 8 commits into from
Oct 21, 2022

Conversation

jycor
Copy link
Contributor

@jycor jycor commented Oct 20, 2022

fix for: dolthub/dolt#4581

tests in dolt because memory.Table doesn't implement RewriteableTable
dolthub/dolt#4593

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

  1. the tests should go in this package, not in dolt, and 2) where are tests for the error case (e.g. preventing you from adding a primary key column if it's not auto increment)?

@@ -491,6 +491,12 @@ func (i *addColumnIter) rewriteTable(ctx *sql.Context, rwt sql.RewritableTable)

rowIter := sql.NewTableRowIter(ctx, rwt, partitions)

var autoTbl sql.AutoIncrementTable
if newSch.HasAutoIncrement() {
autoTbl = rwt.(sql.AutoIncrementTable)
Copy link
Member

Choose a reason for hiding this comment

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

This will panic if the interface doesn't match, always use the two-param version

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple comments

}
autoTbl = t
}
idx := newSch.IndexOf(i.a.column.Name, i.a.column.Source)
Copy link
Member

Choose a reason for hiding this comment

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

Call this autoIncColIdx

@@ -504,6 +514,14 @@ func (i *addColumnIter) rewriteTable(ctx *sql.Context, rwt sql.RewritableTable)
return false, err
}

if autoTbl != nil {
val, err := autoTbl.GetNextAutoIncrementValue(ctx, newRow[idx])
Copy link
Member

Choose a reason for hiding this comment

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

This is a really inefficient way to do this. Get this value once, before the loop, and then increment it inside the loop

)
})

t.Run("Add primary key column with auto increment first", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Have a test with a float too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to this warning, mysql plans on deprecating auto_increment float, do you still want me to add a test?

MySQL > alter table t add column pk float primary key auto_increment;
Query OK, 0 rows affected, 1 warning (0.0405 sec)

Records: 0  Duplicates: 0  Warnings: 1
Warning (code 3856): AUTO_INCREMENT support for FLOAT/DOUBLE columns is deprecated and will be removed in a future release. Consider removing AUTO_INCREMENT from column 'pk'.

Copy link
Member

Choose a reason for hiding this comment

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

We support it in dolt (and in GMS) so we should have a test for it

@@ -4996,6 +4996,80 @@ func TestAddDropPks(t *testing.T, harness Harness) {
{1, 1},
}, nil, nil)
})

if _, ok := harness.(*MemoryHarness); ok {
Copy link
Member

Choose a reason for hiding this comment

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

Don't skip like this. Engine tests should always be harness agnostic.

Make a new test method called TestAddAutoIncrementColumn and skip it from memory_engine_test.go

@jycor jycor merged commit 7d96c5d into main Oct 21, 2022
@Hydrocharged Hydrocharged deleted the james/pk branch March 29, 2023 01:09
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.

None yet

2 participants