-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
crosscluster: add new insert/update/delete replication statements #143157
base: master
Are you sure you want to change the base?
crosscluster: add new insert/update/delete replication statements #143157
Conversation
These statements take advantage of the KV level LWW validation added by PR cockroachdb#143100 and do not explicitly validate the origin timestamp. Update and Delete specify the whole row in the where clause, which is intended to enable future SQL optimizations that generate a CPUT to replace the row instead Release note: none Epic: CRDB-48647
50c5686
to
c52a758
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice!
columns := table.AllColumns() | ||
result := make([]catalog.Column, 0, len(columns)) | ||
for _, col := range columns { | ||
if !col.IsComputed() && !col.IsVirtual() && !col.IsSystemColumn() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on some semantic checks when building INSERT statements, I believe we also need col.IsPublic()
to avoid mutation columns and !col.IsInaccessible()
to avoid inaccessible columns (which are used by expression indexes among other things).
(Or it might be easier to use table.AccessibleColumns()
instead of table.AllColumns()
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, but it looks like changefeeds use WritableColumns, i.e. they include some mutation columns. I'm a little confused about the interaction of LDR with ALTER. 🤔
names := tree.NameList{nameNode} | ||
|
||
// Create a placeholder for the new value (num_columns+i+1) since we | ||
// placholders to the where and placholders are 1 indexed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment missing a word?
func newDeleteStatement(table catalog.TableDescriptor) (tree.Statement, error) { | ||
columns := getPhysicalColumns(table) | ||
|
||
// Create WHERE clause placeholders for every column in the table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might be able to factor this out of both here and newUpdateStatement
|
||
show-delete table=products | ||
---- | ||
DELETE FROM [108 AS replication_target] WHERE ((((id = $1) AND (name = $2)) AND (unit_price = $3)) AND (quantity = $4)) AND (last_updated = $5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool test!
It might be nice to also see the statements for:
- a regional by row table
- a table with an expression index
- a table with a partial index
- a table with an inverted index
- a table with a virtual computed column
These statements take advantage of the KV level LWW validation added by PR #143100 and do not explicitly validate the origin timestamp. Update and Delete specify the whole row in the where clause, which is intended to enable future SQL optimizations that generate a CPUT to replace the row instead
Release note: none
Epic: CRDB-48647