-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allocate continuous row id for single INSERT statement #13648
Changes from 6 commits
20310a0
aedd015
7da26e5
4d7732c
a51c01d
45d11ae
4025063
a6d9262
fed318f
1cff8c1
f2844a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,9 +455,22 @@ func (t *tableCommon) AddRecord(ctx sessionctx.Context, r []types.Datum, opts .. | |
} | ||
} | ||
if !hasRecordID { | ||
recordID, err = t.AllocHandle(ctx) | ||
if err != nil { | ||
return 0, err | ||
stmtCtx := ctx.GetSessionVars().StmtCtx | ||
rows := stmtCtx.RecordRows() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This number is wrong... |
||
if rows > 1 { | ||
if stmtCtx.BaseRowID >= stmtCtx.MaxRowID { | ||
stmtCtx.BaseRowID, stmtCtx.MaxRowID, err = t.AllocHandleIDs(ctx, rows) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
if err != nil { | ||
return 0, err | ||
} | ||
} | ||
stmtCtx.BaseRowID += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should increase BaseRowID after L468? |
||
recordID = stmtCtx.BaseRowID | ||
} else { | ||
recordID, err = t.AllocHandle(ctx) | ||
if err != nil { | ||
return 0, err | ||
} | ||
} | ||
} | ||
|
||
|
@@ -947,9 +960,15 @@ func GetColDefaultValue(ctx sessionctx.Context, col *table.Column, defaultVals [ | |
|
||
// AllocHandle implements table.Table AllocHandle interface. | ||
func (t *tableCommon) AllocHandle(ctx sessionctx.Context) (int64, error) { | ||
_, rowID, err := t.Allocator(ctx).Alloc(t.tableID, 1) | ||
_, rowID, err := t.AllocHandleIDs(ctx, 1) | ||
return rowID, err | ||
} | ||
|
||
// AllocHandle implements table.Table AllocHandle interface. | ||
func (t *tableCommon) AllocHandleIDs(ctx sessionctx.Context, n uint64) (int64, int64, error) { | ||
base, rowID, err := t.Allocator(ctx).Alloc(t.tableID, n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/rowID/maxID |
||
if err != nil { | ||
return 0, err | ||
return 0, 0, err | ||
} | ||
if t.meta.ShardRowIDBits > 0 { | ||
// Use max record ShardRowIDBits to check overflow. | ||
|
@@ -961,16 +980,17 @@ func (t *tableCommon) AllocHandle(ctx sessionctx.Context) (int64, error) { | |
// will be duplicated with: | ||
// rowID = 0100111111111111111111111111111111111111111111111111111111111111 | ||
// shard = 0010000000000000000000000000000000000000000000000000000000000000 | ||
return 0, autoid.ErrAutoincReadFailed | ||
return 0, 0, autoid.ErrAutoincReadFailed | ||
} | ||
txnCtx := ctx.GetSessionVars().TxnCtx | ||
if txnCtx.Shard == nil { | ||
shard := t.calcShard(txnCtx.StartTS) | ||
txnCtx.Shard = &shard | ||
} | ||
rowID |= *txnCtx.Shard | ||
base |= *txnCtx.Shard | ||
} | ||
return rowID, nil | ||
return base, rowID, nil | ||
} | ||
|
||
// OverflowShardBits checks whether the rowID overflow `1<<(64-shardRowIDBits-1) -1`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.......
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Little-Wallace