cockroachdb / cockroachdb/cockroach

sql: support inverted join for tsvector / tsquery

Open
#102,731 1 comment 0 reactions 0 assignees View on GitHub
C-enhancement docs-done docs-known-limitation T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Is your feature request related to a problem? Please describe.**
We currently cannot index-accelerate queries with `@@` predicates when both sides of the operator are variables. For example,
```
SELECT col1, col2, ts_rank(document, query) AS rank
FROM tablename@tablename_expr_idx, to_tsvector(col1 || col2) document, plainto_tsquery('text') query
WHERE query @@ document
ORDER BY rank DESC
LIMIT 10
```
returns the error
```
ERROR: index "tablename_expr_idx" is inverted and cannot be used for this query
```
where `tablename_expr_idx` is defined as:
```
CREATE INDEX ON tablename USING GIN (to_tsvector('english', col1 || col2));
```

**Describe the solution you'd like**
We should add support for inverted join with tsvector / tsquery types so that we can index-accelerate queries like the one above.

Jira issue: CRDB-27620

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the SQL example with the GIN expression index and confirm the current inverted-index error for the query @@ document form. Trace how tsvector and tsquery predicates are handled for inverted joins; done means the query can use the index without that error and has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.