diff --git a/go/go.mod b/go/go.mod index a2286638701..ffe1c303bc7 100644 --- a/go/go.mod +++ b/go/go.mod @@ -14,7 +14,7 @@ require ( github.com/dolthub/fslock v0.0.3 github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20250604183723-cad71bbe21d0 + github.com/dolthub/vitess v0.0.0-20250605180032-fa2a634c215b github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.13.0 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 @@ -60,7 +60,7 @@ require ( github.com/creasty/defaults v1.6.0 github.com/dolthub/aws-sdk-go-ini-parser v0.0.0-20250305001723-2821c37f6c12 github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 - github.com/dolthub/go-mysql-server v0.20.1-0.20250605002725-764333d46138 + github.com/dolthub/go-mysql-server v0.20.1-0.20250605200234-fd7fc07710bd github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 github.com/esote/minmaxheap v1.0.0 github.com/goccy/go-json v0.10.2 diff --git a/go/go.sum b/go/go.sum index 515b0c2178d..56c969fb708 100644 --- a/go/go.sum +++ b/go/go.sum @@ -221,8 +221,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-20250327004329-6799764f2dad h1:66ZPawHszNu37VPQckdhX1BPPVzREsGgNxQeefnlm3g= github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA= -github.com/dolthub/go-mysql-server v0.20.1-0.20250605002725-764333d46138 h1:4faHz/ZmRNE1/FtXjSsyvhb61aaEP9UCOmRwTG1QabA= -github.com/dolthub/go-mysql-server v0.20.1-0.20250605002725-764333d46138/go.mod h1:ERCbQEjnhGhFH6+R5wJ1lVFqWb9f9+wvMxYHYlYtf2k= +github.com/dolthub/go-mysql-server v0.20.1-0.20250605200234-fd7fc07710bd h1:W0WYb9pVn0SFt+3j8oGTPknHDaYURSGrjfSp5Ob5HDM= +github.com/dolthub/go-mysql-server v0.20.1-0.20250605200234-fd7fc07710bd/go.mod h1:Tm4/+ez/jrtIv/rkrOc6C7zKoaAo5Rppj8Qa9DuTGo4= 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= @@ -231,8 +231,8 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= -github.com/dolthub/vitess v0.0.0-20250604183723-cad71bbe21d0 h1:esaEESlRNds2thjx9mEiDRIp1Cm5nM9K2PbYqPKei5Q= -github.com/dolthub/vitess v0.0.0-20250604183723-cad71bbe21d0/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70= +github.com/dolthub/vitess v0.0.0-20250605180032-fa2a634c215b h1:rgZXgRYZ3SZbb4Tz5Y6vnzvB7P9pFvEP+Q7UGfRC9uY= +github.com/dolthub/vitess v0.0.0-20250605180032-fa2a634c215b/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= diff --git a/go/libraries/doltcore/schema/index_coll.go b/go/libraries/doltcore/schema/index_coll.go index 8d4b0537c72..40e76dc2a8e 100644 --- a/go/libraries/doltcore/schema/index_coll.go +++ b/go/libraries/doltcore/schema/index_coll.go @@ -19,6 +19,7 @@ import ( "sort" "strings" + "github.com/dolthub/go-mysql-server/sql" "github.com/dolthub/go-mysql-server/sql/expression/function/vector" ) @@ -133,23 +134,26 @@ func NewIndexCollection(cols *ColCollection, pkCols *ColCollection) IndexCollect return ixc } -func (ixc indexCollectionImpl) Copy() IndexCollection { +func (ixc *indexCollectionImpl) Copy() IndexCollection { + // no need to copy the colColl, it's immutable + nixc := &indexCollectionImpl{ + colColl: ixc.colColl, + } + if ixc.pks != nil { - pks := make([]uint64, len(ixc.pks)) - copy(pks, ixc.pks) - ixc.pks = pks + nixc.pks = make([]uint64, len(ixc.pks)) + copy(nixc.pks, ixc.pks) } if ixc.indexes != nil { - indexes := make(map[string]*indexImpl, len(ixc.indexes)) + nixc.indexes = make(map[string]*indexImpl, len(ixc.indexes)) for name, index := range ixc.indexes { - indexes[name] = index.copy() + nixc.indexes[name] = index.copy() } - ixc.indexes = indexes } if ixc.colTagToIndex != nil { - colTagToIndex := make(map[uint64][]*indexImpl, len(ixc.colTagToIndex)) + nixc.colTagToIndex = make(map[uint64][]*indexImpl, len(ixc.colTagToIndex)) for tag, indexes := range ixc.colTagToIndex { var indexesCopy []*indexImpl if indexes != nil { @@ -158,13 +162,11 @@ func (ixc indexCollectionImpl) Copy() IndexCollection { indexesCopy[i] = index.copy() } } - colTagToIndex[tag] = indexesCopy + nixc.colTagToIndex[tag] = indexesCopy } - ixc.colTagToIndex = colTagToIndex } - // no need to copy the colColl, it's immutable - return &ixc + return nixc } func (ixc *indexCollectionImpl) AddIndex(indexes ...Index) { @@ -202,7 +204,7 @@ func (ixc *indexCollectionImpl) AddIndexByColTags(indexName string, tags []uint6 return nil, fmt.Errorf("indexes cannot be prefixed with `dolt_`") } if ixc.Contains(lowerName) { - return nil, fmt.Errorf("`%s` already exists as an index for this table", lowerName) + return nil, sql.ErrDuplicateKey.New(lowerName) } if !ixc.tagsExist(tags...) { return nil, fmt.Errorf("tags %v do not exist on this table", tags) @@ -454,7 +456,7 @@ func (ixc *indexCollectionImpl) Merge(indexes ...Index) { func (ixc *indexCollectionImpl) RemoveIndex(indexName string) (Index, error) { lowerName := strings.ToLower(indexName) if !ixc.Contains(lowerName) { - return nil, fmt.Errorf("`%s` does not exist as an index for this table", lowerName) + return nil, sql.ErrIndexNotFound.New(indexName) } index := ixc.indexes[lowerName] delete(ixc.indexes, lowerName) @@ -473,12 +475,11 @@ func (ixc *indexCollectionImpl) RemoveIndex(indexName string) (Index, error) { func (ixc *indexCollectionImpl) RenameIndex(oldName, newName string) (Index, error) { lowerCaseOldName := strings.ToLower(oldName) lowerCaseNewName := strings.ToLower(newName) - if !ixc.Contains(lowerCaseOldName) { - return nil, fmt.Errorf("`%s` does not exist as an index for this table", oldName) + return nil, sql.ErrIndexNotFound.New(oldName) } if ixc.Contains(lowerCaseNewName) { - return nil, fmt.Errorf("`%s` already exists as an index for this table", newName) + return nil, sql.ErrDuplicateKey.New(newName) } index := ixc.indexes[lowerCaseOldName] delete(ixc.indexes, lowerCaseOldName)