cockroachdb / cockroachdb/cockroach

opt: coster discrepancy for single-region cluster when region locality is set on the nodes

Open
#106,041 3 comments 0 reactions 0 assignees View on GitHub
C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

In 23.1 we introduced some new costing logic to add a distribution cost for scans accessing a remote region:

https://github.com/cockroachdb/cockroach/blob/3b2d70876abea3f81ff732309c7623f2e2fb6b9b/pkg/sql/opt/xform/coster.go#L835-L846

This may cause a regression in single-region clusters where a region locality is defined on the gateway node but not defined on the table. In this case, the coster thinks that the gateway node is in a different region from the scan, but in fact it is local.

**To Reproduce**

In an opt test, you can run a query like this:
```
# tab is a non-multi-region table.
exec-ddl
CREATE TABLE tab AS (
...
)
----

# performs a scan over table tab.
opt format=show-cost locality=region=us-east1

----

# performs a scan over table tab. The cost of this query will be lower than
# the one above.
opt format=show-cost

----
```
You can also test with a single-region demo cluster: `./cockroach demo`.

**Expected behavior**

The cost should not be different for the same query in a single-region cluster just because the region locality for a node is set. Instead of an empty set of regions for a non-multi-region table, we should probably assign all the regions in the cluster.

Jira issue: CRDB-29363

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.