Open rytaft opened 4 years ago
I just updated the issue description above to more closely represent the new reality as of July 2022. The first two tasks were completed in https://github.com/cockroachdb/cockroach/pull/74349.
FYI @msirek, this issue gives an overview of the scope of work we were discussing yesterday
Notes: Regarding
take into account the different localities in the input and output distributions and the latency between them.
If we measure latencies between regions at every cluster startup, we might get query plans which change too frequently. Some choices are:
I wonder if #75178 should fall under the umbrella of this issue? It seems difficult for the physical planner to make the decision about whether to distribute scans without some kind of costing.
CockroachDB is a geo-distributed database, but the optimizer currently operates with the assumption that all data is located on the same physical machine. There are a couple of exceptions to this rule, such as the deprecated feature called "duplicated indexes". To use this feature, a user can create two (or more) indexes that have exactly the same columns but are pinned to different localities. For example, a user might choose to pin one index to a data center in the East coast of the US, and another identical index to a data center in the West coast. In this case, with all other things being equal, the optimizer will choose whichever index is closest to the gateway node of the SQL query.
There are lots of other cases, however, where the optimizer does not take data locality into account when it should. For example, the optimizer does not consider locality when deciding between two non-identical indexes (i.e., indexes with different columns). This can lead to suboptimal plans in many cases. The purpose of this issue is to track the work needed to make the optimizer aware of data distribution when planning all queries, not just those that use the duplicated indexes feature.
A few of the features we plan to add are:
crdb_region
) is one of the join keys, it may be possible to hash-partition data within a region and perform the join phase before transferring any data across regions. In other words, the optimizer could transform a single join across regions into a union of joins, where each child of the union is a join within a single region. Another possible transformation where we turn a scan of aREGIONAL BY ROW
table into a pk-fk join with aGLOBAL
table is described in https://github.com/cockroachdb/cockroach/issues/69617#issuecomment-916184772.This is not an exhaustive list, but gives a sense of the scope of work.
gz#9256
Jira issue: CRDB-5025