Skip to content
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

Merged
merged 13 commits into from
Mar 13, 2020

Conversation

tiancaiamao
Copy link
Contributor

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 in stmtCtx.AddRecordRows in each chunk.
That means we count the rows repeatedly.

For example, insert into ... from select 100k rows, we assume the rows is known in advance and it's 100k.
However, each time the code run to table.AddRecord, the rows might be

10k
20k
30k
...
80k
90k
100k

The 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

  • No code

Code changes

  • Has exported function/method change

@tiancaiamao tiancaiamao requested a review from a team as a code owner March 10, 2020 08:49
@ghost ghost requested review from wshwsh12 and XuHuaiyu and removed request for a team March 10, 2020 08:49
@tiancaiamao tiancaiamao added type/bugfix This PR fixes a bug. sig/execution SIG execution labels Mar 10, 2020
@tiancaiamao tiancaiamao requested review from AilinKid and Little-Wallace and removed request for wshwsh12 and XuHuaiyu March 10, 2020 08:50
Copy link
Contributor

@AilinKid AilinKid left a 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

@AilinKid AilinKid added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 10, 2020
table/tables/tables.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #15261 into master will decrease coverage by 0.0297%.
The diff coverage is n/a.

@@               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

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@AilinKid
Copy link
Contributor

LGTM

@tiancaiamao
Copy link
Contributor Author

PTAL @Little-Wallace

1 similar comment
@tiancaiamao
Copy link
Contributor Author

PTAL @Little-Wallace

for i, row := range rows {
var err error
if i == 0 {
_, err = e.addRecordWithAutoIDHint(ctx, row, len(rows))
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiancaiamao
Copy link
Contributor Author

Fix #15073
Ping @Little-Wallace

Copy link
Contributor

@Little-Wallace Little-Wallace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tiancaiamao
Copy link
Contributor Author

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 13, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 13, 2020

/run-all-tests

@sre-bot sre-bot merged commit 88dd552 into pingcap:master Mar 13, 2020
@tiancaiamao tiancaiamao deleted the fix-autoid branch March 13, 2020 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants