func (r *TableDefaultPlan) toSeekKey(seekVal interface{}) (kv.Key, error) { var handle int64 var err error if seekVal == nil { handle = math.MinInt64 } else { handle, err = types.ToInt64(seekVal) if err != nil { return nil, errors.Trace(err) } } return tables.EncodeRecordKey(r.T.TableID(), handle, 0), nil }
func (ts *testSuite) TestRowKeyCodec(c *C) { table := []struct { tableID int64 h int64 ID int64 }{ {1, 1234567890, 0}, {2, 1, 0}, {3, -1, 0}, {4, -1, 1}, } for _, t := range table { b := tables.EncodeRecordKey(t.tableID, t.h, t.ID) tableID, handle, columnID, err := tables.DecodeRecordKey(b) c.Assert(err, IsNil) c.Assert(tableID, Equals, t.tableID) c.Assert(handle, Equals, t.h) c.Assert(columnID, Equals, t.ID) handle, err = tables.DecodeRecordKeyHandle(b) c.Assert(err, IsNil) c.Assert(handle, Equals, t.h) } // test error tbl := []string{ "", "x", "t1", "t12345678", "t12345678_i", "t12345678_r1", "t12345678_r1234567", "t12345678_r123456781", } for _, t := range tbl { _, err := tables.DecodeRecordKeyHandle(kv.Key(t)) c.Assert(err, NotNil) } }
func (e *TableScanExec) seek() (kv.Key, error) { seekKey := tables.EncodeRecordKey(e.t.TableID(), e.seekHandle, 0) txn, err := e.ctx.GetTxn(false) if err != nil { return nil, errors.Trace(err) } if e.iter != nil { e.iter.Close() } e.iter, err = txn.Seek(seekKey) if err != nil { return nil, errors.Trace(err) } if !e.iter.Valid() || !e.iter.Key().HasPrefix(e.t.RecordPrefix()) { // No more records in the table, skip to the end. e.cursor = len(e.ranges) return nil, nil } return e.iter.Key(), nil }