> The execution part of the patch seems to be working correctly, but I > think there's an improvement - we don't need to execute the outer plan > to completion before emitting the first row. For example, let's say the > outer plan produces 10000 rows in total and we're supposed to return the > first 1% of those rows. We can emit the first row after fetching the > first 100 rows, we don't have to wait for fetching all 10k rows. > > > but total rows count is not given how can we determine safe to return row >
But you know how many rows were fetched from the outer plan, and this number only grows grows. So the number of rows returned by FETCH FIRST ... PERCENT also only grows. For example with 10% of rows, you know that once you reach 100 rows you should emit ~10 rows, with 200 rows you know you should emit ~20 rows, etc. So you may track how many rows we're supposed to return / returned so far, and emit them early.
yes that is clear but i don't find it easy to put that in formula. may be someone with good mathematics will help