-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Remove counts from CalculateNextIterationRangeEndValues that caused problems with --panic-on-warnings #1557
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
Remove counts from CalculateNextIterationRangeEndValues that caused problems with --panic-on-warnings #1557
Conversation
The split between Temptable and Offset query builders was originally introduced in github#471. Then, both query builders have been changed to calculate actual chunk sizes in github#1500. The updated implementation of the Offset query introduced a bug, where a missing `order by` clause in `select_osc_chunk` can result in end values potentially surpassing the chunk_size. This wasn't detected during our initial testing where the query just returned rows in their original order, but may happen in real-world scenarios in case the db returns data in an undefined order. An obvious fix would be to just add an `order by` to the Offset builder subquery, however since both builders use temptables now, it makes more sense to simplify and use only one of them. Alternatively, the builder could only use the less performant count query variants when `--panic-on-warnings` is enabled and otherwise use the simpler ones from pull/471. We decided to not follow this path for now, hoping `--panic-on-warnings` becomes an updated and safer default in the future. Co-authored-by: Bastian Bartmann <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR consolidates the unique-key range end query to use only the temptable-based builder, removing the offset-based variant and simplifying the applier logic accordingly.
- Removed the
BuildUniqueKeyRangeEndPreparedQueryViaOffset
function and now exclusively use the temptable builder. - Updated the applier to invoke only
BuildUniqueKeyRangeEndPreparedQueryViaTemptable
. - Renamed the corresponding test to
TestBuildUniqueKeyRangeEndPreparedQueryViaTemptable
.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
go/sql/builder_test.go | Renamed test function to match the temptable-only builder |
go/sql/builder.go | Deleted the offset-based builder, retaining only the temptable variant |
go/logic/applier.go | Removed loop over both builders and now calls only the temptable builder |
Thanks @grodowski, we also noticed this bug in production. We also noticed a smaller problem with the range size logic. Between the execution of Lines 1278 to 1281 in 5c88f54
For performance reasons we probably don't want to use a gap lock to ensure |
Thanks for the context @meiji163, it does sound like, given our findings, we should abandon the idea of checking the row count with Do you see any downsides of just dropping the row count check? I don't know there are types of warnings we might need to ignore besides the ones on |
- Removed count subqueries from range builders to restore the more performant approach from PR github#471 - Modified panic-on-warnings logic to trigger errors based solely on SQL warnings, not on row count mismatches - This addresses potential race conditions where row count comparisons could produce false positives due to concurrent table modifications
The split between Temptable and Offset query builders was originally introduced in #471. Then, both query builders have been changed to calculate actual chunk sizes in #1500.
The updated implementation of the Offset query introduced a bug, where a missing
order by
clause inselect_osc_chunk
can result in end values potentially surpassing thechunk_size
. This wasn't detected during our initial testing where the query just returned rows in their original order, but may happen in real-world scenarios in case the db returns data in an undefined order.An obvious fix would be to just add an
order by
to the Offset builder subquery, however since both builders use temptables now, it makes more sense to simplify and use only one of them.Update: using just one query builder was the initial approach in 660cbf9, however based on our findings that the count query can produce unpredictable results with concurrent writes (#1557 (comment)), I propose to drop the row count check in adc7049. This will hopefully mitigate all count-related bugs, bring back the old query builders and make
PanicOnWarnigns
fail in cases where rows are not being dropped, but data is truncated (see added test with a truncated varchar column).Related issue: #1498
script/cibuild
returns with no formatting errors, build errors or unit test errors.