Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: support expressions as ON CONFLICT targets #67893

Open
mgartner opened this issue Jul 22, 2021 · 4 comments · Fixed by cockroachdb/activerecord-cockroachdb-adapter#250
Open
Labels
A-sql-optimizer SQL logical planning and optimizations. A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-syntax Issues strictly related to the SQL grammar, with no semantic aspect A-tools-hasura C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-done docs-known-limitation T-sql-queries SQL Queries Team

Comments

@mgartner
Copy link
Collaborator

mgartner commented Jul 22, 2021

We don't currently support expressions as ON CONFLICT targets. This means that unique expression indexes (still a WIP at the time this was written) cannot be selected as arbiters for INSERT .. ON CONFLICT statements. This will require adding support for expression ON CONFLICT targets to the parser and the AST, and updating optbuilder's arbiter logic to select arbiters based on the expression.

Example:

defaultdb> SET experimental_enable_expression_indexes=true;
SET

defaultdb> CREATE TABLE t (a INT, b INT, UNIQUE INDEX ((a + b)));
CREATE TABLE

defaultdb> INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO NOTHING;
invalid syntax: statement ignored: at or near "(": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO NOTHING
                                         ^
HINT: try \h INSERT

defaultdb> INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO UPDATE SET a = 10;
invalid syntax: statement ignored: at or near "(": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
INSERT INTO t VALUES (1, 2) ON CONFLICT ((a + b)) DO UPDATE SET a = 10
                                         ^
HINT: try \h INSERT

Jira issue: CRDB-8765

@mgartner mgartner added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-optimizer SQL logical planning and optimizations. A-sql-syntax Issues strictly related to the SQL grammar, with no semantic aspect labels Jul 22, 2021
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jul 22, 2021
@mgartner mgartner added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Jul 22, 2021
@mgartner
Copy link
Collaborator Author

@ianjevans this will likely be a known limitation for expression indexes in the 21.2 release.

@ecwall
Copy link
Contributor

ecwall commented May 4, 2022

These flags can be enabled after this is fixed: cockroachdb/activerecord-cockroachdb-adapter#250

@mgartner
Copy link
Collaborator Author

I don't think the linked PR fixes this issue. Reopening.

@mgartner mgartner reopened this May 11, 2022
craig bot pushed a commit that referenced this issue May 14, 2022
79623: sql: add virtual indexes to crdb_internal.cluster_locks virtual table  r=AlexTalks a=AlexTalks

This change adds virtual indexes on the `table_id`, `database_name`, and
`table_name` columns of the `crdb_internal.cluster_locks` virtual table,
so that when queried, the `kv.Batch`es with `QueryLocksRequest`s can be
constrained to query only specific tables or databases. This allows the
requests to be much more limited, rather than needing to request all of
the ranges that comprise the key spans of all tables accessible by the
user.

Release note (sql change): Improved query performance for
`crdb_internal.cluster_locks` when issued with constraints in the WHERE
clause on `table_id`, `database_name`, or `table_name` columns.

Depends on #77876, #80422

80832: kvserver: IsCompleteTransaction might panic with certain batch sequences r=shralex a=shralex

It's unclear how this panic happened. One possibility is that EntTxn had a negative sequence number. Another hypothesis is that ba.Requests was concurrently mutated due to a data race. This happened once, so for now adding more info to the panic.

Release note: None

Jira issue: https://cockroachlabs.atlassian.net/browse/CRDB-14627

81190: roachtest: update activerecord adapter to v6.1.10 r=rafiss a=ecwall

refs #67893
refs #80777

This version correctly disables supports_expression_index to
prevent `ON CONFLICT expression` from appearing in generated
SQL statements.

Release note: None

81193: storage: upgrade to pebblev2 table format r=jbowens,nicktrav a=erikgrinaker

Resubmit of #76780, which was partially reverted for 22.1.

---

The `Pebblev2` SSTable format adds support for range keys. Add two new
cluster versions to provide the upgrade path - the first version for
bumping the store, the second for use as a feature gate.

Release note: None

81207: ttljob: fix a range edge case r=rafiss a=otan

See individual commits for details.

Refs: #81208

Co-authored-by: Alex Sarkesian <[email protected]>
Co-authored-by: shralex <[email protected]>
Co-authored-by: Evan Wall <[email protected]>
Co-authored-by: Erik Grinaker <[email protected]>
Co-authored-by: Oliver Tan <[email protected]>
blathers-crl bot pushed a commit that referenced this issue May 14, 2022
refs #67893
refs #80777

This version correctly disables supports_expression_index to
prevent `ON CONFLICT expression` from appearing in generated
SQL statements.

Release note: None
blathers-crl bot pushed a commit that referenced this issue May 16, 2022
refs #67893
refs #80777

This version correctly disables supports_expression_index to
prevent `ON CONFLICT expression` from appearing in generated
SQL statements.

Release note: None
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@mgartner mgartner moved this from Backlog (DO NOT ADD NEW ISSUES) to New Backlog in SQL Queries Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. A-sql-pgcompat Semantic compatibility with PostgreSQL A-sql-syntax Issues strictly related to the SQL grammar, with no semantic aspect A-tools-hasura C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-done docs-known-limitation T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

6 participants