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

Fix KV#list with long (≥50ch) prefixes #691

Merged
merged 8 commits into from Oct 25, 2023
Merged

Fix KV#list with long (≥50ch) prefixes #691

merged 8 commits into from Oct 25, 2023

Conversation

huw
Copy link
Contributor

@huw huw commented Sep 22, 2023

Resolves #690. See comments for more.

@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2023

⚠️ No Changeset found

Latest commit: 0480e82

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mrbbot
Copy link
Contributor

mrbbot commented Sep 28, 2023

Hey! 👋 Great catch! I suspect we might need some workerd changes to fix this, will flag internally. 👍

@huw
Copy link
Contributor Author

huw commented Oct 10, 2023

@mrbbot Is there an issue I can follow? I’m not sure if I made it clear but this completely blocks me from using local mode, which means I can’t adopt the Birthday Week features

@huw huw changed the title Add a failing test for KV .list() with a long prefix Fix KV#list with long (≥50ch) prefixes Oct 25, 2023
@huw
Copy link
Contributor Author

huw commented Oct 25, 2023

I narrowed this down to https://github.com/cloudflare/workerd/blob/efa6c737e0aa78af29e353cecc88e05537cb44b3/src/workerd/util/sqlite.c%2B%2B#L526, which sets the LIKE clause limit to 50 characters for security reasons. Unless @kentonv is willing to raise it, I think the easier solution is just to avoid LIKE clauses unless we need complex patterns. As such, I updated the PR to run WHERE SUBSTR(key, 1, LENGTH(:prefix)) = :prefix instead and dropped the escaping code. I can’t see many reasons why it would be slower or otherwise undesirable, but you’ll know this better than I will. Thoughts?

@mrbbot
Copy link
Contributor

mrbbot commented Oct 25, 2023

Hey! 👋 Thank you very much for fixing this, and apologies I didn't get back to you sooner. I asked about this internally, but never followed-up on it. I was going to switch to this exact substr approach if we couldn't get those limits lifted, so very happy with this approach. 😃 Looks like it's still doing an index scan so not concerned about it being slower. 👍

This was also a problem with R2. We're planning to do another patch release today to fix some logging issues. I've committed the required fixes for R2 too, so we can get this in with that. 🙂

@mrbbot mrbbot merged commit 6993c87 into cloudflare:tre Oct 25, 2023
9 checks passed
@huw
Copy link
Contributor Author

huw commented Oct 25, 2023

Goated, cheers mate 🐐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants