On Fri, Aug 2, 2019 at 1:43 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > Meh. I think the odds that you got this 100% right are small, and the > odds that it would be maintainable are smaller. There's too much that > can happen if you're not holding any lock --- and there's a lot of active > work on btree indexes, which could break whatever assumptions you might > make today.
I agree that this sounds very scary. > BTW, you haven't even really made the case that optimizing a query that > behaves this way is the right thing to be doing ... maybe some other > plan shape that isn't a nestloop around a LIMIT query would be a better > solution. I wonder if some variety of block nested loop join would be helpful here. I'm not aware of any specific design that would help with Floris' case, but the idea of reducing the number of scans required on the inner side by buffering outer side tuples (say based on the "k=:val" constant) seems like it might generalize well enough. I suggest Floris look into that possibility. This paper might be worth a read: https://dl.acm.org/citation.cfm?id=582278 (Though it also might not be worth a read -- I haven't actually read it myself.) -- Peter Geoghegan