Re: index prefetching

2024-03-05 Thread Jakub Wartak
On Fri, Mar 1, 2024 at 3:58 PM Tomas Vondra wrote: [..] > TBH I don't have a clear idea what to do. It'd be cool to have at least > some benefits in v17, but I don't know how to do that in a way that > would be useful in the future. > > For example, the v20240124 patch implements this in the

Re: index prefetching

2024-03-01 Thread Peter Geoghegan
On Fri, Mar 1, 2024 at 10:18 AM Tomas Vondra wrote: > But I have very hard time figuring out what the MVP version should be, > because I have very limited understanding on how much control the index > AM ought to have :-( And it'd be a bit silly to do something in v17, > only to have to rip it

Re: index prefetching

2024-03-01 Thread Tomas Vondra
On 2/15/24 21:30, Peter Geoghegan wrote: > On Thu, Feb 15, 2024 at 3:13 PM Andres Freund wrote: >>> This is why I don't think that the tuples with lower page offset >>> numbers are in any way significant here. The significant part is >>> whether or not you'll actually need to visit more than one

Re: index prefetching

2024-03-01 Thread Tomas Vondra
Hi, Thanks for looking at the patch! On 3/1/24 09:20, Jakub Wartak wrote: > On Wed, Jan 24, 2024 at 7:13 PM Tomas Vondra > wrote: > [ >> >> (1) Melanie actually presented a very different way to implement this, >> relying on the StreamingRead API. So chances are this struct won't >> actually

Re: index prefetching

2024-03-01 Thread Jakub Wartak
On Wed, Jan 24, 2024 at 7:13 PM Tomas Vondra wrote: [ > > (1) Melanie actually presented a very different way to implement this, > relying on the StreamingRead API. So chances are this struct won't > actually be used. Given lots of effort already spent on this and the fact that is thread is

Re: index prefetching

2024-02-15 Thread Peter Geoghegan
On Thu, Feb 15, 2024 at 3:13 PM Andres Freund wrote: > > This is why I don't think that the tuples with lower page offset > > numbers are in any way significant here. The significant part is > > whether or not you'll actually need to visit more than one leaf page > > in the first place (plus the

Re: index prefetching

2024-02-15 Thread Andres Freund
Hi, On 2024-02-15 12:53:10 -0500, Peter Geoghegan wrote: > On Thu, Feb 15, 2024 at 12:26 PM Tomas Vondra > wrote: > > I may be missing something, but it seems fairly self-evident to me an > > entry at the beginning of an index page won't get prefetched (assuming > > the page-at-a-time thing). >

Re: index prefetching

2024-02-15 Thread Peter Geoghegan
On Thu, Feb 15, 2024 at 12:26 PM Tomas Vondra wrote: > I may be missing something, but it seems fairly self-evident to me an > entry at the beginning of an index page won't get prefetched (assuming > the page-at-a-time thing). Sure, if the first item on the page is also the first item that we

Re: index prefetching

2024-02-15 Thread Tomas Vondra
On 2/15/24 17:42, Peter Geoghegan wrote: > On Thu, Feb 15, 2024 at 9:36 AM Tomas Vondra > wrote: >> On 2/15/24 00:06, Peter Geoghegan wrote: >>> I suppose that it might be much more important than I imagine it is >>> right now, but it'd be nice to have something a bit more concrete to >>> go

Re: index prefetching

2024-02-15 Thread Peter Geoghegan
On Thu, Feb 15, 2024 at 9:36 AM Tomas Vondra wrote: > On 2/15/24 00:06, Peter Geoghegan wrote: > > I suppose that it might be much more important than I imagine it is > > right now, but it'd be nice to have something a bit more concrete to > > go on. > > > > This probably depends on which corner

Re: index prefetching

2024-02-15 Thread Tomas Vondra
On 2/15/24 00:06, Peter Geoghegan wrote: > On Wed, Feb 14, 2024 at 4:46 PM Melanie Plageman > wrote: > >> ... > > 2. Are you sure that the leaf-page-at-a-time thing is such a huge > hindrance to effective prefetching? > > I suppose that it might be much more important than I imagine it is >

Re: index prefetching

2024-02-14 Thread Robert Haas
ands - not hold a pin on the "current" index > leaf page. Which makes index prefetching as currently implemented incompatible > with kill_prior_tuple, as that requires the index leaf page pin being held. But I think it probably also breaks MVCC, as Peter was saying. -- Robert Haas EDB: http://www.enterprisedb.com

Re: index prefetching

2024-02-14 Thread Andres Freund
he first tuples referenced by an index leaf page. However, if we want to issue table readahead for tids on the neighboring index leaf page, we'll - as the patch stands - not hold a pin on the "current" index leaf page. Which makes index prefetching as currently implemented incompati

Re: index prefetching

2024-02-14 Thread Robert Haas
On Wed, Feb 14, 2024 at 7:43 PM Tomas Vondra wrote: > I don't think it's just a bookkeeping problem. In a way, nbtree already > does keep an array of tuples to kill (see btgettuple), but it's always > for the current index page. So it's not that we immediately go and kill > the prior tuple -

Re: index prefetching

2024-02-14 Thread Peter Geoghegan
t be able to design a system where the bitmap > contains a certain number of back-references to the index, allowing later > cleanup if there weren't any page splits or such. That does seem possible, but do you really want a design for index prefetching that relies on that massive enhancement (a to

Re: index prefetching

2024-02-14 Thread Andres Freund
Hi, On 2024-02-13 14:54:14 -0500, Peter Geoghegan wrote: > This property of index scans is fundamental to how index scans work. > Pinning an index page as an interlock against concurrently TID > recycling by VACUUM is directly described by the index API docs [1], > even (the docs actually use

Re: index prefetching

2024-02-14 Thread Andres Freund
Hi, On 2024-02-14 16:45:57 -0500, Melanie Plageman wrote: > > > The LIMIT problem is not very clear to me either. Yes, if we get close > > > to the end of the leaf page, we may need to visit the next leaf page. > > > But that's kinda the whole point of prefetching - reading stuff ahead, > > > and

Re: index prefetching

2024-02-14 Thread Peter Geoghegan
he leaf-page-at-a-time thing, and that still seemed like a big improvement to me. While being less invasive, in effect. If we can agree that something like that represents a useful step in the right direction (not an evolutionary dead end), then we can make good incremental progress within a sin

Re: index prefetching

2024-02-14 Thread Melanie Plageman
index scan is about the index scan > itself, first and foremost. The heap accesses are usually the dominant > cost, of course, but sometimes the index leaf page accesses really do > make up a significant fraction of the overall cost of the index scan. > Especially with an expensive index qual. S

Re: index prefetching

2024-02-14 Thread Melanie Plageman
On Wed, Feb 14, 2024 at 11:40 AM Melanie Plageman wrote: > > On Tue, Feb 13, 2024 at 2:01 PM Tomas Vondra > wrote: > > > > On 2/7/24 22:48, Melanie Plageman wrote: > > > ... > > > - switching scan directions > > > > > > If the index scan switches directions on a given invocation of > > >

Re: index prefetching

2024-02-14 Thread Peter Geoghegan
On Wed, Feb 14, 2024 at 11:40 AM Melanie Plageman wrote: > I wasn't quite sure how we could use > index_compute_xid_horizon_for_tuples() for inspiration -- per Peter's > suggestion. But, I'd like to understand. The point I was trying to make with that example was: a highly generic mechanism can

Re: index prefetching

2024-02-14 Thread Peter Geoghegan
On Wed, Feb 14, 2024 at 8:34 AM Tomas Vondra wrote: > > Another thing that argues against doing this is that we might not need > > to visit any more B-Tree leaf pages when there is a LIMIT n involved. > > We could end up scanning a whole extra leaf page (including all of its > > tuples) for want

Re: index prefetching

2024-02-14 Thread Melanie Plageman
On Tue, Feb 13, 2024 at 2:01 PM Tomas Vondra wrote: > > On 2/7/24 22:48, Melanie Plageman wrote: > > ... Issues > > --- > > - kill prior tuple > > > > This optimization doesn't work with index prefetching with the current > > design. Kill prior tu

Re: index prefetching

2024-02-14 Thread Tomas Vondra
On 2/14/24 08:10, Robert Haas wrote: > On Thu, Feb 8, 2024 at 3:18 AM Melanie Plageman > wrote: >> - kill prior tuple >> >> This optimization doesn't work with index prefetching with the current >> design. Kill prior tuple relies on alternating between fe

Re: index prefetching

2024-02-14 Thread Tomas Vondra
On 2/13/24 20:54, Peter Geoghegan wrote: > On Tue, Feb 13, 2024 at 2:01 PM Tomas Vondra > wrote: >> On 2/7/24 22:48, Melanie Plageman wrote: >> I admit I haven't thought about kill_prior_tuple until you pointed out. >> Yeah, prefetching separates (de-synchronizes) the two scans (index and >>

Re: index prefetching

2024-02-13 Thread Robert Haas
On Thu, Feb 8, 2024 at 3:18 AM Melanie Plageman wrote: > - kill prior tuple > > This optimization doesn't work with index prefetching with the current > design. Kill prior tuple relies on alternating between fetching a > single index tuple and visiting the heap. After visiting th

Re: index prefetching

2024-02-13 Thread Peter Geoghegan
On Tue, Feb 13, 2024 at 2:01 PM Tomas Vondra wrote: > On 2/7/24 22:48, Melanie Plageman wrote: > I admit I haven't thought about kill_prior_tuple until you pointed out. > Yeah, prefetching separates (de-synchronizes) the two scans (index and > heap) in a way that prevents this optimization. Or at

Re: index prefetching

2024-02-13 Thread Tomas Vondra
ould need to solve in the streaming read API. Some are > issues with index prefetching generally. > > Note that these two patches have to be applied before 21d9c3ee4e > because Thomas hasn't released a rebased version of the streaming read > API patches yet. > Thanks for wo

Re: index prefetching

2024-02-07 Thread Melanie Plageman
est), so I suspect I have some kind of > control flow issue. Perhaps I should fix the resource leak so I can > actually see the failing tests :) Attached is a patch which implements a real queue and fixes some of the issues with the previous version. It doesn't pass tests yet and has issues. Some

Re: index prefetching

2024-01-25 Thread Tomas Vondra
On 1/25/24 11:45, Dilip Kumar wrote: > On Wed, Jan 24, 2024 at 11:43 PM Tomas Vondra > wrote: > >> On 1/22/24 07:35, Konstantin Knizhnik wrote: >>> >>> On 22/01/2024 1:47 am, Tomas Vondra wrote: h, right. Well, you're right in this case we perhaps could set just one of those flags,

Re: index prefetching

2024-01-25 Thread Dilip Kumar
On Wed, Jan 24, 2024 at 11:43 PM Tomas Vondra wrote: > On 1/22/24 07:35, Konstantin Knizhnik wrote: > > > > On 22/01/2024 1:47 am, Tomas Vondra wrote: > >> h, right. Well, you're right in this case we perhaps could set just one > >> of those flags, but the "purpose" of the two places is quite

Re: index prefetching

2024-01-24 Thread Melanie Plageman
t;>> bother investigating [which causes it to fail tests]). > >>> > >>> 0001 is all of Thomas' streaming read API code that isn't yet in > >>> master and 0002 is my rough sketch of index prefetching using the > >>> streaming read API > >>>

Re: index prefetching

2024-01-24 Thread Tomas Vondra
On 1/22/24 07:35, Konstantin Knizhnik wrote: > > On 22/01/2024 1:47 am, Tomas Vondra wrote: >> h, right. Well, you're right in this case we perhaps could set just one >> of those flags, but the "purpose" of the two places is quite different. >> >> The "prefetch" flag is fully controlled by the

Re: index prefetching

2024-01-24 Thread Tomas Vondra
On 1/22/24 08:21, Konstantin Knizhnik wrote: > > On 22/01/2024 1:39 am, Tomas Vondra wrote: >>> Why we can prefer covering index  to compound index? I see only two good >>> reasons: >>> 1. Extra columns type do not  have comparison function need for AM. >>> 2. The extra columns are never used in

Re: index prefetching

2024-01-24 Thread Tomas Vondra
. A lage TID queue can't cause overload of anything. What could happen is a TID queue being too small, so the prefetch can't hit the target distance. But that can happen already, e.g. indexes that are correlated and/or index-only scans with all-visible pages. >>> There are also table AM

Re: index prefetching

2024-01-23 Thread Melanie Plageman
t week. > > There are also table AM layering violations in my sketch which would > > have to be worked out (not to mention some resource leakage I didn't > > bother investigating [which causes it to fail tests]). > > > > 0001 is all of Thomas' streaming read API cod

Re: index prefetching

2024-01-23 Thread Tomas Vondra
single entry? Shouldn't the first queue (blk_queue) store TIDs instead? > There are also table AM layering violations in my sketch which would > have to be worked out (not to mention some resource leakage I didn't > bother investigating [which causes it to fail tests]). > > 0001 is al

Re: index prefetching

2024-01-21 Thread Konstantin Knizhnik
On 22/01/2024 1:39 am, Tomas Vondra wrote: Why we can prefer covering index  to compound index? I see only two good reasons: 1. Extra columns type do not  have comparison function need for AM. 2. The extra columns are never used in query predicate. Or maybe you don't want to include the

Re: index prefetching

2024-01-21 Thread Konstantin Knizhnik
On 22/01/2024 1:47 am, Tomas Vondra wrote: h, right. Well, you're right in this case we perhaps could set just one of those flags, but the "purpose" of the two places is quite different. The "prefetch" flag is fully controlled by the prefetcher, and it's up to it to change it (e.g. I can

Re: index prefetching

2024-01-21 Thread Peter Smith
2024-01 Commitfest. Hi, This patch has a CF status of "Needs Review" [1], but it seems like there were CFbot test failures last time it was run [2]. Please have a look and post an updated version if necessary. == [1] https://commitfest.postgresql.org/46/4351/ [2]

Re: index prefetching

2024-01-21 Thread Tomas Vondra
On 1/21/24 20:56, Konstantin Knizhnik wrote: > > On 19/01/2024 2:35 pm, Tomas Vondra wrote: >> >> On 1/19/24 09:34, Konstantin Knizhnik wrote: >>> On 18/01/2024 6:00 pm, Tomas Vondra wrote: On 1/17/24 09:45, Konstantin Knizhnik wrote: > I have integrated your prefetch patch in Neon

Re: index prefetching

2024-01-21 Thread Tomas Vondra
On 1/21/24 20:50, Konstantin Knizhnik wrote: > > On 20/01/2024 12:14 am, Tomas Vondra wrote: >> Looks like I was not true, even if it is not index-only scan but index >>> condition involves only index attributes, then heap is not accessed >>> until we find tuple satisfying search condition.

Re: index prefetching

2024-01-21 Thread Konstantin Knizhnik
On 19/01/2024 2:35 pm, Tomas Vondra wrote: On 1/19/24 09:34, Konstantin Knizhnik wrote: On 18/01/2024 6:00 pm, Tomas Vondra wrote: On 1/17/24 09:45, Konstantin Knizhnik wrote: I have integrated your prefetch patch in Neon and it actually works! Moreover, I combined it with prefetch of leaf

Re: index prefetching

2024-01-21 Thread Konstantin Knizhnik
On 20/01/2024 12:14 am, Tomas Vondra wrote: Looks like I was not true, even if it is not index-only scan but index condition involves only index attributes, then heap is not accessed until we find tuple satisfying search condition. Inclusive index case described above

Re: index prefetching

2024-01-19 Thread Tomas Vondra
On 1/19/24 16:19, Konstantin Knizhnik wrote: > > On 18/01/2024 5:57 pm, Tomas Vondra wrote: >> On 1/16/24 21:10, Konstantin Knizhnik wrote: >>> ... >>> 4. I think that performing prefetch at executor level is really great > idea and so prefetch can be used by all indexes, including

Re: index prefetching

2024-01-19 Thread Melanie Plageman
There are also table AM layering violations in my sketch which would have to be worked out (not to mention some resource leakage I didn't bother investigating [which causes it to fail tests]). 0001 is all of Thomas' streaming read API code that isn't yet in master and 0002 is my rough sketch

Re: index prefetching

2024-01-19 Thread Konstantin Knizhnik
On 18/01/2024 5:57 pm, Tomas Vondra wrote: On 1/16/24 21:10, Konstantin Knizhnik wrote: ... 4. I think that performing prefetch at executor level is really great idea and so prefetch can be used by all indexes, including custom indexes. But prefetch will be efficient only if index can

Re: index prefetching

2024-01-19 Thread Tomas Vondra
On 1/19/24 09:34, Konstantin Knizhnik wrote: > > On 18/01/2024 6:00 pm, Tomas Vondra wrote: >> On 1/17/24 09:45, Konstantin Knizhnik wrote: >>> I have integrated your prefetch patch in Neon and it actually works! >>> Moreover, I combined it with prefetch of leaf pages for IOS and it also >>>

Re: index prefetching

2024-01-19 Thread Konstantin Knizhnik
On 18/01/2024 6:00 pm, Tomas Vondra wrote: On 1/17/24 09:45, Konstantin Knizhnik wrote: I have integrated your prefetch patch in Neon and it actually works! Moreover, I combined it with prefetch of leaf pages for IOS and it also seems to work. Cool! And do you think this is the right

Re: index prefetching

2024-01-18 Thread Tomas Vondra
On 1/17/24 09:45, Konstantin Knizhnik wrote: > I have integrated your prefetch patch in Neon and it actually works! > Moreover, I combined it with prefetch of leaf pages for IOS and it also > seems to work. > Cool! And do you think this is the right design/way to do this? > Just small notice:

Re: index prefetching

2024-01-18 Thread Tomas Vondra
On 1/16/24 21:10, Konstantin Knizhnik wrote: > > ... > >> 4. I think that performing prefetch at executor level is really great >>> idea and so prefetch can be used by all indexes, including custom >>> indexes. But prefetch will be efficient only if index can provide fast >>> access to next TID

Re: index prefetching

2024-01-17 Thread Konstantin Knizhnik
I have integrated your prefetch patch in Neon and it actually works! Moreover, I combined it with prefetch of leaf pages for IOS and it also seems to work. Just small notice: you are reporting `blks_prefetch_rounds` in explain, but it is not incremented anywhere. Moreover, I do not precisely

Re: index prefetching

2024-01-17 Thread Konstantin Knizhnik
On 16/01/2024 11:58 pm, Jim Nasby wrote: On 1/16/24 2:10 PM, Konstantin Knizhnik wrote: Amazon RDS is just vanilla Postgres with file system mounted on EBS (Amazon  distributed file system). EBS provides good throughput but larger latencies comparing with local SSDs. I am not sure if

Re: index prefetching

2024-01-16 Thread Konstantin Knizhnik
On 16/01/2024 11:58 pm, Jim Nasby wrote: On 1/16/24 2:10 PM, Konstantin Knizhnik wrote: Amazon RDS is just vanilla Postgres with file system mounted on EBS (Amazon  distributed file system). EBS provides good throughput but larger latencies comparing with local SSDs. I am not sure if

Re: index prefetching

2024-01-16 Thread Jim Nasby
On 1/16/24 2:10 PM, Konstantin Knizhnik wrote: Amazon RDS is just vanilla Postgres with file system mounted on EBS (Amazon  distributed file system). EBS provides good throughput but larger latencies comparing with local SSDs. I am not sure if read-ahead works for EBS. Actually, EBS only

Re: index prefetching

2024-01-16 Thread Konstantin Knizhnik
On 16/01/2024 6:25 pm, Tomas Vondra wrote: On 1/16/24 09:13, Konstantin Knizhnik wrote: Hi, On 12/01/2024 6:42 pm, Tomas Vondra wrote: Hi, Here's an improved version of this patch, finishing a lot of the stuff that I alluded to earlier - moving the code from indexam.c, renaming a bunch of

Re: index prefetching

2024-01-16 Thread Robert Haas
On Tue, Jan 16, 2024 at 11:25 AM Tomas Vondra wrote: > > 3. It doesn't perform prefetch of leave pages for IOS, only referenced > > heap pages which are not marked as all-visible. It seems to me that if > > optimized has chosen IOS (and not bitmap heap scan for example), then > > there should be

Re: index prefetching

2024-01-16 Thread Tomas Vondra
On 1/16/24 09:13, Konstantin Knizhnik wrote: > Hi, > > On 12/01/2024 6:42 pm, Tomas Vondra wrote: >> Hi, >> >> Here's an improved version of this patch, finishing a lot of the stuff >> that I alluded to earlier - moving the code from indexam.c, renaming a >> bunch of stuff, etc. I've also

Re: index prefetching

2024-01-16 Thread Konstantin Knizhnik
Hi, On 12/01/2024 6:42 pm, Tomas Vondra wrote: Hi, Here's an improved version of this patch, finishing a lot of the stuff that I alluded to earlier - moving the code from indexam.c, renaming a bunch of stuff, etc. I've also squashed it into a single patch, to make it easier to review. I am

Re: index prefetching

2024-01-12 Thread Robert Haas
Not a full response, but just to address a few points: On Fri, Jan 12, 2024 at 11:42 AM Tomas Vondra wrote: > Thinking about this, I think it should be possible to make prefetching > work even for plans with execute_once=false. In particular, when the > plan changes direction it should be

Re: index prefetching

2024-01-12 Thread Tomas Vondra
generally had the same effect, I think. > + * XXX This might lead to IOS being slower than plain index scan, if the > + * table has a lot of pages that need recheck. > > How? > The comment is not particularly clear what "this" means, but I believe this

Re: index prefetching

2024-01-09 Thread Robert Haas
ed to be + * parallel. Well, this seems sad. + * XXX This might lead to IOS being slower than plain index scan, if the + * table has a lot of pages that need recheck. How? + /* + * XXX Only allow index prefetching when parallelModeOK=true. This is a bit + * of a misuse of

Re: index prefetching

2024-01-04 Thread Tomas Vondra
Hi, Here's a somewhat reworked version of the patch. My initial goal was to see if it could adopt the StreamingRead API proposed in [1], but that turned out to be less straight-forward than I hoped, for two reasons: (1) The StreamingRead API seems to be designed for pages, but the index code

Re: index prefetching

2023-12-21 Thread Tomas Vondra
On 12/21/23 18:14, Robert Haas wrote: > On Thu, Dec 21, 2023 at 11:08 AM Andres Freund wrote: >> But I'd like you to feel guilty (no, not really) and fix it (yes, really) :) > > Sadly, you're more likely to get the first one than you are to get the > second one. I can't really see going back to

Re: index prefetching

2023-12-21 Thread Robert Haas
On Thu, Dec 21, 2023 at 11:08 AM Andres Freund wrote: > But I'd like you to feel guilty (no, not really) and fix it (yes, really) :) Sadly, you're more likely to get the first one than you are to get the second one. I can't really see going back to revisit that decision as a basis for somebody

Re: index prefetching

2023-12-21 Thread Andres Freund
Hi, On 2023-12-21 11:00:34 -0500, Robert Haas wrote: > On Thu, Dec 21, 2023 at 10:33 AM Tomas Vondra > wrote: > > > I continue to think that we should not have split plain and index only > > > scans > > > into separate files... > > > > I do agree with that opinion. Not just because of this

Re: index prefetching

2023-12-21 Thread Robert Haas
On Thu, Dec 21, 2023 at 10:33 AM Tomas Vondra wrote: > > I continue to think that we should not have split plain and index only scans > > into separate files... > > I do agree with that opinion. Not just because of this prefetching > thread, but also because of the discussions about index-only

Re: index prefetching

2023-12-21 Thread Andres Freund
Hi, On 2023-12-21 16:20:45 +0100, Tomas Vondra wrote: > On 12/21/23 14:43, Andres Freund wrote: > >> AFAICS this seems similar to some of the AIO patch, I wonder what that > >> plans to do. I need to check. > > > > Yes, most of this exists there. The difference that with the AIO you don't > >

Re: index prefetching

2023-12-21 Thread Tomas Vondra
On 12/21/23 14:27, Andres Freund wrote: > Hi, > > On 2023-12-09 19:08:20 +0100, Tomas Vondra wrote: >> But there's a layering problem that I don't know how to solve - I don't >> see how we could make indexam.c entirely oblivious to the prefetching, >> and move it entirely to the executor.

Re: index prefetching

2023-12-21 Thread Tomas Vondra
On 12/21/23 14:43, Andres Freund wrote: > Hi, > > On 2023-12-21 13:30:42 +0100, Tomas Vondra wrote: >> You're right a lot of this is a guesswork. I don't think we can do much >> better, because it depends on stuff that's out of our control - each OS >> may do things differently, or perhaps

Re: index prefetching

2023-12-21 Thread Andres Freund
Hi, On 2023-12-21 13:30:42 +0100, Tomas Vondra wrote: > You're right a lot of this is a guesswork. I don't think we can do much > better, because it depends on stuff that's out of our control - each OS > may do things differently, or perhaps it's just configured differently. > > But I don't

Re: index prefetching

2023-12-21 Thread Andres Freund
Hi, On 2023-12-09 19:08:20 +0100, Tomas Vondra wrote: > But there's a layering problem that I don't know how to solve - I don't > see how we could make indexam.c entirely oblivious to the prefetching, > and move it entirely to the executor. Because how else would you know > what to prefetch? >

Re: index prefetching

2023-12-21 Thread Tomas Vondra
On 12/21/23 07:49, Dilip Kumar wrote: > On Wed, Dec 20, 2023 at 7:11 AM Tomas Vondra > wrote: >> > I was going through to understand the idea, couple of observations > > -- > + for (int i = 0; i < PREFETCH_LRU_SIZE; i++) > + { > + entry = >prefetchCache[lru * PREFETCH_LRU_SIZE + i]; > + > +

Re: index prefetching

2023-12-21 Thread Tomas Vondra
On 12/20/23 20:09, Robert Haas wrote: > On Tue, Dec 19, 2023 at 8:41 PM Tomas Vondra > ... >> I have imagined something like this: >> >> nodeIndexscan / index_getnext_slot() >> -> no callback, all TIDs are prefetched >> >> nodeIndexonlyscan / index_getnext_tid() >> -> callback checks VM for the

Re: index prefetching

2023-12-20 Thread Dilip Kumar
On Wed, Dec 20, 2023 at 7:11 AM Tomas Vondra wrote: > I was going through to understand the idea, couple of observations -- + for (int i = 0; i < PREFETCH_LRU_SIZE; i++) + { + entry = >prefetchCache[lru * PREFETCH_LRU_SIZE + i]; + + /* Is this the oldest prefetch request in this LRU? */ + if

Re: index prefetching

2023-12-20 Thread Robert Haas
On Tue, Dec 19, 2023 at 8:41 PM Tomas Vondra wrote: > Whatever the right abstraction is, it probably needs to do these VM > checks only once. Makes sense. > Yeah, after you pointed out the "leaky" abstraction, I also started to > think about customizing the behavior using a callback. Not sure

Re: index prefetching

2023-12-19 Thread Tomas Vondra
he executor. Because how else would you know >> what to prefetch? > > Yeah, that seems impossible. > > Some thoughts: > > * I think perhaps the subject line of this thread is misleading. It > doesn't seem like there is any index prefetching going on here at all, > a

Re: index prefetching

2023-12-18 Thread Robert Haas
fetch? Yeah, that seems impossible. Some thoughts: * I think perhaps the subject line of this thread is misleading. It doesn't seem like there is any index prefetching going on here at all, and there couldn't be, unless you extended the index AM API with new methods. What you're actually doing is

Re: index prefetching

2023-07-14 Thread Tomas Vondra
x_beginscan(heap, index, , indnkeyatts, 0, 0, 0); index_rescan(index_scan, scankeys, indnkeyatts, NULL, 0); while (index_getnext_slot(index_scan, ForwardScanDirection, existing_slot)) diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index e776524227..c0bb732658 10

Re: index prefetching

2023-06-30 Thread Tomas Vondra
x_scan = index_beginscan(heap, index, , indnkeyatts, 0); + index_scan = index_beginscan(heap, index, , indnkeyatts, 0, 0, 0); index_rescan(index_scan, scankeys, indnkeyatts, NULL, 0); while (index_getnext_slot(index_scan, ForwardScanDirection, existing_slot)) diff --git a/src/backend/executor/

Re: index prefetching

2023-06-19 Thread Tomas Vondra
el index scan * * Caller must be holding suitable locks on the heap and the index. + * + * XXX See index_beginscan() for more comments on prefetch_target. */ IndexScanDesc index_beginscan_parallel(Relation heaprel, Relation indexrel, int nkeys, - int norderbys, ParallelIndexScanDesc

Re: index prefetching

2023-06-12 Thread Dilip Kumar
On Thu, Jun 8, 2023 at 9:10 PM Tomas Vondra wrote: > We already do prefetching for bitmap index scans, where the bitmap heap > scan prefetches future pages based on effective_io_concurrency. I'm not > sure why exactly was prefetching implemented only for bitmap scans, but > I suspect the

Re: index prefetching

2023-06-12 Thread Tomasz Rybak
On Thu, 2023-06-08 at 17:40 +0200, Tomas Vondra wrote: > Hi, > > At pgcon unconference I presented a PoC patch adding prefetching for > indexes, along with some benchmark results demonstrating the (pretty > significant) benefits etc. The feedback was quite positive, so let me > share the current

Re: index prefetching

2023-06-10 Thread Tomas Vondra
On 6/10/23 22:34, Andres Freund wrote: > Hi, > > On 2023-06-09 12:18:11 +0200, Tomas Vondra wrote: >>> 2) prefetching from executor Another question is whether the prefetching shouldn't actually happen even higher - in the executor. That's what Andres suggested during the

Re: index prefetching

2023-06-10 Thread Andres Freund
Hi, On 2023-06-09 12:18:11 +0200, Tomas Vondra wrote: > > > >> 2) prefetching from executor > >> > >> Another question is whether the prefetching shouldn't actually happen > >> even higher - in the executor. That's what Andres suggested during the > >> unconference, and it kinda makes sense.

Re: index prefetching

2023-06-09 Thread Gregory Smith
On Thu, Jun 8, 2023 at 11:40 AM Tomas Vondra wrote: > We already do prefetching for bitmap index scans, where the bitmap heap > scan prefetches future pages based on effective_io_concurrency. I'm not > sure why exactly was prefetching implemented only for bitmap scans At the point Greg Stark

Re: index prefetching

2023-06-09 Thread Peter Geoghegan
On Fri, Jun 9, 2023 at 3:45 AM Tomas Vondra wrote: > > What the exact historical timeline is may not be that important. My > > emphasis on ScalarArrayOpExpr is partly due to it being a particularly > > compelling case for both parallel index scan and prefetching, in > > general. There are many

Re: index prefetching

2023-06-09 Thread Tomas Vondra
On 6/9/23 01:38, Peter Geoghegan wrote: > On Thu, Jun 8, 2023 at 3:17 PM Tomas Vondra > wrote: >> Normal index scans are an even more interesting case but I'm not >> sure how hard it would be to get that information. It may only be >> convenient to get the blocks from the last leaf

Re: index prefetching

2023-06-09 Thread Tomas Vondra
On 6/9/23 02:06, Andres Freund wrote: > Hi, > > On 2023-06-08 17:40:12 +0200, Tomas Vondra wrote: >> At pgcon unconference I presented a PoC patch adding prefetching for >> indexes, along with some benchmark results demonstrating the (pretty >> significant) benefits etc. The feedback was quite

Re: index prefetching

2023-06-08 Thread Peter Geoghegan
On Thu, Jun 8, 2023 at 4:38 PM Peter Geoghegan wrote: > This is conceptually a "mini bitmap index scan", though one that takes > place "inside" a plain index scan, as it processes one particular leaf > page. That's the kind of design that "plain index scan vs bitmap index > scan as a continuum"

Re: index prefetching

2023-06-08 Thread Andres Freund
Hi, On 2023-06-08 17:40:12 +0200, Tomas Vondra wrote: > At pgcon unconference I presented a PoC patch adding prefetching for > indexes, along with some benchmark results demonstrating the (pretty > significant) benefits etc. The feedback was quite positive, so let me > share the current patch

Re: index prefetching

2023-06-08 Thread Peter Geoghegan
On Thu, Jun 8, 2023 at 3:17 PM Tomas Vondra wrote: > Normal index scans are an even more interesting case but I'm not > sure how hard it would be to get that information. It may only be > convenient to get the blocks from the last leaf page we looked at, > for example. > > So this

Re: index prefetching

2023-06-08 Thread Tomas Vondra
On 6/8/23 20:56, Peter Geoghegan wrote: > On Thu, Jun 8, 2023 at 8:40 AM Tomas Vondra > wrote: >> We already do prefetching for bitmap index scans, where the bitmap heap >> scan prefetches future pages based on effective_io_concurrency. I'm not >> sure why exactly was prefetching implemented only

Re: index prefetching

2023-06-08 Thread Peter Geoghegan
On Thu, Jun 8, 2023 at 8:40 AM Tomas Vondra wrote: > We already do prefetching for bitmap index scans, where the bitmap heap > scan prefetches future pages based on effective_io_concurrency. I'm not > sure why exactly was prefetching implemented only for bitmap scans, but > I suspect the