cockroachdb / cockroachdb/cockroach

opt: redundant locality-optimized search operator when only targeting remote regions

Open
#100,934 0 comments 0 reactions 0 assignees View on GitHub
C-cleanup O-qa T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Set up MR cluster via demo
```
cockroach demo movr --global --nodes 9 --multitenant=false --insecure
```
and then
```sql
ALTER DATABASE movr PRIMARY REGION "us-east1";
ALTER DATABASE movr ADD REGION "europe-west1";
ALTER DATABASE movr ADD REGION "us-west1";

CREATE TABLE parent (
p_id INT PRIMARY KEY,
p_attr INT
) LOCALITY REGIONAL BY ROW;

CREATE TABLE child (
c_id INT PRIMARY KEY,
c_p_id INT REFERENCES parent (p_id)
) LOCALITY REGIONAL BY ROW;
```
The query targeting only remote regions has redundant locality-optimized search operator:
```sql
EXPLAIN (opt) SELECT * FROM child INNER LOOKUP JOIN parent ON c_p_id = p_id AND child.crdb_region IN ('us-west1', 'europe-west1') LIMIT 3;
```
```
project
└── limit
├── project
│ └── locality-optimized-search
│ ├── values
│ └── inner-join (lookup parent)
│ ├── flags: force lookup join (into right side)
│ ├── lookup columns are key
│ ├── scan child
│ │ └── constraint: /19/17
│ │ ├── [/'europe-west1' - /'europe-west1']
│ │ └── [/'us-west1' - /'us-west1']
│ └── filters (true)
└── 3
```
```
• limit
│ count: 3

└── • union all

├── • norows

└── • lookup join
│ table: parent@parent_pkey
│ equality cols are key
│ lookup condition: (crdb_region IN ('europe-west1', 'us-east1', 'us-west1')) AND (c_p_id = p_id)

└── • scan
missing stats
table: child@child_pkey
spans: [/'europe-west1' - /'europe-west1'] [/'us-west1' - /'us-west1']
```
Not a big deal, but it'd be great if we could remove this redundant `locality-optimized-search` operator.

Jira issue: CRDB-26705

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.