-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds ForcePut mode to indexes in which all writes are handled via Put, even in cases where they would typically used CPut or InitPut. This change is in support of the mvcc-compatible index backfiller. As part of the backfill process, newly added indexes will be added in a BACKFILLING state in which they see no writes or deletes. However, this would allow for the following sequence of events: t0: `CREATE INDEX` creates "new index" in BACKFILLING state t1: `INSERT INTO` with a = 1 (new index does not see this write) t2: Backfill starts at t1 (a=1 included in backfill, ends up in "new index") t3: UPDATE a = 2 where a = 1 (new index still in backfilling does not see these writes) t4: Backfilling completes t5: "new index" to DELETE-ONLY t6: "new index" to DELETE-AND-WRITE-ONLY t7: `INSERT INTO` into with a = 1 At t7, the user would encounter an erroneous duplicate key violation when they attempt their insert because the attempted CPut into "new index" would fail as there is an existing value (a=1). The ForcePut mode solves this case. While use of this option would be unsafe in general because it allows for writes that violate the unique constraint on the index. However, when used as part of the index backfilling process it should be safe because indexes are checked for uniqueness before being made public. The tests added here are nearly identical to the tests added for DeletePreservingEncoding. Release note: None
- Loading branch information
1 parent
4a73be0
commit 50e05a9
Showing
10 changed files
with
416 additions
and
26 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# LogicTest: local !metamorphic | ||
|
||
# --------------------------------------------------------- | ||
# Ensure ForcePut indexes forces Puts even on unique indexes. | ||
# --------------------------------------------------------- | ||
statement ok | ||
CREATE TABLE ti ( | ||
a INT PRIMARY KEY, | ||
b INT, | ||
FAMILY (a, b), | ||
UNIQUE INDEX (b) | ||
); | ||
|
||
let $t_id | ||
SELECT id FROM system.namespace WHERE name = 'ti' | ||
|
||
let $updated_t_jsonb | ||
WITH | ||
descs | ||
AS ( | ||
SELECT | ||
id, | ||
crdb_internal.pb_to_json( | ||
'cockroach.sql.sqlbase.Descriptor', | ||
descriptor | ||
) | ||
AS descriptor | ||
FROM | ||
system.descriptor | ||
) | ||
SELECT | ||
CAST (json_set(descriptor, ARRAY['table', 'indexes', '0', 'forcePut'], 'true') AS STRING) | ||
FROM | ||
descs WHERE id = $t_id; | ||
|
||
statement ok | ||
SELECT * FROM crdb_internal.unsafe_upsert_descriptor($t_id, crdb_internal.json_to_pb('cockroach.sql.sqlbase.Descriptor',$$ $updated_t_jsonb $$), true) | ||
|
||
statement ok | ||
INSERT INTO ti VALUES (1, 1), (2, 2) | ||
|
||
# Test that it's okay to insert into the unique | ||
# force put index. | ||
query T kvtrace | ||
INSERT INTO ti VALUES (3, 1) | ||
---- | ||
CPut /Table/56/1/3/0 -> /TUPLE/2:2:Int/1 | ||
Put /Table/56/2/1/0 -> /BYTES/0x8b | ||
|
||
# Test that Put's triggered but update that should fail, continue to | ||
# work. | ||
statement ok | ||
INSERT INTO ti VALUES (4, 4) | ||
|
||
query T kvtrace | ||
UPDATE ti SET b = 2 WHERE a = 4 | ||
---- | ||
Scan /Table/56/1/4/0 | ||
Put /Table/56/1/4/0 -> /TUPLE/2:2:Int/2 | ||
Del /Table/56/2/4/0 | ||
Put /Table/56/2/2/0 -> /BYTES/0x8c |
12 changes: 6 additions & 6 deletions
12
pkg/sql/opt/exec/execbuilder/testdata/show_trace_nonmetamorphic
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.