Skip to content

Commit

Permalink
stmt/stmts: insert use primary key value as record ID
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood committed Dec 25, 2015
1 parent 56ff3d3 commit c3bdfb1
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 157 deletions.
16 changes: 8 additions & 8 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *testColumnSuite) TestColumn(c *C) {

num := 10
for i := 0; i < num; i++ {
_, err := t.AddRecord(ctx, []interface{}{i, 10 * i, 100 * i}, 0)
_, err := t.AddRecord(ctx, []interface{}{i, 10 * i, 100 * i})
c.Assert(err, IsNil)
}

Expand Down Expand Up @@ -155,7 +155,7 @@ func (s *testColumnSuite) TestColumn(c *C) {
})
c.Assert(i, Equals, int64(num))

h, err := t.AddRecord(ctx, []interface{}{11, 12, 13, 14}, 0)
h, err := t.AddRecord(ctx, []interface{}{11, 12, 13, 14})
c.Assert(err, IsNil)
err = ctx.FinishTxn(false)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *testColumnSuite) checkDeleteOnlyColumn(c *C, ctx context.Context, d *dd
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -381,7 +381,7 @@ func (s *testColumnSuite) checkWriteOnlyColumn(c *C, ctx context.Context, d *ddl
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -440,7 +440,7 @@ func (s *testColumnSuite) checkReorganizationColumn(c *C, ctx context.Context, d
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -499,7 +499,7 @@ func (s *testColumnSuite) checkPublicColumn(c *C, ctx context.Context, d *ddl, t
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33), int64(44)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -577,7 +577,7 @@ func (s *testColumnSuite) TestAddColumn(c *C) {
t := testGetTable(c, d, s.dbInfo.ID, tblInfo.ID)

row := []interface{}{int64(1), int64(2), int64(3)}
handle, err := t.AddRecord(ctx, row, 0)
handle, err := t.AddRecord(ctx, row)
c.Assert(err, IsNil)

err = ctx.FinishTxn(false)
Expand Down Expand Up @@ -645,7 +645,7 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
colName := "c4"
defaultColValue := int64(4)
row := []interface{}{int64(1), int64(2), int64(3)}
handle, err := t.AddRecord(ctx, append(row, defaultColValue), 0)
handle, err := t.AddRecord(ctx, append(row, defaultColValue))
c.Assert(err, IsNil)

err = ctx.FinishTxn(false)
Expand Down
8 changes: 4 additions & 4 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (ts *testSuite) TestDDL(c *C) {
tb, err := sessionctx.GetDomain(ctx).InfoSchema().TableByName(tbIdent.Schema, tbIdent.Name)
c.Assert(err, IsNil)
c.Assert(tb, NotNil)
_, err = tb.AddRecord(ctx, []interface{}{1, "b", 2, 4}, 0)
_, err = tb.AddRecord(ctx, []interface{}{1, "b", 2, 4})
c.Assert(err, IsNil)

alterStmt := statement(ctx, "alter table t add column aa int first").(*stmts.AlterTableStmt)
Expand Down Expand Up @@ -126,9 +126,9 @@ func (ts *testSuite) TestDDL(c *C) {
tb, err = sessionctx.GetDomain(ctx).InfoSchema().TableByName(tbIdent2.Schema, tbIdent2.Name)
c.Assert(err, IsNil)
c.Assert(tb, NotNil)
rid0, err := tb.AddRecord(ctx, []interface{}{1}, 0)
rid0, err := tb.AddRecord(ctx, []interface{}{1})
c.Assert(err, IsNil)
rid1, err := tb.AddRecord(ctx, []interface{}{2}, 0)
rid1, err := tb.AddRecord(ctx, []interface{}{2})
c.Assert(err, IsNil)

alterStmt = statement(ctx, `alter table t2 add b enum("bb") first`).(*stmts.AlterTableStmt)
Expand All @@ -155,7 +155,7 @@ func (ts *testSuite) TestDDL(c *C) {
c.Assert(cols[0], Equals, nil)
c.Assert(cols[1], BytesEquals, []byte("abc"))
c.Assert(cols[2], Equals, int64(2))
rid3, err := tb.AddRecord(ctx, []interface{}{mysql.Enum{Name: "bb", Value: 1}, "c", 3}, 0)
rid3, err := tb.AddRecord(ctx, []interface{}{mysql.Enum{Name: "bb", Value: 1}, "c", 3})
c.Assert(err, IsNil)
cols, err = tb.Row(ctx, rid3)
c.Assert(err, IsNil)
Expand Down
22 changes: 11 additions & 11 deletions ddl/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *testIndexSuite) TestIndex(c *C) {

num := 10
for i := 0; i < num; i++ {
_, err = t.AddRecord(ctx, []interface{}{i, i, i}, 0)
_, err = t.AddRecord(ctx, []interface{}{i, i, i})
c.Assert(err, IsNil)
}

Expand All @@ -122,14 +122,14 @@ func (s *testIndexSuite) TestIndex(c *C) {
index := t.FindIndexByColName("c1")
c.Assert(index, NotNil)

h, err := t.AddRecord(ctx, []interface{}{num + 1, 1, 1}, 0)
h, err := t.AddRecord(ctx, []interface{}{num + 1, 1, 1})
c.Assert(err, IsNil)

h1, err := t.AddRecord(ctx, []interface{}{num + 1, 1, 1}, 0)
h1, err := t.AddRecord(ctx, []interface{}{num + 1, 1, 1})
c.Assert(err, NotNil)
c.Assert(h, Equals, h1)

h, err = t.AddRecord(ctx, []interface{}{1, 1, 1}, 0)
h, err = t.AddRecord(ctx, []interface{}{1, 1, 1})
c.Assert(err, NotNil)

txn, err = ctx.GetTxn(true)
Expand All @@ -153,7 +153,7 @@ func (s *testIndexSuite) TestIndex(c *C) {
c.Assert(err, IsNil)
c.Assert(exist, IsFalse)

h, err = t.AddRecord(ctx, []interface{}{1, 1, 1}, 0)
h, err = t.AddRecord(ctx, []interface{}{1, 1, 1})
c.Assert(err, IsNil)
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (s *testIndexSuite) checkDeleteOnlyIndex(c *C, ctx context.Context, d *ddl,
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -317,7 +317,7 @@ func (s *testIndexSuite) checkWriteOnlyIndex(c *C, ctx context.Context, d *ddl,
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -397,7 +397,7 @@ func (s *testIndexSuite) checkReorganizationIndex(c *C, ctx context.Context, d *
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -484,7 +484,7 @@ func (s *testIndexSuite) checkPublicIndex(c *C, ctx context.Context, d *ddl, tbl
c.Assert(err, IsNil)

newRow := []interface{}{int64(11), int64(22), int64(33)}
handle, err = t.AddRecord(ctx, newRow, 0)
handle, err = t.AddRecord(ctx, newRow)
c.Assert(err, IsNil)

txn, err = ctx.GetTxn(true)
Expand Down Expand Up @@ -574,7 +574,7 @@ func (s *testIndexSuite) TestAddIndex(c *C) {
t := testGetTable(c, d, s.dbInfo.ID, tblInfo.ID)

row := []interface{}{int64(1), int64(2), int64(3)}
handle, err := t.AddRecord(ctx, row, 0)
handle, err := t.AddRecord(ctx, row)
c.Assert(err, IsNil)

err = ctx.FinishTxn(false)
Expand Down Expand Up @@ -638,7 +638,7 @@ func (s *testIndexSuite) TestDropIndex(c *C) {
t := testGetTable(c, d, s.dbInfo.ID, tblInfo.ID)

row := []interface{}{int64(1), int64(2), int64(3)}
handle, err := t.AddRecord(ctx, row, 0)
handle, err := t.AddRecord(ctx, row)
c.Assert(err, IsNil)

err = ctx.FinishTxn(false)
Expand Down
2 changes: 1 addition & 1 deletion ddl/reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *testDDLSuite) TestReorgOwner(c *C) {

num := 10
for i := 0; i < num; i++ {
_, err := t.AddRecord(ctx, []interface{}{i, i, i}, 0)
_, err := t.AddRecord(ctx, []interface{}{i, i, i})
c.Assert(err, IsNil)
}

Expand Down
4 changes: 2 additions & 2 deletions ddl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ func (s *testTableSuite) TestTable(c *C) {

tbl := testGetTable(c, d, s.dbInfo.ID, tblInfo.ID)

_, err = tbl.AddRecord(ctx, []interface{}{1, 1, 1}, 0)
_, err = tbl.AddRecord(ctx, []interface{}{1, 1, 1})
c.Assert(err, IsNil)

_, err = tbl.AddRecord(ctx, []interface{}{2, 2, 2}, 0)
_, err = tbl.AddRecord(ctx, []interface{}{2, 2, 2})
c.Assert(err, IsNil)

job = testDropTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down
4 changes: 2 additions & 2 deletions inspectkv/inspectkv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (s *testSuite) TestScan(c *C) {
tb, err := tables.TableFromMeta(alloc, s.tbInfo)
c.Assert(err, IsNil)
indices := tb.Indices()
_, err = tb.AddRecord(s.ctx, []interface{}{10, 11}, 0)
_, err = tb.AddRecord(s.ctx, []interface{}{10, 11})
c.Assert(err, IsNil)
s.ctx.FinishTxn(false)

Expand All @@ -169,7 +169,7 @@ func (s *testSuite) TestScan(c *C) {
c.Assert(err, IsNil)
c.Assert(records, DeepEquals, []*RecordData{record1})

_, err = tb.AddRecord(s.ctx, record2.Values, record2.Handle)
_, err = tb.AddRecord(s.ctx, record2.Values)
c.Assert(err, IsNil)
s.ctx.FinishTxn(false)
txn, err := s.store.Begin()
Expand Down
8 changes: 4 additions & 4 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ type TableInfo struct {
Charset string `json:"charset"`
Collate string `json:"collate"`
// Columns are listed in the order in which they appear in the schema.
Columns []*ColumnInfo `json:"cols"`
Indices []*IndexInfo `json:"index_info"`
State SchemaState `json:"state"`
PKIsHandle bool `json:"pk_is_handle"`
Columns []*ColumnInfo `json:"cols"`
Indices []*IndexInfo `json:"index_info"`
State SchemaState `json:"state"`
PKIsHandle bool `json:"pk_is_handle"`
}

// Clone clones TableInfo.
Expand Down
24 changes: 12 additions & 12 deletions plan/plans/from_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ func (p *testFromSuit) SetUpSuite(c *C) {
c.Assert(err, IsNil)
p.vars = map[string]interface{}{}
p.txn, _ = store.Begin()
p.cols = []*column.Col{
{
ColumnInfo: model.ColumnInfo{
tbInfo := &model.TableInfo{
ID: 1,
Name: model.NewCIStr("t"),
State: model.StatePublic,
Columns: []*model.ColumnInfo{
{
ID: 0,
Name: model.NewCIStr("id"),
Offset: 0,
DefaultValue: 0,
FieldType: *types.NewFieldType(mysql.TypeLonglong),
State: model.StatePublic,
},
},
{
ColumnInfo: model.ColumnInfo{
{
ID: 1,
Name: model.NewCIStr("name"),
Offset: 1,
Expand All @@ -97,14 +98,13 @@ func (p *testFromSuit) SetUpSuite(c *C) {
},
},
}

p.tbl = tables.NewTable(1, "t", p.cols, &simpleAllocator{})

p.tbl, err = tables.TableFromMeta(&simpleAllocator{}, tbInfo)
c.Assert(err, IsNil)
variable.BindSessionVars(p)

var i int64
for i = 0; i < 10; i++ {
_, err = p.tbl.AddRecord(p, []interface{}{i * 10, "hello"}, 0)
_, err = p.tbl.AddRecord(p, []interface{}{i * 10, "hello"})
c.Assert(err, IsNil)
}
}
Expand All @@ -131,8 +131,8 @@ func (p *testFromSuit) TestTableDefaultPlan(c *C) {
pln := &plans.TableDefaultPlan{
T: p.tbl,
Fields: []*field.ResultField{
field.ColToResultField(p.cols[0], "t"),
field.ColToResultField(p.cols[1], "t"),
field.ColToResultField(p.tbl.Cols()[0], "t"),
field.ColToResultField(p.tbl.Cols()[1], "t"),
},
}

Expand Down
53 changes: 25 additions & 28 deletions plan/plans/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ func (p *testIndexSuit) SetUpSuite(c *C) {
p.store = store
se, _ := tidb.CreateSession(store)
p.ctx = se.(context.Context)
p.cols = []*column.Col{
{
ColumnInfo: model.ColumnInfo{
tbInfo := &model.TableInfo{
ID: 2,
Name: model.NewCIStr("t2"),
State: model.StatePublic,
Columns: []*model.ColumnInfo{
{
ID: 0,
Name: model.NewCIStr("id"),
Offset: 0,
DefaultValue: 0,
FieldType: *types.NewFieldType(mysql.TypeLonglong),
State: model.StatePublic,
},
},
{
ColumnInfo: model.ColumnInfo{
{
ID: 1,
Name: model.NewCIStr("name"),
Offset: 1,
Expand All @@ -73,33 +74,29 @@ func (p *testIndexSuit) SetUpSuite(c *C) {
State: model.StatePublic,
},
},
}

p.tbl = tables.NewTable(2, "t2", p.cols, &simpleAllocator{})

idxCol := &column.IndexedCol{
IndexInfo: model.IndexInfo{
Name: model.NewCIStr("id"),
Table: model.NewCIStr("t2"),
Columns: []*model.IndexColumn{
{
Name: model.NewCIStr("id"),
Offset: 0,
Length: 0,
Indices: []*model.IndexInfo{
{
Name: model.NewCIStr("id"),
Table: model.NewCIStr("t2"),
Columns: []*model.IndexColumn{
{
Name: model.NewCIStr("id"),
Offset: 0,
Length: 0,
},
},
Unique: false,
Primary: false,
State: model.StatePublic,
},
Unique: false,
Primary: false,
State: model.StatePublic,
},
}

idxCol.X = kv.NewKVIndex("i", "id", 0, false)

p.tbl.AddIndex(idxCol)
p.tbl, err = tables.TableFromMeta(&simpleAllocator{}, tbInfo)
c.Assert(err, IsNil)
var i int64
for i = 0; i < 10; i++ {
p.tbl.AddRecord(p.ctx, []interface{}{i * 10, "hello"}, 0)
p.tbl.AddRecord(p.ctx, []interface{}{i * 10, "hello"})
}
}

Expand All @@ -123,8 +120,8 @@ func (p *testIndexSuit) TestIndexPlan(c *C) {
pln := &plans.TableDefaultPlan{
T: p.tbl,
Fields: []*field.ResultField{
field.ColToResultField(p.cols[0], "t"),
field.ColToResultField(p.cols[1], "t"),
field.ColToResultField(p.tbl.Cols()[0], "t"),
field.ColToResultField(p.tbl.Cols()[1], "t"),
},
}

Expand Down
Loading

0 comments on commit c3bdfb1

Please sign in to comment.