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

Fixing error on deletes from owning table for a lookup being populated by CreateLookupVindex after a SwitchWrites #8701

Conversation

frouioui
Copy link
Member

Description

After creating two keyspaces and a lookup Vindex using CreateLookupVindex , every delete query that uses the same lookup Vindex starts failing. Below are: a sample query using the column c2 (which is our lookup Vindex); and the error that we got after executing the query.

mysql> delete from table where c2 = 1;
ERROR 1105 (HY000): cannot map vindex to unique keyspace id: DestinationKeyRange(-)

The reason behind this error is the following: the engine tries to execute a delete equal however, the lookup Vindex used to resolve the shard is in write_only mode, meaning we cannot resolve to which shard this query needs to be routed. The default behavior, when this happened, was to return a slice of DestinationKeyRange keyspace IDs, which is not a single shard, thus failing for delete equal. This pull request changes this behavior by transforming delete unique into delete scatter when the query is made using a lookup Vindex on write_only mode.

Related Issue(s)

Checklist

  • Should this PR be backported?
  • Tests were added or are not required
  • Documentation was added or is not required

Copy link
Contributor

@aquarapid aquarapid left a comment

Choose a reason for hiding this comment

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

LGTM; also validated manually with some edgecases.

@deepthi
Copy link
Member

deepthi commented Aug 28, 2021

Does this also fix #7336?

@harshit-gangal
Copy link
Member

Does this also fix #7336?

It does not fix the issue mentioned.

@frouioui
Copy link
Member Author

@harshit-gangal, as we talked about offline: I have modified the code to change the DML's opcode in the planbuilder instead of doing it in the engine

Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

we can remove the changes in the engine test as the changes are associated with the planner.
Also, add unit test at executor level.

go/vt/vtgate/planbuilder/dml.go Outdated Show resolved Hide resolved
@frouioui
Copy link
Member Author

@harshit-gangal, thank you for the review! I have applied the recommended changes

Copy link
Member

@harshit-gangal harshit-gangal left a comment

Choose a reason for hiding this comment

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

changes look good.
More tests are needed in executor and planner where a higher cost Vindex is selected as the lower cost vindex was in backfill.

go/vt/vtgate/executor_dml_test.go Outdated Show resolved Hide resolved
go/vt/vtgate/planbuilder/dml.go Outdated Show resolved Hide resolved
go/vt/vtgate/vindexes/lookup_vindex.go Outdated Show resolved Hide resolved
@harshit-gangal harshit-gangal merged commit 8a8d31b into vitessio:main Sep 6, 2021
@harshit-gangal harshit-gangal deleted the fixing-lookup-vindex-during-backfilling branch September 6, 2021 08:17
aliulis pushed a commit to vinted/vitess that referenced this pull request Feb 28, 2022
…x-during-backfilling

Fixing error on deletes from owning table for a lookup being populated by CreateLookupVindex after a SwitchWrites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants