-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[usage] Batch lookup Workspaces to fix too many placeholders error #10758
Conversation
019e5ab
to
3d5810a
Compare
🤯 is that limit really 2^16? I assumed it would be something like 1000. Anyway, I guess the unit tests will tell -- will take a look today. 👀 |
Yeah I was also surprised. |
components/usage/pkg/db/workspace.go
Outdated
batches := int(math.Ceil(float64(items / listBatchSize))) | ||
for i := 0; i <= batches; i++ { |
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.
Won't this always process one more batch than necessary?
(math.Ceil
already rounds up the number of necessary batches, then you go from 0
to batches
both included?)
batches := int(math.Ceil(float64(items / listBatchSize))) | |
for i := 0; i <= batches; i++ { | |
batches := int(math.Ceil(float64(items / listBatchSize))) | |
for i := 0; i < batches; i++ { |
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.
I've simplified this a bit. The issue was with float64(items / listBatchSize)
which actually performed integer division (div). What it needs to be is float64(items) / listBatchSize
because the numerator determines the resulting type of the division operation, here it's floating point division. Which then works with Ceil to always run at least one batch.
if upper > items { | ||
upper = items | ||
} |
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.
For my own curiosity: In Go, list[lower:upper]
is already safe against out-of-bounds, right? E.g. list[0:10]
on a list with 4 items would return a list with 4 items without errors?
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.
In go, the upper bound from a slice is not safe for out of bounds, it panics https://goplay.tools/snippet/SgSiwcAPfXC
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.
Code looks good and seems to work (according to the unit test).
I find it hard to trust code just based on unit tests (e.g. production workload might be significantly different than what the unit tests do, as we've seen for this bug), but in this case, it's okay to test in production since this component is not on the critical path yet. 😊
Adding a hold because of optional questions/remarks:
/hold
3d5810a
to
7a1eafa
Compare
How do you propose we solve this problem? In general there are a couple of constraints:
|
7a1eafa
to
bce28a3
Compare
/unhold |
Description
Ensures that we do not include more than 2^16 placeholders in a
WHERE field IN (values)
prepared query.https://bugs.mysql.com/bug.php?id=101630
Related Issue(s)
Fixes #10642
How to test
Unit tests
Release Notes
Documentation
NONE