Skip to content

Conversation

@fulghum
Copy link
Contributor

@fulghum fulghum commented Mar 14, 2025

insertIter can be given a sql.RowInserter and a sql.RowUpdater, and when the ON DUPLICATE UPDATE clause is present, it can use both to update a table. StatementBegin was only being called on the sql.RowInserter and not for the sql.RowUpdater, which caused a problem for some implementations (e.g. docsWriter) that depend on StatementBegin being called.

Test for this added to the Dolt package (dolthub/dolt#8988), using the docWriter implementation where this bug was originally discovered.

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.

Maybe Max has a comment on this one too, seems a bit sus.

if updater != nil {
eds = append(eds, updater)
}
return plan.NewTableEditorIter(insertIter, eds...), nil
Copy link
Member

Choose a reason for hiding this comment

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

AFAICT we never use more than one editor in practice, despite this constructor accepting multiple editors. I guess if it works and the tests pass it's fine?

But it seems like there should be at least one engine test that doesn't work before this change and passes now.

Copy link
Contributor Author

@fulghum fulghum Mar 15, 2025

Choose a reason for hiding this comment

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

insertIter takes a replacer, an updater, and an inserter. If the replacer isn't set, it'll use the inserter, and if the inserter fails, it'll handle an ON DUPLICATE UPDATE clause and use the updater.

This doesn't repro with a regular, user table, but is triggered by the docWriter implementation (specifically, the one held in the updater field), because it needs StatementBegin() called to initialize its table writer. Without this, there's a panic from trying to use the nil table writer.

Copy link
Contributor

@max-hoffman max-hoffman left a comment

Choose a reason for hiding this comment

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

The change looks good to me, the editor interfaces are very indirect and different between Dolt and GMS if i'm remembering correctly so good that there's an added test.

@fulghum fulghum merged commit f61a772 into main Mar 15, 2025
9 checks passed
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.

4 participants