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: fast path uniqueness checks for single-row insert #102995

Closed
wants to merge 9 commits into from
25 changes: 12 additions & 13 deletions pkg/ccl/logictestccl/testdata/logic_test/explain_redact
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ insert p
├── key: ()
├── fd: ()-->(5,6)
├── distribution: test
├── prune: (5,6)
└── ‹(‹×›, ‹×›)›

query T
Expand All @@ -133,7 +132,6 @@ insert p
├── key: ()
├── fd: ()-->(5,6)
├── distribution: test
├── prune: (5,6)
└── tuple [type=tuple{int, int}]
├── const: ‹×› [type=int]
└── const: ‹×› [type=int]
Expand All @@ -146,26 +144,27 @@ memo (optimized, ~4KB, required=[presentation: info:7] [distribution: test])
│ └── [presentation: info:7] [distribution: test]
│ ├── best: (explain G2="[distribution: test]" [distribution: test])
│ └── cost: 0.05
├── G2: (insert G3 G4 G5 p)
├── G2: (insert G3 G4 G5 G6 p)
│ ├── [distribution: test]
│ │ ├── best: (insert G3="[distribution: test]" G4 G5 p)
│ │ ├── best: (insert G3="[distribution: test]" G4 G5 G6 p)
│ │ └── cost: 0.03
│ └── []
│ ├── best: (insert G3 G4 G5 p)
│ ├── best: (insert G3 G4 G5 G6 p)
│ └── cost: 0.03
├── G3: (values G6 id=v1)
├── G3: (values G7 id=v1)
│ ├── [distribution: test]
│ │ ├── best: (values G6 id=v1)
│ │ ├── best: (values G7 id=v1)
│ │ └── cost: 0.02
│ └── []
│ ├── best: (values G6 id=v1)
│ ├── best: (values G7 id=v1)
│ └── cost: 0.02
├── G4: (unique-checks)
├── G5: (f-k-checks)
├── G6: (scalar-list G7)
├── G7: (tuple G8)
├── G8: (scalar-list G9 G9)
└── G9: (const ‹×›)
├── G5: (fast-path-unique-checks)
├── G6: (f-k-checks)
├── G7: (scalar-list G8)
├── G8: (tuple G9)
├── G9: (scalar-list G10 G10)
└── G10: (const ‹×›)
insert p
└── values
└── ‹(‹×›, ‹×›)›
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,54 +338,18 @@ EXPLAIN (VERBOSE) INSERT INTO t_unique_hash_pk (id, part) VALUES (4321, 'seattle
distribution: local
vectorized: true
·
• root
│ columns: ()
├── • insert
│ │ columns: ()
│ │ estimated row count: 0 (missing stats)
│ │ into: t_unique_hash_pk(crdb_internal_id_shard_16, id, part)
│ │
│ └── • values
│ columns: (crdb_internal_id_shard_16_comp, column1, column2, check1, check2)
│ size: 5 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 'seattle'
│ row 0, expr 2: 11
│ row 0, expr 3: true
│ row 0, expr 4: true
└── • constraint-check
└── • error if rows
│ columns: ()
└── • project
│ columns: (id)
└── • cross join (inner)
│ columns: (id, crdb_internal_id_shard_16, id, part)
│ estimated row count: 1 (missing stats)
├── • values
│ columns: (id)
│ size: 1 column, 1 row
│ row 0, expr 0: 4321
└── • limit
│ columns: (crdb_internal_id_shard_16, id, part)
│ count: 1
└── • filter
│ columns: (crdb_internal_id_shard_16, id, part)
│ estimated row count: 6 (missing stats)
│ filter: (crdb_internal_id_shard_16 != 11) OR (part != 'seattle')
└── • scan
columns: (crdb_internal_id_shard_16, id, part)
estimated row count: 0 (missing stats)
table: t_unique_hash_pk@t_unique_hash_pk_pkey
spans: /"new york"/11/4321/0 /"seattle"/11/4321/0
• insert fast path
columns: ()
estimated row count: 0 (missing stats)
into: t_unique_hash_pk(crdb_internal_id_shard_16, id, part)
auto commit
uniqueness check: t_unique_hash_pk@t_unique_hash_pk_pkey
size: 5 columns, 1 row
row 0, expr 0: 11
row 0, expr 1: 4321
row 0, expr 2: 'seattle'
row 0, expr 3: true
row 0, expr 4: true

query T
EXPLAIN (VERBOSE) INSERT INTO t_unique_hash_pk (id, part) VALUES (4321, 'seattle') ON CONFLICT DO NOTHING;
Expand Down Expand Up @@ -946,79 +910,20 @@ EXPLAIN (VERBOSE) INSERT INTO t_unique_hash_sec_key (id, email, part) VALUES (43
distribution: local
vectorized: true
·
• root
│ columns: ()
├── • insert
│ │ columns: ()
│ │ estimated row count: 0 (missing stats)
│ │ into: t_unique_hash_sec_key(id, email, part, crdb_internal_email_shard_16)
│ │
│ └── • values
│ columns: (column1, column2, column3, crdb_internal_email_shard_16_comp, check1, check2)
│ size: 6 columns, 1 row
│ row 0, expr 0: 4321
│ row 0, expr 1: 'some_email'
│ row 0, expr 2: 'seattle'
│ row 0, expr 3: 1
│ row 0, expr 4: true
│ row 0, expr 5: true
├── • constraint-check
│ │
│ └── • error if rows
│ │ columns: ()
│ │
│ └── • project
│ │ columns: (id)
│ │
│ └── • cross join (inner)
│ │ columns: (id, id, part)
│ │ estimated row count: 1 (missing stats)
│ │
│ ├── • values
│ │ columns: (id)
│ │ size: 1 column, 1 row
│ │ row 0, expr 0: 4321
│ │
│ └── • scan
│ columns: (id, part)
│ estimated row count: 1 (missing stats)
│ table: t_unique_hash_sec_key@t_unique_hash_sec_key_pkey
│ spans: /"new york"/4321/0
│ limit: 1
└── • constraint-check
└── • error if rows
│ columns: ()
└── • project
│ columns: (email)
└── • cross join (inner)
│ columns: (email, id, email, part)
│ estimated row count: 1 (missing stats)
├── • values
│ columns: (email)
│ size: 1 column, 1 row
│ row 0, expr 0: 'some_email'
└── • limit
│ columns: (id, email, part)
│ count: 1
└── • filter
│ columns: (id, email, part)
│ estimated row count: 6 (missing stats)
│ filter: (id != 4321) OR (part != 'seattle')
└── • scan
columns: (id, email, part)
estimated row count: 0 (missing stats)
table: t_unique_hash_sec_key@idx_uniq_hash_email
spans: /"new york"/1/"some_email"/0 /"seattle"/1/"some_email"/0
• insert fast path
columns: ()
estimated row count: 0 (missing stats)
into: t_unique_hash_sec_key(id, email, part, crdb_internal_email_shard_16)
auto commit
uniqueness check: t_unique_hash_sec_key@t_unique_hash_sec_key_pkey
uniqueness check: t_unique_hash_sec_key@idx_uniq_hash_email
size: 6 columns, 1 row
row 0, expr 0: 4321
row 0, expr 1: 'some_email'
row 0, expr 2: 'seattle'
row 0, expr 3: 1
row 0, expr 4: true
row 0, expr 5: true

query T
EXPLAIN (VERBOSE) INSERT INTO t_unique_hash_sec_key (id, email, part) VALUES (4321, 'some_email', 'seattle') ON CONFLICT DO NOTHING;
Expand Down
Loading