Skip to content

Commit

Permalink
Merge pull request #8274 from dolthub/fulghum/dolt-8254
Browse files Browse the repository at this point in the history
Allow duplicate indexes, to match MySQL behavior
  • Loading branch information
fulghum authored Aug 16, 2024
2 parents cc54f22 + 12da95e commit 7309db0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 41 deletions.
2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0
github.com/creasty/defaults v1.6.0
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-mysql-server v0.18.2-0.20240815142344-761713e36043
github.com/dolthub/go-mysql-server v0.18.2-0.20240816004605-0fd0947fb3d8
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63
github.com/dolthub/swiss v0.1.0
github.com/goccy/go-json v0.10.2
Expand Down
4 changes: 2 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.18.2-0.20240815142344-761713e36043 h1:KgrDVE4o4Y04XLnAs5BGv6I6z+Rd82FWntCbQEmbTKs=
github.com/dolthub/go-mysql-server v0.18.2-0.20240815142344-761713e36043/go.mod h1:nbdOzd0ceWONE80vbfwoRBjut7z3CIj69ZgDF/cKuaA=
github.com/dolthub/go-mysql-server v0.18.2-0.20240816004605-0fd0947fb3d8 h1:IMlS4ycXRhjRmYTgXCLX1jVSzeKlPCUpO5RHREzbCKY=
github.com/dolthub/go-mysql-server v0.18.2-0.20240816004605-0fd0947fb3d8/go.mod h1:nbdOzd0ceWONE80vbfwoRBjut7z3CIj69ZgDF/cKuaA=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand Down
6 changes: 1 addition & 5 deletions go/libraries/doltcore/schema/index_coll.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type IndexCollection interface {
Equals(other IndexCollection) bool
// GetByName returns the index with the given name, or nil if it does not exist.
GetByName(indexName string) Index
// GetByName returns the index with a matching case-insensitive name, the bool return value indicates if a match was found.
// GetByNameCaseInsensitive returns the index with a matching case-insensitive name, the bool return value indicates if a match was found.
GetByNameCaseInsensitive(indexName string) (Index, bool)
// GetIndexByColumnNames returns whether the collection contains an index that has this exact collection and ordering of columns.
GetIndexByColumnNames(cols ...string) (Index, bool)
Expand Down Expand Up @@ -173,10 +173,6 @@ func (ixc *indexCollectionImpl) AddIndex(indexes ...Index) {
if ok {
ixc.removeIndex(oldNamedIndex)
}
oldTaggedIndex := ixc.containsColumnTagCollection(index.tags...)
if oldTaggedIndex != nil {
ixc.removeIndex(oldTaggedIndex)
}
ixc.indexes[lowerName] = index
for _, tag := range index.tags {
ixc.colTagToIndex[tag] = append(ixc.colTagToIndex[tag], index)
Expand Down
40 changes: 7 additions & 33 deletions go/libraries/doltcore/schema/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,56 +84,30 @@ func TestIndexCollectionAddIndex(t *testing.T) {
indexColl.clear(t)
}

const prefix = "new_"

t.Run("Tag Overwrites", func(t *testing.T) {
t.Run("Duplicate column set", func(t *testing.T) {
for _, testIndex := range testIndexes {
indexColl.AddIndex(testIndex)
newIndex := testIndex.copy()
newIndex.name = prefix + testIndex.name
newIndex.name = "dupe_" + testIndex.name
indexColl.AddIndex(newIndex)
assert.Equal(t, newIndex, indexColl.GetByName(newIndex.Name()))
assert.Nil(t, indexColl.GetByName(testIndex.Name()))
assert.Equal(t, testIndex, indexColl.GetByName(testIndex.Name()))
assert.Contains(t, indexColl.AllIndexes(), newIndex)
assert.NotContains(t, indexColl.AllIndexes(), testIndex)
assert.Contains(t, indexColl.AllIndexes(), testIndex)
for _, tag := range newIndex.IndexedColumnTags() {
assert.Contains(t, indexColl.IndexesWithTag(tag), newIndex)
assert.NotContains(t, indexColl.IndexesWithTag(tag), testIndex)
assert.Contains(t, indexColl.IndexesWithTag(tag), testIndex)
}
for _, col := range newIndex.ColumnNames() {
assert.Contains(t, indexColl.IndexesWithColumn(col), newIndex)
assert.NotContains(t, indexColl.IndexesWithColumn(col), testIndex)
assert.Contains(t, indexColl.IndexesWithColumn(col), testIndex)
}
assert.True(t, indexColl.Contains(newIndex.Name()))
assert.False(t, indexColl.Contains(testIndex.Name()))
assert.True(t, indexColl.Contains(testIndex.Name()))
assert.True(t, indexColl.hasIndexOnColumns(newIndex.ColumnNames()...))
assert.True(t, indexColl.hasIndexOnTags(newIndex.IndexedColumnTags()...))
}
})

t.Run("Name Overwrites", func(t *testing.T) {
// should be able to reduce collection to one index
lastStanding := &indexImpl{
name: "none",
tags: []uint64{4},
allTags: []uint64{4, 1, 2},
indexColl: indexColl,
}

for _, testIndex := range testIndexes {
lastStanding.name = prefix + testIndex.name
indexColl.AddIndex(lastStanding)
}

assert.Equal(t, map[string]*indexImpl{lastStanding.name: lastStanding}, indexColl.indexes)
for tag, indexes := range indexColl.colTagToIndex {
if tag == 4 {
assert.Equal(t, indexes, []*indexImpl{lastStanding})
} else {
assert.Empty(t, indexes)
}
}
})
}

func TestIndexCollectionAddIndexByColNames(t *testing.T) {
Expand Down

0 comments on commit 7309db0

Please sign in to comment.