Last active
March 30, 2016 17:18
-
-
Save tamird/cde74c6372b8610b11fa95bdd49af73b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/sql/errors.go b/sql/errors.go | |
index 8bf61c2..036e545 100644 | |
--- a/sql/errors.go | |
+++ b/sql/errors.go | |
@@ -150,11 +150,6 @@ func convertBatchError(tableDesc *TableDescriptor, b client.Batch, origPErr *roa | |
if err != nil { | |
return roachpb.NewError(err) | |
} | |
- if !index.Unique { | |
- // We can get what looks like a uniqueness violation on a | |
- // non-unique index because of a duplicate primary key. | |
- index = &tableDesc.PrimaryIndex | |
- } | |
valTypes, err := makeKeyVals(tableDesc, index.ColumnIDs) | |
if err != nil { | |
return roachpb.NewError(err) | |
diff --git a/sql/insert.go b/sql/insert.go | |
index afe8549..aca273d 100644 | |
--- a/sql/insert.go | |
+++ b/sql/insert.go | |
@@ -206,6 +206,15 @@ func (p *planner) Insert(n *parser.Insert, autoCommit bool) (planNode, *roachpb. | |
return nil, roachpb.NewError(eErr) | |
} | |
+ // Write the row sentinel. | |
+ sentinelKey := keys.MakeNonColumnKey(primaryIndexKey) | |
+ if log.V(2) { | |
+ log.Infof("CPut %s -> NULL", roachpb.Key(sentinelKey)) | |
+ } | |
+ // This is subtle: An interface{}(nil) deletes the value, so we pass in | |
+ // []byte{} as a non-nil value. | |
+ b.CPut(sentinelKey, []byte{}, nil) | |
+ | |
// Write the secondary indexes. | |
indexes := tableDesc.Indexes | |
// Also include the secondary indexes in mutation state WRITE_ONLY. | |
@@ -230,15 +239,6 @@ func (p *planner) Insert(n *parser.Insert, autoCommit bool) (planNode, *roachpb. | |
b.CPut(secondaryIndexEntry.key, secondaryIndexEntry.value, nil) | |
} | |
- // Write the row sentinel. | |
- sentinelKey := keys.MakeNonColumnKey(primaryIndexKey) | |
- if log.V(2) { | |
- log.Infof("CPut %s -> NULL", roachpb.Key(sentinelKey)) | |
- } | |
- // This is subtle: An interface{}(nil) deletes the value, so we pass in | |
- // []byte{} as a non-nil value. | |
- b.CPut(sentinelKey, []byte{}, nil) | |
- | |
// Write the row columns. | |
for i, val := range rowVals { | |
col := cols[i] | |
diff --git a/sql/testdata/insert b/sql/testdata/insert | |
index 795f296..4bb66db 100644 | |
--- a/sql/testdata/insert | |
+++ b/sql/testdata/insert | |
@@ -67,7 +67,7 @@ EXPLAIN (DEBUG) SELECT * FROM kv@a | |
8 /kv/a/'f' /'e' ROW | |
statement error pgcode 23505 duplicate key value \(v\)=\('f'\) violates unique constraint "a" | |
-INSERT INTO kv VALUES ('e', 'f') | |
+INSERT INTO kv VALUES ('h', 'f') | |
query ITTT | |
EXPLAIN (DEBUG) SELECT * FROM kv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment