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

crosscluster: add new insert/update/delete replication statements #143157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeffswenson
Copy link
Collaborator

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

@jeffswenson jeffswenson requested review from dt, michae2 and msbutler March 19, 2025 20:00
@jeffswenson jeffswenson requested a review from a team as a code owner March 19, 2025 20:00
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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
@jeffswenson jeffswenson force-pushed the jeffswenson-ldr-crud-sql-statements branch from 50c5686 to c52a758 Compare March 19, 2025 21:02
Copy link
Collaborator

@michae2 michae2 left a 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() {
Copy link
Collaborator

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().)

Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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)
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants