diff --git a/ddl/ddl.go b/ddl/ddl.go index e78728dbdc3d3..7f97d133fec6b 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -498,13 +498,6 @@ func (d *ddl) WorkerVars() *variable.SessionVars { return d.workerVars } -func filterError(err, exceptErr error) error { - if terror.ErrorEqual(err, exceptErr) { - return nil - } - return errors.Trace(err) -} - // DDL error codes. const ( codeInvalidWorker terror.ErrCode = 1 diff --git a/distsql/distsql.go b/distsql/distsql.go index d53fba3c6f3ef..a7caea6912db8 100644 --- a/distsql/distsql.go +++ b/distsql/distsql.go @@ -244,11 +244,6 @@ func Analyze(ctx goctx.Context, client kv.Client, kvReq *kv.Request) (SelectResu return result, nil } -type resultWithErr struct { - result []byte - err error -} - // XAPI error codes. const ( codeInvalidResp = 1 diff --git a/executor/write.go b/executor/write.go index 7ac77bb189582..d356a01bb0b33 100644 --- a/executor/write.go +++ b/executor/write.go @@ -1171,18 +1171,6 @@ func (e *InsertExec) onDuplicateUpdate(row []types.Datum, h int64, cols []*expre return nil } -func findColumnByName(t table.Table, tableName, colName string) (*table.Column, error) { - if len(tableName) > 0 && !strings.EqualFold(tableName, t.Meta().Name.O) { - return nil, errors.Errorf("unknown field %s.%s", tableName, colName) - } - - c := table.FindCol(t.Cols(), colName) - if c == nil { - return nil, errors.Errorf("unknown field %s", colName) - } - return c, nil -} - // ReplaceExec represents a replace executor. type ReplaceExec struct { *InsertValues diff --git a/expression/expression.go b/expression/expression.go index 45062c4d7d6ed..d2e12b8e2174e 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -295,11 +295,6 @@ func TableInfo2SchemaWithDBName(dbName model.CIStr, tbl *model.TableInfo) *Schem return schema } -// ColumnInfos2Columns converts a slice of ColumnInfo to a slice of Column with empty DBName. -func ColumnInfos2Columns(tblName model.CIStr, colInfos []*model.ColumnInfo) []*Column { - return ColumnInfos2ColumnsWithDBName(model.CIStr{}, tblName, colInfos) -} - // ColumnInfos2ColumnsWithDBName converts a slice of ColumnInfo to a slice of Column. func ColumnInfos2ColumnsWithDBName(dbName, tblName model.CIStr, colInfos []*model.ColumnInfo) []*Column { columns := make([]*Column, 0, len(colInfos)) diff --git a/expression/util.go b/expression/util.go index 580f09a0ca8b0..d4a15838e1d5c 100644 --- a/expression/util.go +++ b/expression/util.go @@ -147,31 +147,6 @@ func SubstituteCorCol2Constant(expr Expression) (Expression, error) { return expr.Clone(), nil } -// ConvertCol2CorCol will convert the column in the condition which can be found in outerSchema to a correlated column whose -// Column is this column. And please make sure the outerSchema.Columns[i].Equal(corCols[i].Column)) holds when you call this. -func ConvertCol2CorCol(cond Expression, corCols []*CorrelatedColumn, outerSchema *Schema) Expression { - switch x := cond.(type) { - case *ScalarFunction: - newArgs := make([]Expression, 0, len(x.GetArgs())) - for _, arg := range x.GetArgs() { - newArg := ConvertCol2CorCol(arg, corCols, outerSchema) - newArgs = append(newArgs, newArg) - } - var newSf Expression - if x.FuncName.L == ast.Cast { - newSf = BuildCastFunction(x.GetCtx(), newArgs[0], x.RetType) - } else { - newSf = NewFunctionInternal(x.GetCtx(), x.FuncName.L, x.GetType(), newArgs...) - } - return newSf - case *Column: - if pos := outerSchema.ColumnIndex(x); pos >= 0 { - return corCols[pos] - } - } - return cond -} - // timeZone2Duration converts timezone whose format should satisfy the regular condition // `(^(+|-)(0?[0-9]|1[0-2]):[0-5]?\d$)|(^+13:00$)` to time.Duration. func timeZone2Duration(tz string) time.Duration { diff --git a/kv/mem_buffer_test.go b/kv/mem_buffer_test.go index 2ff09b0a17908..11befecf06640 100644 --- a/kv/mem_buffer_test.go +++ b/kv/mem_buffer_test.go @@ -118,14 +118,6 @@ func checkNewIterator(c *C, buffer MemBuffer) { iter.Close() } -func mustNotGet(c *C, buffer MemBuffer) { - for i := startIndex; i < testCount; i++ { - s := encodeInt(i * indexStep) - _, err := buffer.Get(s) - c.Assert(err, NotNil) - } -} - func mustGet(c *C, buffer MemBuffer) { for i := startIndex; i < testCount; i++ { s := encodeInt(i * indexStep) diff --git a/parser/misc.go b/parser/misc.go index 4e2c0b84bb464..1b26ca503b651 100644 --- a/parser/misc.go +++ b/parser/misc.go @@ -40,10 +40,6 @@ func isIdentFirstChar(ch rune) bool { return isLetter(ch) || ch == '_' } -func isASCII(ch rune) bool { - return ch >= 0 && ch <= 0177 -} - type trieNode struct { childs [256]*trieNode token int diff --git a/plan/logical_plan_test.go b/plan/logical_plan_test.go index b7031354c73fc..708a387bcfcc5 100644 --- a/plan/logical_plan_test.go +++ b/plan/logical_plan_test.go @@ -27,7 +27,6 @@ import ( "github.com/pingcap/tidb/mysql" "github.com/pingcap/tidb/parser" "github.com/pingcap/tidb/sessionctx" - "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/store/tikv/oracle" "github.com/pingcap/tidb/terror" "github.com/pingcap/tidb/util/mock" @@ -394,32 +393,6 @@ func mockContext() context.Context { return ctx } -func mockStatsTable(tbl *model.TableInfo, rowCount int64) *statistics.Table { - statsTbl := &statistics.Table{ - TableID: tbl.ID, - Count: rowCount, - Columns: make(map[int64]*statistics.Column, len(tbl.Columns)), - Indices: make(map[int64]*statistics.Index, len(tbl.Indices)), - } - return statsTbl -} - -// mockStatsHistogram will create a statistics.Histogram, of which the data is uniform distribution. -func mockStatsHistogram(id int64, values []types.Datum, repeat int64) *statistics.Histogram { - ndv := len(values) - histogram := &statistics.Histogram{ - ID: id, - NDV: int64(ndv), - Buckets: make([]statistics.Bucket, ndv), - } - for i := 0; i < ndv; i++ { - histogram.Buckets[i].Repeats = repeat - histogram.Buckets[i].Count = repeat * int64(i+1) - histogram.Buckets[i].UpperBound = values[i] - } - return histogram -} - func (s *testPlanSuite) TestPredicatePushDown(c *C) { defer testleak.AfterTest(c)() tests := []struct { diff --git a/server/util.go b/server/util.go index 4bcbc580f7e77..6a1e7c6944ccc 100644 --- a/server/util.go +++ b/server/util.go @@ -217,29 +217,6 @@ func dumpBinaryDateTime(t types.Time, loc *time.Location) (data []byte, err erro return } -func uniformValue(value interface{}) interface{} { - switch v := value.(type) { - case int8: - return int64(v) - case int16: - return int64(v) - case int32: - return int64(v) - case int64: - return v - case uint8: - return uint64(v) - case uint16: - return uint64(v) - case uint32: - return uint64(v) - case uint64: - return v - default: - return value - } -} - func dumpRowValuesBinary(buffer []byte, columns []*ColumnInfo, row []types.Datum) ([]byte, error) { if len(columns) != len(row) { return nil, mysql.ErrMalformPacket diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index d698cfd74db80..a3ea697e46aa8 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -489,13 +489,3 @@ func (sc *StatementContext) ResetForRetry() { sc.mu.warnings = nil sc.mu.Unlock() } - -// MostRestrictStateContext gets a most restrict StatementContext. -func MostRestrictStateContext() *StatementContext { - return &StatementContext{ - IgnoreTruncate: false, - OverflowAsWarning: false, - TruncateAsWarning: false, - TimeZone: time.UTC, - } -} diff --git a/store/tikv/kv.go b/store/tikv/kv.go index 16d12780e0249..9cf77f4c8b1e8 100644 --- a/store/tikv/kv.go +++ b/store/tikv/kv.go @@ -249,14 +249,6 @@ func WithHijackClient(wrap func(Client) Client) MockTiKVStoreOption { } } -// WithHijackPDClient hijacks PD client's behavior, makes it easy to simulate the network -// problem between TiDB and PD, such as GetTS too slow, GetStore or GetRegion fail. -func WithHijackPDClient(wrap func(pd.Client) pd.Client) MockTiKVStoreOption { - return func(c *mockOptions) { - c.pdClientHijack = wrap - } -} - // WithCluster provides the customized cluster. func WithCluster(cluster *mocktikv.Cluster) MockTiKVStoreOption { return func(c *mockOptions) { @@ -445,12 +437,6 @@ func (s *tikvStore) GetTiKVClient() (client Client) { return s.client } -// ParseEtcdAddr parses path to etcd address list -func ParseEtcdAddr(path string) (etcdAddrs []string, err error) { - etcdAddrs, _, err = parsePath(path) - return -} - func parsePath(path string) (etcdAddrs []string, disableGC bool, err error) { var u *url.URL u, err = url.Parse(path) diff --git a/store/tikv/region_cache.go b/store/tikv/region_cache.go index 6706c542b10f5..0ac36dc62b8df 100644 --- a/store/tikv/region_cache.go +++ b/store/tikv/region_cache.go @@ -483,17 +483,6 @@ func (c *RegionCache) PDClient() pd.Client { return c.pdClient } -// moveLeaderToFirst moves the leader peer to the first and makes it easier to -// try the next peer if the current peer does not respond. -func moveLeaderToFirst(r *metapb.Region, leaderStoreID uint64) { - for i := range r.Peers { - if r.Peers[i].GetStoreId() == leaderStoreID { - r.Peers[0], r.Peers[i] = r.Peers[i], r.Peers[0] - return - } - } -} - // llrbItem is llrbTree's Item that uses []byte to compare. type llrbItem struct { key []byte diff --git a/tablecodec/tablecodec.go b/tablecodec/tablecodec.go index 526b9d3dc53e7..29f409673fbfd 100644 --- a/tablecodec/tablecodec.go +++ b/tablecodec/tablecodec.go @@ -336,46 +336,6 @@ func CutRowNew(data []byte, colIDs map[int64]int) ([][]byte, error) { return row, nil } -// CutRow cuts encoded row into byte slices and return interested columns' byte slice. -// Row layout: colID1, value1, colID2, value2, ..... -func CutRow(data []byte, cols map[int64]*types.FieldType) (map[int64][]byte, error) { - if data == nil { - return nil, nil - } - if len(data) == 1 && data[0] == codec.NilFlag { - return nil, nil - } - row := make(map[int64][]byte, len(cols)) - cnt := 0 - var ( - b []byte - err error - ) - for len(data) > 0 && cnt < len(cols) { - // Get col id. - b, data, err = codec.CutOne(data) - if err != nil { - return nil, errors.Trace(err) - } - _, cid, err := codec.DecodeOne(b) - if err != nil { - return nil, errors.Trace(err) - } - // Get col value. - b, data, err = codec.CutOne(data) - if err != nil { - return nil, errors.Trace(err) - } - id := cid.GetInt64() - _, ok := cols[id] - if ok { - row[id] = b - cnt++ - } - } - return row, nil -} - // unflatten converts a raw datum to a column datum. func unflatten(datum types.Datum, ft *types.FieldType, loc *time.Location) (types.Datum, error) { if datum.IsNull() { @@ -443,12 +403,6 @@ func EncodeIndexSeekKey(tableID int64, idxID int64, encodedValue []byte) kv.Key return key } -// DecodeIndexKey decodes datums from an index key. -func DecodeIndexKey(key kv.Key) ([]types.Datum, error) { - b := key[prefixLen+idLen:] - return codec.Decode(b, 1) -} - // CutIndexKey cuts encoded index key into colIDs to bytes slices map. // The returned value b is the remaining bytes of the key which would be empty if it is unique index or handle data // if it is non-unique index. diff --git a/util/bytespool/bytespool.go b/util/bytespool/bytespool.go deleted file mode 100644 index 6ea46c2832810..0000000000000 --- a/util/bytespool/bytespool.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2017 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package bytespool - -import ( - "sync" -) - -// BytesPool maintains large bytes pools, used for reducing memory allocation. -// It has a slice of pools which handle different size of bytes. -// Can be safely used concurrently. -type BytesPool struct { - buckets []sync.Pool -} - -const ( - kilo = 1024 - mega = kilo * kilo - baseSize = kilo - numBuckets = 18 - maxSize = 128 * mega -) - -// DefaultPool is a default BytesBool instance. -var DefaultPool = NewBytesPool() - -// NewBytesPool creates a new bytes pool. -func NewBytesPool() *BytesPool { - bp := new(BytesPool) - bp.buckets = make([]sync.Pool, numBuckets) - for i := uint(0); i < numBuckets; i++ { - bp.buckets[i].New = makeNewFunc(i) - } - return bp -} - -func makeNewFunc(shift uint) func() interface{} { - return func() interface{} { - return make([]byte, baseSize< maxSize { - return nil, make([]byte, size) - } - i := bucketIdx(size) - origin = bp.buckets[i].Get().([]byte) - data = origin[:size] - return -} - -// Free frees the data which should be the original bytes return by Alloc. -// It returns the bucket index of the data. returns -1 means the data is not returned to the pool. -func (bp *BytesPool) Free(origin []byte) int { - originLen := len(origin) - if originLen > maxSize || originLen < baseSize || !isPowerOfTwo(originLen) { - return -1 - } - i := bucketIdx(originLen) - bp.buckets[i].Put(origin) - return i -} - -func isPowerOfTwo(x int) bool { - return x&(x-1) == 0 -} - -func bucketIdx(size int) (i int) { - for size > baseSize { - size = (size + 1) >> 1 - i++ - } - return -} diff --git a/util/bytespool/bytespool_test.go b/util/bytespool/bytespool_test.go deleted file mode 100644 index 4b638843d4ea4..0000000000000 --- a/util/bytespool/bytespool_test.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2017 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package bytespool - -import ( - "testing" - - . "github.com/pingcap/check" -) - -func TestT(t *testing.T) { - TestingT(t) -} - -var _ = Suite(&testBytesPoolSuite{}) - -type testBytesPoolSuite struct{} - -func (s *testBytesPoolSuite) TestBytesPool(c *C) { - poolTests := []struct { - size int - allocSize int - freeIdx int - }{ - {100, kilo, 0}, - {kilo, kilo, 0}, - {2 * kilo, 2 * kilo, 1}, - {8*kilo + 1, 16 * kilo, 4}, - {128 * mega, 128 * mega, 17}, - } - bp := NewBytesPool() - for _, tt := range poolTests { - origin, data := bp.Alloc(tt.size) - c.Assert(len(data), Equals, tt.size) - c.Assert(len(origin), Equals, tt.allocSize) - idx := bp.Free(origin) - c.Assert(idx, Equals, tt.freeIdx) - } - c.Assert(bp.Free(make([]byte, 100)), Equals, -1) - c.Assert(bp.Free(make([]byte, kilo+1)), Equals, -1) -} diff --git a/util/ranger/refiner.go b/util/ranger/refiner.go index 747bb9114fde3..4db9d96520a67 100644 --- a/util/ranger/refiner.go +++ b/util/ranger/refiner.go @@ -41,85 +41,6 @@ func FullIndexRange() []*types.IndexRange { return []*types.IndexRange{{LowVal: []types.Datum{{}}, HighVal: []types.Datum{types.MaxValueDatum()}}} } -// BuildIndexRange will build range of index for PhysicalIndexScan -func BuildIndexRange(sc *variable.StatementContext, tblInfo *model.TableInfo, index *model.IndexInfo, - accessInAndEqCount int, accessCondition []expression.Expression) ([]*types.IndexRange, error) { - rb := builder{sc: sc} - var ranges []*types.IndexRange - for i := 0; i < accessInAndEqCount; i++ { - // Build ranges for equal or in access conditions. - point := rb.build(accessCondition[i]) - colOff := index.Columns[i].Offset - tp := &tblInfo.Columns[colOff].FieldType - if i == 0 { - ranges = rb.buildIndexRanges(point, tp) - } else { - ranges = rb.appendIndexRanges(ranges, point, tp) - } - } - rangePoints := fullRange - // Build rangePoints for non-equal access conditions. - for i := accessInAndEqCount; i < len(accessCondition); i++ { - rangePoints = rb.intersection(rangePoints, rb.build(accessCondition[i])) - } - if accessInAndEqCount == 0 { - colOff := index.Columns[0].Offset - tp := &tblInfo.Columns[colOff].FieldType - ranges = rb.buildIndexRanges(rangePoints, tp) - } else if accessInAndEqCount < len(accessCondition) { - colOff := index.Columns[accessInAndEqCount].Offset - tp := &tblInfo.Columns[colOff].FieldType - ranges = rb.appendIndexRanges(ranges, rangePoints, tp) - } - - // Take prefix index into consideration. - if index.HasPrefixIndex() { - for i := 0; i < len(ranges); i++ { - refineRange(ranges[i], index) - } - } - - if len(ranges) > 0 && len(ranges[0].LowVal) < len(index.Columns) { - for _, ran := range ranges { - if ran.HighExclude || ran.LowExclude { - if ran.HighExclude { - ran.HighVal = append(ran.HighVal, types.NewDatum(nil)) - } else { - ran.HighVal = append(ran.HighVal, types.MaxValueDatum()) - } - if ran.LowExclude { - ran.LowVal = append(ran.LowVal, types.MaxValueDatum()) - } else { - ran.LowVal = append(ran.LowVal, types.NewDatum(nil)) - } - } - } - } - return ranges, errors.Trace(rb.err) -} - -// refineRange changes the IndexRange taking prefix index length into consideration. -func refineRange(v *types.IndexRange, idxInfo *model.IndexInfo) { - for i := 0; i < len(v.LowVal); i++ { - refineRangeDatum(&v.LowVal[i], idxInfo.Columns[i]) - v.LowExclude = false - } - - for i := 0; i < len(v.HighVal); i++ { - refineRangeDatum(&v.HighVal[i], idxInfo.Columns[i]) - v.HighExclude = false - } -} - -func refineRangeDatum(v *types.Datum, ic *model.IndexColumn) { - if ic.Length != types.UnspecifiedLength { - // if index prefix length is used, change scan range. - if ic.Length < len(v.GetBytes()) { - v.SetBytes(v.GetBytes()[:ic.Length]) - } - } -} - // getEQFunctionOffset judge if the expression is a eq function like A = 1 where a is an index. // If so, it will return the offset of A in index columns. e.g. for index(C,B,A), A's offset is 2. func getEQFunctionOffset(expr expression.Expression, cols []*model.IndexColumn) int { @@ -202,65 +123,6 @@ func DetachIndexFilterConditions(conditions []expression.Expression, indexColumn return indexConditions, tableConditions } -// DetachIndexScanConditions will detach the index filters from table filters. -func DetachIndexScanConditions(conditions []expression.Expression, index *model.IndexInfo) (accessConds []expression.Expression, - filterConds []expression.Expression, accessEqualCount int, accessInAndEqCount int) { - accessConds = make([]expression.Expression, len(index.Columns)) - // PushDownNot here can convert query 'not (a != 1)' to 'a = 1'. - for i, cond := range conditions { - conditions[i] = expression.PushDownNot(cond, false, nil) - } - for _, cond := range conditions { - offset := getEQFunctionOffset(cond, index.Columns) - if offset != -1 { - accessConds[offset] = cond - } - } - for i, cond := range accessConds { - if cond == nil { - accessConds = accessConds[:i] - accessEqualCount = i - break - } - if index.Columns[i].Length != types.UnspecifiedLength { - filterConds = append(filterConds, cond) - } - if i == len(accessConds)-1 { - accessEqualCount = len(accessConds) - } - } - accessInAndEqCount = accessEqualCount - // We should remove all accessConds, so that they will not be added to filter conditions. - conditions = removeAccessConditions(conditions, accessConds) - var curIndex int - for curIndex = accessEqualCount; curIndex < len(index.Columns); curIndex++ { - checker := &conditionChecker{ - idx: index, - columnOffset: curIndex, - length: index.Columns[curIndex].Length, - } - // First of all, we should extract all of in/eq expressions from rest conditions for every continuous index column. - // e.g. For index (a,b,c) and conditions a in (1,2) and b < 1 and c in (3,4), we should only extract column a in (1,2). - accessIdx := checker.findEqOrInFunc(conditions) - // If we fail to find any in or eq expression, we should consider all of other conditions for the next column. - if accessIdx == -1 { - accessConds, filterConds = checker.extractAccessAndFilterConds(conditions, accessConds, filterConds) - break - } - accessInAndEqCount++ - accessConds = append(accessConds, conditions[accessIdx]) - if index.Columns[curIndex].Length != types.UnspecifiedLength { - filterConds = append(filterConds, conditions[accessIdx]) - } - conditions = append(conditions[:accessIdx], conditions[accessIdx+1:]...) - } - // If curIndex equals to len of index columns, it means the rest conditions haven't been appended to filter conditions. - if curIndex == len(index.Columns) { - filterConds = append(filterConds, conditions...) - } - return accessConds, filterConds, accessEqualCount, accessInAndEqCount -} - // DetachColumnConditions distinguishes between access conditions and filter conditions from conditions. func DetachColumnConditions(conditions []expression.Expression, colName model.CIStr) ([]expression.Expression, []expression.Expression) { if colName.L == "" { diff --git a/util/segmentmap/segmentmap.go b/util/segmentmap/segmentmap.go deleted file mode 100644 index 26b931427f666..0000000000000 --- a/util/segmentmap/segmentmap.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package segmentmap - -import ( - "hash/crc32" - - "github.com/juju/errors" -) - -// SegmentMap is used for handle a big map slice by slice. -// It's not thread safe. -type SegmentMap struct { - size int64 - maps []map[string]interface{} - - crcTable *crc32.Table -} - -// NewSegmentMap creates a new SegmentMap. -func NewSegmentMap(size int64) (*SegmentMap, error) { - if size <= 0 { - return nil, errors.Errorf("Invalid size: %d", size) - } - - sm := &SegmentMap{ - maps: make([]map[string]interface{}, size), - size: size, - } - for i := int64(0); i < size; i++ { - sm.maps[i] = make(map[string]interface{}) - } - - sm.crcTable = crc32.MakeTable(crc32.Castagnoli) - return sm, nil -} - -// Get is the same as map[k]. -func (sm *SegmentMap) Get(key []byte) (interface{}, bool) { - idx := int64(crc32.Checksum(key, sm.crcTable)) % sm.size - val, ok := sm.maps[idx][string(key)] - return val, ok -} - -// GetSegment gets the map specific by index. -func (sm *SegmentMap) GetSegment(index int64) (map[string]interface{}, error) { - if index >= sm.size || index < 0 { - return nil, errors.Errorf("index out of bound: %d", index) - } - - return sm.maps[index], nil -} - -// Set if key not exists, returns whether already exists. -func (sm *SegmentMap) Set(key []byte, value interface{}, force bool) bool { - idx := int64(crc32.Checksum(key, sm.crcTable)) % sm.size - k := string(key) - _, exist := sm.maps[idx][k] - if exist && !force { - return exist - } - - sm.maps[idx][k] = value - return exist -} - -// SegmentCount returns how many inner segments. -func (sm *SegmentMap) SegmentCount() int64 { - return sm.size -} diff --git a/util/segmentmap/segmentmap_test.go b/util/segmentmap/segmentmap_test.go deleted file mode 100644 index e79b4c845d7ae..0000000000000 --- a/util/segmentmap/segmentmap_test.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// See the License for the specific language governing permissions and -// limitations under the License. - -package segmentmap - -import ( - "testing" - - . "github.com/pingcap/check" - "github.com/pingcap/tidb/util/testleak" -) - -func TestT(t *testing.T) { - TestingT(t) -} - -var _ = Suite(&testSegmentMapSuite{}) - -type testSegmentMapSuite struct { -} - -func (s *testSegmentMapSuite) TestSegment(c *C) { - defer testleak.AfterTest(c)() - segs := int64(2) - m, err := NewSegmentMap(segs) - c.Assert(err, IsNil) - c.Assert(m.SegmentCount(), Equals, segs) - k := []byte("k") - v := []byte("v") - val, exist := m.Get(k) - c.Assert(exist, IsFalse) - - exist = m.Set(k, v, false) - c.Assert(exist, IsFalse) - - val, exist = m.Get(k) - c.Assert(v, DeepEquals, val.([]byte)) - c.Assert(exist, IsTrue) - - m0, err := m.GetSegment(0) - c.Assert(err, IsNil) - - m1, err := m.GetSegment(1) - c.Assert(err, IsNil) - - c.Assert(len(m0)+len(m1), Equals, 1) - - _, err = m.GetSegment(3) - c.Assert(err, NotNil) -} diff --git a/util/types/etc.go b/util/types/etc.go index aa79007667937..ff3e4a62b2776 100644 --- a/util/types/etc.go +++ b/util/types/etc.go @@ -50,11 +50,6 @@ func IsTypeVarchar(tp byte) bool { return tp == mysql.TypeVarString || tp == mysql.TypeVarchar } -// IsTypeJSON returns a boolean indicating whether the tp is the JSON type. -func IsTypeJSON(tp byte) bool { - return tp == mysql.TypeJSON -} - // IsTypeUnspecified returns a boolean indicating whether the tp is the Unspecified type. func IsTypeUnspecified(tp byte) bool { return tp == mysql.TypeUnspecified