-
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
*: fix autoid allocation to avoid quickly exhaustion #15261
Conversation
remove unnecessary methods. "The bigger the interface, the weaker the abstraction -- Rob Pike"
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.
via opt is cool, LGTM
Codecov Report
@@ Coverage Diff @@
## master #15261 +/- ##
================================================
- Coverage 80.6609% 80.6312% -0.0298%
================================================
Files 503 503
Lines 134981 135285 +304
================================================
+ Hits 108877 109082 +205
- Misses 17705 17714 +9
- Partials 8399 8489 +90 |
/run-all-tests |
LGTM |
PTAL @Little-Wallace |
1 similar comment
PTAL @Little-Wallace |
for i, row := range rows { | ||
var err error | ||
if i == 0 { | ||
_, err = e.addRecordWithAutoIDHint(ctx, row, len(rows)) |
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.
Do we not need to limit the size of reserveAutoIDCount?
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.
Unnecessary, the rows count equals to the size of a chunk https://github.com/pingcap/tidb/blob/master/executor/insert_common.go#L420
Fix #15073 |
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.
LGTM
/merge |
/run-all-tests |
What problem does this PR solve?
In #13648, we try to allocate continuous row id for a single INSERT statement.
It asserts the rows count changed by a statement is known in advance, obtained through
stmtCtx.RecordRows()
.However, that's not true.
In
insert into ... from select
, we don't know the actual rows count in advance.stmtCtx.RecordRows()
is accumulated instmtCtx.AddRecordRows
in each chunk.That means we count the rows repeatedly.
For example,
insert into ... from select
100k rows, we assume therows
is known in advance and it's 100k.However, each time the code run to
table.AddRecord
, therows
might beThe total count is much more than 100k, which wastes a lot of auto-ID.
What is changed and how it works?
I rewrite the
addRecord
function and add a reverse auto-ID hint parameter.The caller would use the hint to guide the
table.AddRecord
to preallocate some auto-ID in the statement context.And later use statement cached ones prior to the table's allocator.
Check List
Tests
Code changes