Skip to content

Conversation

VinaiRachakonda
Copy link
Contributor

@VinaiRachakonda VinaiRachakonda commented Jul 1, 2021

Adds tests for transactions and auto increment values.

@VinaiRachakonda VinaiRachakonda changed the title Add transactions test [wip] Add transactions test Jul 1, 2021
@VinaiRachakonda VinaiRachakonda changed the title [wip] Add transactions test Add transactions test Jul 1, 2021
},
{
Query: "/* client a */ select * from t2 order by x",
Expected: []sql.Row{{10, 10}, {12, 12}}, // TODO: Why does it not have (11, 11)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zachmu Can you sanity check this with me? Isn't this a bug?

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.

Looks good, will wait for dolt to settle before stamping

val, err := i.autoIncVal.Eval(ctx, row)
if err != nil {
return nil, err
return given, nil
Copy link
Member

Choose a reason for hiding this comment

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

In general, Eval should be safe to call multiple times, and this change makes that not the case

I think it's fine for now, and you have tests, but add a note for whoever breaks this

sql/core.go Outdated
// PeekNextAutoIncrementValue returns the expected next AUTO_INCREMENT value but does not require
// implementations to update their state.
PeekNextAutoIncrementValue(*Context) (interface{}, error)
// GetNextAutoIncrementValue gets the next AUTO_INCREMENT value.
Copy link
Member

Choose a reason for hiding this comment

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

Need to explain the semantics of the added param

}

nextVal, err := NewIncrement(i.autoIncVal).Eval(ctx, row)
// Integrator answer
// TODO: Calling Eval in general should be safe but since this gets called per row this should be fine.
Copy link
Member

Choose a reason for hiding this comment

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

Comment needs more explanation than this

The problem is that if we call Eval on this expression more than once, we will end up skipping keys

nextVal, err := NewIncrement(i.autoIncVal).Eval(ctx, row)
// Integrator answer
// TODO: Calling Eval in general should be safe but since this gets called per row this should be fine.
last, err := i.autoTbl.GetNextAutoIncrementValue(ctx, given)
Copy link
Member

Choose a reason for hiding this comment

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

last? How about next

val, err := i.autoIncVal.Eval(ctx, row)
if err != nil {
return nil, err
if cmp == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Can't you check if it's nil directly rather than call compare above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

0 is treated as NULL for auto increment columns. I'll fix.

@VinaiRachakonda VinaiRachakonda merged commit 3475290 into master Jul 13, 2021
@Hydrocharged Hydrocharged deleted the vinai/ai-transactions branch December 8, 2021 07:08
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.

2 participants