Skip to content

Commit

Permalink
*: refactor index, use TableInfo and IndexInfo to create an Index (pi…
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored Jun 21, 2016
1 parent 17af1cd commit dd6bfac
Show file tree
Hide file tree
Showing 19 changed files with 238 additions and 212 deletions.
19 changes: 9 additions & 10 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,21 @@ LOOP:
c.Assert(err, IsNil)

// check in index
var nidx *table.IndexedColumn
var nidx table.Index
for _, tidx := range t.Indices() {
if tidx.Name.L == "c3_index" {
if tidx.Meta().Name.L == "c3_index" {
nidx = tidx
break
}
}
// Make sure there is index with name c3_index
c.Assert(nidx, NotNil)
c.Assert(nidx.ID, Greater, int64(0))
idx := tables.NewIndex(t.IndexPrefix(), "c3_index", nidx.ID, false)
c.Assert(nidx.Meta().ID, Greater, int64(0))
txn, err := ctx.GetTxn(true)
c.Assert(err, IsNil)
defer ctx.RollbackTxn()

it, err := idx.SeekFirst(txn)
it, err := nidx.SeekFirst(txn)
c.Assert(err, IsNil)
defer it.Close()

Expand Down Expand Up @@ -229,9 +228,9 @@ func (s *testDBSuite) testDropIndex(c *C) {
s.mustExec(c, "insert into t1 values (?, ?, ?)", i, i, i)
}
t := s.testGetTable(c, "t1")
var c3idx *table.IndexedColumn
var c3idx table.Index
for _, tidx := range t.Indices() {
if tidx.Name.L == "c3_index" {
if tidx.Meta().Name.L == "c3_index" {
c3idx = tidx
break
}
Expand Down Expand Up @@ -273,16 +272,16 @@ LOOP:
handles := make(map[int64]struct{})

t = s.testGetTable(c, "t1")
var nidx *table.IndexedColumn
var nidx table.Index
for _, tidx := range t.Indices() {
if tidx.Name.L == "c3_index" {
if tidx.Meta().Name.L == "c3_index" {
nidx = tidx
break
}
}
// Make sure there is no index with name c3_index
c.Assert(nidx, IsNil)
idx := tables.NewIndex(t.IndexPrefix(), "c3_index", c3idx.ID, false)
idx := tables.NewIndex(t.Meta(), c3idx.Meta())
txn, err := ctx.GetTxn(true)
c.Assert(err, IsNil)
defer ctx.RollbackTxn()
Expand Down
5 changes: 3 additions & 2 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/types"
"github.com/pingcap/tidb/xapi/tablecodec"
)

func buildIndexInfo(tblInfo *model.TableInfo, unique bool, indexName model.CIStr, indexID int64,
Expand Down Expand Up @@ -416,7 +417,7 @@ func lockRow(txn kv.Transaction, t table.Table, h int64) error {
}

func (d *ddl) backfillTableIndex(t table.Table, indexInfo *model.IndexInfo, handles []int64, reorgInfo *reorgInfo) error {
kvX := tables.NewIndex(t.IndexPrefix(), indexInfo.Name.L, indexInfo.ID, indexInfo.Unique)
kvX := tables.NewIndex(t.Meta(), indexInfo)

for _, handle := range handles {
log.Debug("[ddl] building index...", handle)
Expand Down Expand Up @@ -473,7 +474,7 @@ func (d *ddl) backfillTableIndex(t table.Table, indexInfo *model.IndexInfo, hand
}

func (d *ddl) dropTableIndex(t table.Table, indexInfo *model.IndexInfo) error {
prefix := tables.GenIndexPrefix(t.IndexPrefix(), indexInfo.ID)
prefix := tablecodec.EncodeTableIndexPrefix(t.Meta().ID, indexInfo.ID)
err := d.delKeysWithPrefix(prefix)

return errors.Trace(err)
Expand Down
Loading

0 comments on commit dd6bfac

Please sign in to comment.