cockroachdb / cockroachdb/cockroach

opt: support locality-optimized search for filters on non-indexed columns

Open
#99,535 1 comment 0 reactions 0 assignees View on GitHub
A-multiregion A-sql-optimizer C-enhancement O-qa T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

We can use locality-optimized search with a predicate on a primary key or index key (which turns into a constrained scan), or no predicate at all (which turns into a full scan) but not with a predicate on a non-indexed key (which turns into a full scan and a filter). It seems like this should be possible. Here's an example using `cockroach demo --global --nodes 9 --multitenant=false --insecure`:

```sql
CREATE DATABASE d PRIMARY REGION "us-east1" REGIONS "europe-west1", "us-west1";
SHOW CREATE DATABASE d;
USE d;

CREATE TABLE abc (
a INT,
b INT,
c INT,
PRIMARY KEY (a),
INDEX (b)
) LOCALITY REGIONAL BY ROW;
SHOW CREATE TABLE abc;

INSERT INTO abc (a, b, c, crdb_region) VALUES (0, 0, 0, 'us-east1'), (1, 1, 1, 'europe-west1'), (2, 2, 2, 'us-west1');

SET enforce_home_region = on;

SHOW LOCALITY;

-- these three use LOS
SELECT a FROM abc LIMIT 1;
SELECT a FROM abc WHERE a = 0 LIMIT 1;
SELECT a FROM abc WHERE b = 0 LIMIT 1;

-- this does not currently use LOS, but seems like it should be able to if the full scan above can
SELECT a FROM abc WHERE c = 0 LIMIT 1;
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the SQL example with `cockroach demo --global --nodes 9 --multitenant=false --insecure`, then trace how locality-optimized search plans predicates on indexed versus non-indexed columns. Done means the `WHERE c = 0` query can use locality-optimized search and regression coverage confirms the resulting plan and behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases, distributed-systems, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.