forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60831: opt,sql: add support for locality optimized scans r=rytaft a=rytaft This commit adds support for a new type of operator called `LocalityOptimizedSearch`. If the session setting `locality_optimized_partitioned_index_scan` is true, the optimizer now plans a `LocalityOptimizedSearch` operation whenever possible. `LocalityOptimizedSearch` is similar to `UnionAll`, but it is designed to avoid communicating with remote nodes (relative to the gateway region) if at all possible. `LocalityOptimizedSearch` can be planned under the following conditions: - A scan is known to produce at most one row. - The scan contains multiple spans, with some spans targeting partitions on local nodes (relative to the gateway region), and some targeting partitions on remote nodes. It is not known which span will produce the row. This commit adds a new exploration rule called `GenerateLocalityOptimizedScan` that generates a `LocalityOptimizedSearch` if the above conditions hold. The result of `GenerateLocalityOptimizedScan` will be a `LocalityOptimizedSearch` in which the left child contains a new scan operator with the local spans from the orginal scan, and the right child contains a new scan operator with the remote spans. The `LocalityOptimizedSearch` operator ensures that the right child (containing remote spans) is only executed if the left child (containing local spans) does not return any rows. This is a useful optimization if there is locality of access in the workload, such that rows tend to be accessed from the region where they are located. If there is no locality of access, using `LocalityOptimizedSearch` could be a slight pessimization, since rows residing in remote regions will be fetched slightly more slowly than they would be otherwise. For example, suppose we have a multi-region database with regions 'us-east1', 'us-west1' and 'europe-west1', and we have the following table and query, issued from 'us-east1': ``` CREATE TABLE tab ( k INT PRIMARY KEY, v INT ) LOCALITY REGIONAL BY ROW; SELECT * FROM tab WHERE k = 10; ``` Normally, this would produce the following plan: ``` scan tab └── constraint: /3/1 ├── [/'europe-west1'/10 - /'europe-west1'/10] ├── [/'us-east1'/10 - /'us-east1'/10] └── [/'us-west1'/10 - /'us-west1'/10] ``` but if the session setting `locality_optimized_partitioned_index_scan` is enabled, the optimizer will produce this plan, using locality optimized search: ``` locality-optimized-search ├── scan tab │ └── constraint: /9/7: [/'us-east1'/10 - /'us-east1'/10] └── scan tab └── constraint: /14/12 ├── [/'europe-west1'/10 - /'europe-west1'/10] └── [/'us-west1'/10 - /'us-west1'/10] ``` As long as `k = 10` is located in 'us-east1', the second plan will be much faster. But if `k = 10` is located in one of the other regions, the first plan would be slightly faster. Informs cockroachdb#55185 Release justification: This commit is a low risk, high benefit change to existing functionality. The session setting that enables the change is locality_optimized_partitioned_index_scan, which is still disabled by default. Release note (performance improvement): If the session setting locality_optimized_partitioned_index_scan is enabled, the optimizer will try to plan scans known to produce at most one row using "locality optimized search". This optimization applies for REGIONAL BY ROW tables, and if enabled, it means that the execution engine will first search locally for the row before searching remote nodes. If the row is found in a local node, remote nodes will not be searched. Co-authored-by: Rebecca Taft <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,316 additions
and
39 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
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.