Skip to content

Commit 7309db0

Browse files
authored
Merge pull request #8274 from dolthub/fulghum/dolt-8254
Allow duplicate indexes, to match MySQL behavior
2 parents cc54f22 + 12da95e commit 7309db0

File tree

4 files changed

+11
-41
lines changed

4 files changed

+11
-41
lines changed

Diff for: go/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ require (
5757
github.com/cespare/xxhash/v2 v2.2.0
5858
github.com/creasty/defaults v1.6.0
5959
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
60-
github.com/dolthub/go-mysql-server v0.18.2-0.20240815142344-761713e36043
60+
github.com/dolthub/go-mysql-server v0.18.2-0.20240816004605-0fd0947fb3d8
6161
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63
6262
github.com/dolthub/swiss v0.1.0
6363
github.com/goccy/go-json v0.10.2

Diff for: go/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
183183
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
184184
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
185185
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
186-
github.com/dolthub/go-mysql-server v0.18.2-0.20240815142344-761713e36043 h1:KgrDVE4o4Y04XLnAs5BGv6I6z+Rd82FWntCbQEmbTKs=
187-
github.com/dolthub/go-mysql-server v0.18.2-0.20240815142344-761713e36043/go.mod h1:nbdOzd0ceWONE80vbfwoRBjut7z3CIj69ZgDF/cKuaA=
186+
github.com/dolthub/go-mysql-server v0.18.2-0.20240816004605-0fd0947fb3d8 h1:IMlS4ycXRhjRmYTgXCLX1jVSzeKlPCUpO5RHREzbCKY=
187+
github.com/dolthub/go-mysql-server v0.18.2-0.20240816004605-0fd0947fb3d8/go.mod h1:nbdOzd0ceWONE80vbfwoRBjut7z3CIj69ZgDF/cKuaA=
188188
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
189189
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
190190
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=

Diff for: go/libraries/doltcore/schema/index_coll.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type IndexCollection interface {
4141
Equals(other IndexCollection) bool
4242
// GetByName returns the index with the given name, or nil if it does not exist.
4343
GetByName(indexName string) Index
44-
// GetByName returns the index with a matching case-insensitive name, the bool return value indicates if a match was found.
44+
// GetByNameCaseInsensitive returns the index with a matching case-insensitive name, the bool return value indicates if a match was found.
4545
GetByNameCaseInsensitive(indexName string) (Index, bool)
4646
// GetIndexByColumnNames returns whether the collection contains an index that has this exact collection and ordering of columns.
4747
GetIndexByColumnNames(cols ...string) (Index, bool)
@@ -173,10 +173,6 @@ func (ixc *indexCollectionImpl) AddIndex(indexes ...Index) {
173173
if ok {
174174
ixc.removeIndex(oldNamedIndex)
175175
}
176-
oldTaggedIndex := ixc.containsColumnTagCollection(index.tags...)
177-
if oldTaggedIndex != nil {
178-
ixc.removeIndex(oldTaggedIndex)
179-
}
180176
ixc.indexes[lowerName] = index
181177
for _, tag := range index.tags {
182178
ixc.colTagToIndex[tag] = append(ixc.colTagToIndex[tag], index)

Diff for: go/libraries/doltcore/schema/index_test.go

+7-33
Original file line numberDiff line numberDiff line change
@@ -84,56 +84,30 @@ func TestIndexCollectionAddIndex(t *testing.T) {
8484
indexColl.clear(t)
8585
}
8686

87-
const prefix = "new_"
88-
89-
t.Run("Tag Overwrites", func(t *testing.T) {
87+
t.Run("Duplicate column set", func(t *testing.T) {
9088
for _, testIndex := range testIndexes {
9189
indexColl.AddIndex(testIndex)
9290
newIndex := testIndex.copy()
93-
newIndex.name = prefix + testIndex.name
91+
newIndex.name = "dupe_" + testIndex.name
9492
indexColl.AddIndex(newIndex)
9593
assert.Equal(t, newIndex, indexColl.GetByName(newIndex.Name()))
96-
assert.Nil(t, indexColl.GetByName(testIndex.Name()))
94+
assert.Equal(t, testIndex, indexColl.GetByName(testIndex.Name()))
9795
assert.Contains(t, indexColl.AllIndexes(), newIndex)
98-
assert.NotContains(t, indexColl.AllIndexes(), testIndex)
96+
assert.Contains(t, indexColl.AllIndexes(), testIndex)
9997
for _, tag := range newIndex.IndexedColumnTags() {
10098
assert.Contains(t, indexColl.IndexesWithTag(tag), newIndex)
101-
assert.NotContains(t, indexColl.IndexesWithTag(tag), testIndex)
99+
assert.Contains(t, indexColl.IndexesWithTag(tag), testIndex)
102100
}
103101
for _, col := range newIndex.ColumnNames() {
104102
assert.Contains(t, indexColl.IndexesWithColumn(col), newIndex)
105-
assert.NotContains(t, indexColl.IndexesWithColumn(col), testIndex)
103+
assert.Contains(t, indexColl.IndexesWithColumn(col), testIndex)
106104
}
107105
assert.True(t, indexColl.Contains(newIndex.Name()))
108-
assert.False(t, indexColl.Contains(testIndex.Name()))
106+
assert.True(t, indexColl.Contains(testIndex.Name()))
109107
assert.True(t, indexColl.hasIndexOnColumns(newIndex.ColumnNames()...))
110108
assert.True(t, indexColl.hasIndexOnTags(newIndex.IndexedColumnTags()...))
111109
}
112110
})
113-
114-
t.Run("Name Overwrites", func(t *testing.T) {
115-
// should be able to reduce collection to one index
116-
lastStanding := &indexImpl{
117-
name: "none",
118-
tags: []uint64{4},
119-
allTags: []uint64{4, 1, 2},
120-
indexColl: indexColl,
121-
}
122-
123-
for _, testIndex := range testIndexes {
124-
lastStanding.name = prefix + testIndex.name
125-
indexColl.AddIndex(lastStanding)
126-
}
127-
128-
assert.Equal(t, map[string]*indexImpl{lastStanding.name: lastStanding}, indexColl.indexes)
129-
for tag, indexes := range indexColl.colTagToIndex {
130-
if tag == 4 {
131-
assert.Equal(t, indexes, []*indexImpl{lastStanding})
132-
} else {
133-
assert.Empty(t, indexes)
134-
}
135-
}
136-
})
137111
}
138112

139113
func TestIndexCollectionAddIndexByColNames(t *testing.T) {

0 commit comments

Comments
 (0)