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

Check for invalid down link while prefetching B-Tree leave pages for index-only scan #9867

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

knizhnik
Copy link
Contributor

Problem

See #9866

Index-only scan prefetch implementation doesn't take in account that down link may be invalid

Summary of changes

Check that downlink is valid block number

Correspondent Postgres PRs:
neondatabase/postgres#534
neondatabase/postgres#535
neondatabase/postgres#536
neondatabase/postgres#537

@knizhnik knizhnik requested a review from a team as a code owner November 24, 2024 18:56
@knizhnik knizhnik requested a review from tristan957 November 24, 2024 18:56
@bayandin bayandin linked an issue Nov 24, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Nov 24, 2024

7095 tests run: 6798 passed, 0 failed, 297 skipped (full report)


Code coverage* (full report)

  • functions: 31.4% (8402 of 26778 functions)
  • lines: 48.1% (66635 of 138650 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
af979af at 2024-12-13T20:37:05.642Z :recycle:

@hlinnaka
Copy link
Contributor

Please add a test case for this

@MMeent
Copy link
Contributor

MMeent commented Nov 25, 2024

I don't think I understand how a downlink can contain InvalidBlockNumber, could you refer me to code which generates that?

@MMeent
Copy link
Contributor

MMeent commented Nov 25, 2024

I think you have a mistaken understanding of the issue. In the issue you've linked the calculated value for skip is sometimes negative. That's bad, because we use that to read from the prefetch_blocks array, which thus causes out-of-bounds reads in that array, which finally would be the cause for InvalidBlockNumber results from that access.

I think you'll have to fix the skip calculation instead of papering over the invalid results from that skip calculation.

Copy link
Contributor

@MMeent MMeent left a comment

Choose a reason for hiding this comment

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

This needs a different approach to fixing the issue, as this seems to just paper over it.

See #9867 (comment)

@knizhnik
Copy link
Contributor Author

I think you have a mistaken understanding of the issue. In the issue you've linked the calculated value for skip is sometimes negative. That's bad, because we use that to read from the prefetch_blocks array, which thus causes out-of-bounds reads in that array, which finally would be the cause for InvalidBlockNumber results from that access.

I think you'll have to fix the skip calculation instead of papering over the invalid results from that skip calculation.

I think you are right. It seems to me that I have saw checks for InvalidBlockNumber but right now I have checked it once again ands that it is used only for parent link.

So I restored original code and added extra checks (including check that skip is not negative). But tests are now passed both CI and locally.
So still trying to reproduce the issue.

@knizhnik knizhnik requested a review from MMeent December 1, 2024 15:52
@knizhnik knizhnik force-pushed the ios_prefetch_fix branch 2 times, most recently from b9c7077 to e07ddc4 Compare December 5, 2024 15:21
Copy link
Contributor

@MMeent MMeent left a comment

Choose a reason for hiding this comment

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

LGTM

@knizhnik knizhnik added this pull request to the merge queue Dec 13, 2024
Merged via the queue into main with commit 2521eba Dec 13, 2024
84 checks passed
@knizhnik knizhnik deleted the ios_prefetch_fix branch December 13, 2024 20:47
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.

Index prefetch attemtps to prefetch invalid blocks
3 participants