-
Notifications
You must be signed in to change notification settings - Fork 6k
statistics: record last gc ts to avoid huge read on stats table #46138
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d7119ec
statistics: record last gc ts to avoid huge read on stats table
winoros 729e4f5
fix linter
winoros b28d41b
fix
winoros 9980a85
Merge branch 'master' into speedup-gc-stat
winoros 264bd27
fix the case for dropping
winoros af53282
fix a test
winoros 3960dcd
address comments
winoros ababb04
Merge branch 'master' into speedup-gc-stat
winoros ff81270
fix the merge error
winoros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,13 @@ func (h *Handle) HandleDDLEvent(t *util.Event) error { | |
return err | ||
} | ||
} | ||
case model.ActionDropTable: | ||
ids := h.getInitStateTableIDs(t.TableInfo) | ||
for _, id := range ids { | ||
if err := h.resetTableStats2KVForDrop(id); err != nil { | ||
return err | ||
} | ||
} | ||
case model.ActionAddColumn, model.ActionModifyColumn: | ||
ids := h.getInitStateTableIDs(t.TableInfo) | ||
for _, id := range ids { | ||
|
@@ -63,6 +70,11 @@ func (h *Handle) HandleDDLEvent(t *util.Event) error { | |
return err | ||
} | ||
} | ||
for _, def := range t.PartInfo.Definitions { | ||
if err := h.resetTableStats2KVForDrop(def.ID); err != nil { | ||
return err | ||
} | ||
} | ||
case model.ActionReorganizePartition: | ||
for _, def := range t.PartInfo.Definitions { | ||
// TODO: Should we trigger analyze instead of adding 0s? | ||
|
@@ -320,6 +332,36 @@ func (h *Handle) insertTableStats2KV(info *model.TableInfo, physicalID int64) (e | |
return nil | ||
} | ||
|
||
// resetTableStats2KV resets the count to 0. | ||
func (h *Handle) resetTableStats2KVForDrop(physicalID int64) (err error) { | ||
statsVer := uint64(0) | ||
defer func() { | ||
if err == nil && statsVer != 0 { | ||
h.recordHistoricalStatsMeta(physicalID, statsVer, StatsMetaHistorySourceSchemaChange) | ||
} | ||
}() | ||
h.mu.Lock() | ||
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. can we use the h.session.pool to avoid the lock the handle? |
||
defer h.mu.Unlock() | ||
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnStats) | ||
exec := h.mu.ctx.(sqlexec.SQLExecutor) | ||
_, err = exec.ExecuteInternal(ctx, "begin") | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
defer func() { | ||
err = finishTransaction(ctx, exec, err) | ||
}() | ||
txn, err := h.mu.ctx.Txn(true) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
startTS := txn.StartTS() | ||
if _, err := exec.ExecuteInternal(ctx, "update mysql.stats_meta set count=0, modify_count=0, version=%? where table_id =%?", startTS, physicalID); err != nil { | ||
time-and-fate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// insertColStats2KV insert a record to stats_histograms with distinct_count 1 and insert a bucket to stats_buckets with default value. | ||
// This operation also updates version. | ||
func (h *Handle) insertColStats2KV(physicalID int64, colInfos []*model.ColumnInfo) (err error) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.