-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: clean up the lifecycle of fetchers
Previously, the lifecycle of different fetcher objects was a mess. Consider the sequence of fetchers when used by the join reader with the old non-streamer code path: `rowexec.joinReader` -> `row.Fetcher` -> `row.KVFetcher` -> `row.txnKVFetcher`. `row.Fetcher` was initialized once, but then on every call to `StartScan`, we would create a new `row.txnKVFetcher` and then wrap it with a new `row.KVFetcher` (during an internal `StartScanFrom` call). In other words, throughout the lifetime of the join reader, its fetcher would create a new pair of objects for each input row batch. This setup is very unintuitive and previously led to some bugs with memory accounting. I believe such a setup was created organically, without giving too much thought to it. Some considerations should be pointed out: - in some cases, we have some state from the previous fetch that we want to discard - in some cases, we provide the `row.Fetcher` with a custom `KVBatchFetcher` implementation. This commit refactors all of this stuff to make it much more sane. In particular, we now only create a single `row.KVFetcher` object that is powered by a single `row.txnKVFetcher` or `row.txnKVStreamer` implementation throughout the whole lifetime of `row.Fetcher`. In the main code path, the callers are now expected to only use `StartScan` method which correctly discards unnecessary state from the previous call. This is achieved by adding a new method to `KVBatchFetcher` interface. This commit supports the use case with custom `KVBatchFetcher`s too by asking the caller to explicitly specify a knob during the initialization of the `row.Fetcher` - in such case, only `StartScanFrom` calls are allowed. There, we still close the `KVBatchFetcher` from the previous call (tbh I believe this is not necessary since these custom `KVBatchFetcher`s don't have anything to clean up, but it's probably safer to keep the old behavior here). Furthermore, this commit pushes some arguments from `StartScan` into `Init` - most notably the txn is now passed only once. However, there are some use cases (like a column backfill, done in chunks) where the txn might change throughout the lifetime of the fetcher - we allow updating it later if needed. This also allows us to unify the streamer and the non-streamer code paths - to remove some of the duplicated code as well as push the usage of the streamer lower in the stack. Release note: None
- Loading branch information
1 parent
fecfaed
commit e7e724e
Showing
29 changed files
with
595 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.