示例#1
0
文件: from.go 项目: lovedboy/tidb
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
}
示例#2
0
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)
	}
}
示例#3
0
文件: executor.go 项目: lovedboy/tidb
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
}