-
-
Notifications
You must be signed in to change notification settings - Fork 525
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
Indexes on virtual generated columns generate incorrect results. #8276
Comments
This only happens on Dolt. Running GMS with its in-memory storage returns the correct result. |
Inspecting the secondary index, it appears to be incorrect. In this specific example, the secondary index looks like this:
The first key column is Inserting new rows and updating existing rows causes the correct values to be inserted into the index. It's only creating the index that gives the wrong result. What's interesting is that virtual columns in the table can interfere with the creation of indexes on non-virtual columns:
Results in c6 looking like this:
However, adding an index on My theory to what's going on here is that since virtual columns don't appear in the primary index, they create an off-by-one error when creating a secondary index. For instance, in the above example, |
There's a couple things going on here.
func indexCreateRequiresBuild(n *plan.AlterIndex) bool {
return n.Constraint == sql.IndexConstraint_Unique || indexOnVirtualColumn(n.Columns, n.TargetSchema())
}
(2) seems like vestigal code and an outdated docstring, the Mostly likely what's going on here is that (3) wasn't written with virtual columns in mind. There's a mismatch going on here where the RowIter is returning the underlying physical rows but the Inserter expects the projected rows, including virtual columns. This should be a mismatch between the row lengths, but (4) results in the missing columns being treated as nil instead. We could likely get around this specific issue by not rebuilding the table, but this could still result in incorrect behavior is the table gets rebuilt for other reasons. But we shouldn't ignore (1) either, because needlessly rebuilding the table is slow and expensive. We should fix both issues. |
After adding the index, the same select query returns a different, incorrect result.
The text was updated successfully, but these errors were encountered: