Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Fix a bug in index assignment that led to incorrect query results, and add index driver to engine_test #864

Closed
wants to merge 51 commits into from

Conversation

zachmu
Copy link
Contributor

@zachmu zachmu commented Nov 6, 2019

In testing out indexing capability with our product's custom IndexDriver, I found a bug. The following query would incorrectly return only a single result on an indexed column for an IndexLookup that didn't implement the Mergeable interface:

SELECT col1 from table where col1 = 1 or col1 = 2;

When the two index lookups couldn't be merged, the first one was returned as the sole lookup for that table. This lookup then got pushed down to the table by the analyzer.

Verifying that this bug was actually fixed ended up being pretty difficult, because engine_test doesn't use an IndexDriver. So I moved the test index types out of assign_indexes_test.go into the memory package, then implemented the Values() method for them so that they could return matching rows from the memory tables. Then I implemented an IndexDriver for the memory package which can be seeded by hand for tests. Finally, I changed TestQueries to test every combination of partitions, index driver, and parallelism, for a total of 12 runs.

The biggest change here is how MergedIndexLookups are handled in the assign_index_tests.go file. What I have now is (I think) more understandable and correct than the previous method of tracking unions and intersections, but did substantially increase the amount of boilerplate in the test code.

Finally, I fixed an unrelated bug in time_test.go, which would fail in my timezone after 4pm due to timezone differences in date calculation.

zachmu and others added 30 commits October 28, 2019 13:59
… that cannot be merged together. This partial index usage resulted in pushdown getting an IndexableTable for only one side of the OR expression, returning incorrect results.

Signed-off-by: Zach Musgrave <[email protected]>
… using them in engine_test.go to reproduce index-related bugs in SELECT statements

Signed-off-by: Zach Musgrave <[email protected]>
…ementations necessarily need to be coupled, so starting down that path.

Signed-off-by: Zach Musgrave <[email protected]>
…un queries with every combination of indexed / parallel / partitioned

Signed-off-by: Zach Musgrave <[email protected]>
…s over each in the parent table looking for matches -- not here to make queries faster, just to test if they give correct results when indexes are involved.

Signed-off-by: Zach Musgrave <[email protected]>
…tering the number of partitions for the test setup

Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
… and intersect functions

Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
…ion for between operation)

Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
…ilures (probably a mistake in the index Values() implementation)

Signed-off-by: Zach Musgrave <[email protected]>
zachmu added 12 commits November 4, 2019 16:33
… to index structs, introduced some new helper functions to cut down on verbosity of test literals

Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
…ummy from the name. Moved a few interface assertions left over from assignindex_test into the type files.

Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
Fixed a bug in indexing code that would cause queries to return incorrect results. Along the way, implemented index capabilities for the in-memory tables (only for correctness verification), and expanded engine_test to test every combination of indexes, partitions, and parallelism.
@zachmu zachmu requested a review from a team as a code owner November 6, 2019 19:27
result, err = assignIndexes(a, node)
require.NoError(err)

lookupIdxs, ok = result["t1"]

Choose a reason for hiding this comment

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

SA4006: this value of lookupIdxs is never used (from staticcheck)

result, err = assignIndexes(a, node)
require.NoError(err)

lookupIdxs, ok = result["t1"]

Choose a reason for hiding this comment

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

SA4006: this value of lookupIdxs is never used (from staticcheck)

…or checking for compatibility

Signed-off-by: Zach Musgrave <[email protected]>
… bug: select col1, col2 from table gets mapped as a ResolvedTable, rather than a Project. This means the columns come back in the wrong order.

Signed-off-by: Zach Musgrave <[email protected]>
…ect were being inappropriately pruned (a Project turned into a ResolvedTable because none of the columns were referenced by a return).

Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
Signed-off-by: Zach Musgrave <[email protected]>
Support for "INSERT INTO table1 SELECT * FROM table2" statements.
@zachmu
Copy link
Contributor Author

zachmu commented Nov 8, 2019

Closing in favor of #865 -- we have continued development on this branch, and this PR is big enough without adding additional features.

@zachmu zachmu closed this Nov 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants