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

planner: log the reason why the sample-rate is chosen when analyzing table (#45938) #45968

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup
qw4990 committed Oct 12, 2023

Verified

This commit was signed with the committer’s verified signature.
radoering Randy Döring
commit f2a009c8dff2b7b1a46efc7f7ccdf96f90bc5e64
11 changes: 1 addition & 10 deletions executor/builder.go
Original file line number Diff line number Diff line change
@@ -2604,11 +2604,7 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC
if opts[ast.AnalyzeOptNumSamples] == 0 {
*sampleRate = math.Float64frombits(opts[ast.AnalyzeOptSampleRate])
if *sampleRate < 0 {
<<<<<<< HEAD
*sampleRate = b.getAdjustedSampleRate(b.ctx, task)
=======
*sampleRate, sampleRateReason = b.getAdjustedSampleRate(task)
>>>>>>> 6fb20c9d306 (planner: log the reason why the sample-rate is chosen when analyzing table (#45938))
if task.PartitionName != "" {
sc.AppendNote(errors.Errorf(
`Analyze use auto adjusted sample rate %f for table %s.%s's partition %s, reason to use this rate is "%s"`,
@@ -2690,13 +2686,8 @@ func (b *executorBuilder) buildAnalyzeSamplingPushdown(task plannercore.AnalyzeC
// If we take n = 1e12, a 300*k sample still gives <= 0.66 bin size error with probability 0.99.
// So if we don't consider the top-n values, we can keep the sample size at 300*256.
// But we may take some top-n before building the histogram, so we increase the sample a little.
<<<<<<< HEAD
func (b *executorBuilder) getAdjustedSampleRate(sctx sessionctx.Context, task plannercore.AnalyzeColumnsTask) float64 {
statsHandle := domain.GetDomain(sctx).StatsHandle()
=======
func (b *executorBuilder) getAdjustedSampleRate(task plannercore.AnalyzeColumnsTask) (sampleRate float64, reason string) {
func (b *executorBuilder) getAdjustedSampleRate(sctx sessionctx.Context, task plannercore.AnalyzeColumnsTask) (sampleRate float64, reason string) {
statsHandle := domain.GetDomain(b.ctx).StatsHandle()
>>>>>>> 6fb20c9d306 (planner: log the reason why the sample-rate is chosen when analyzing table (#45938))
defaultRate := 0.001
if statsHandle == nil {
return defaultRate, fmt.Sprintf("statsHandler is nil, use the default-rate=%v", defaultRate)
6 changes: 1 addition & 5 deletions statistics/analyze_jobs.go
Original file line number Diff line number Diff line change
@@ -26,15 +26,11 @@ type AnalyzeJob struct {
TableName string
PartitionName string
JobInfo string
<<<<<<< HEAD
StartTime time.Time
EndTime time.Time
Progress AnalyzeProgress
=======

SampleRateReason string // why this sample-rate is chosen
Progress AnalyzeProgress
>>>>>>> 6fb20c9d306 (planner: log the reason why the sample-rate is chosen when analyzing table (#45938))
SampleRateReason string // why this sample-rate is chosen
}

// AnalyzeProgress represents the process of one analyze job.