Skip to content

Add random rowid sampling helper - #14

Open
shubham-dce wants to merge 1 commit into
eviction-01-policy-registrationfrom
eviction-02-sampling
Open

Add random rowid sampling helper#14
shubham-dce wants to merge 1 commit into
eviction-01-policy-registrationfrom
eviction-02-sampling

Conversation

@shubham-dce

Copy link
Copy Markdown
Owner

Summary

Adds Cache._sample(n), a helper method that returns n randomly picked sample rows from the Cache table for later scoring for size + access_count

Changes

  • Sampling using random rowid jumps instead of using ORDER BY RANDOM() to ensure the cost remains roughly same regardless of the table size.
  • Duplicate row ids within one call of _sample are skipped with the help of the seen set.
  • Handles the cases where cache could be empty or cache size is less than that of input 'n' to _sample(n)

Testing

  • Adds 3 tests, runs successfully, covering the empty cache case, and less number of items than input.
  • Complete test-suite passes successfully. Test coverage above 98%.

shubham-dce commented Aug 14, 2026

Copy link
Copy Markdown
Owner Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants