-
Notifications
You must be signed in to change notification settings - Fork 5.9k
executor: add more explain analyze info for hash join spill #59255
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
Changes from 8 commits
c8755b3
cbfecd7
1a34326
1df8319
4b6b593
062114a
8c90bd5
4e7e6bb
4887b34
752753f
2133fe6
c01e064
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 |
---|---|---|
|
@@ -21,9 +21,23 @@ import ( | |
"sync/atomic" | ||
"time" | ||
|
||
"github.com/pingcap/tidb/pkg/util" | ||
"github.com/pingcap/tidb/pkg/util/execdetails" | ||
) | ||
|
||
func writeBytesStatsToString(buf *bytes.Buffer, convertedBytes []int64) string { | ||
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. Seems no need to return string here. 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.
deleted |
||
buf.WriteString("[") | ||
for i, byte := range convertedBytes { | ||
if i == 0 { | ||
buf.WriteString(fmt.Sprintf("%.2f", util.ByteToGiB(float64(byte)))) | ||
} else { | ||
buf.WriteString(fmt.Sprintf(" %.2f", util.ByteToGiB(float64(byte)))) | ||
} | ||
} | ||
buf.WriteString("]") | ||
return buf.String() | ||
} | ||
|
||
type hashJoinRuntimeStats struct { | ||
fetchAndBuildHashTable time.Duration | ||
hashStat hashStatistic | ||
|
@@ -107,6 +121,13 @@ func (s *hashStatistic) String() string { | |
return fmt.Sprintf("probe_collision:%v, build:%v", s.probeCollision, execdetails.FormatDuration(s.buildTableElapse)) | ||
} | ||
|
||
type spillStats struct { | ||
round int | ||
totalSpillBytesPerRound []int64 | ||
partitionNumPerRound []int | ||
spillBuildBytesPerRound []int64 | ||
} | ||
|
||
type hashJoinRuntimeStatsV2 struct { | ||
concurrent int | ||
probeCollision int64 | ||
|
@@ -127,6 +148,8 @@ type hashJoinRuntimeStatsV2 struct { | |
maxBuildHashTableForCurrentRound int64 | ||
maxProbeForCurrentRound int64 | ||
maxFetchAndProbeForCurrentRound int64 | ||
|
||
spill spillStats | ||
} | ||
|
||
func setMaxValue(addr *int64, currentValue int64) { | ||
|
@@ -194,14 +217,25 @@ func (e *hashJoinRuntimeStatsV2) String() string { | |
buf.WriteString(execdetails.FormatDuration(time.Duration(atomic.LoadInt64(&e.maxFetchAndProbe)))) | ||
buf.WriteString(", probe:") | ||
buf.WriteString(execdetails.FormatDuration(time.Duration(e.maxProbe))) | ||
buf.WriteString(", fetch and wait:") | ||
buf.WriteString(", fetch_and_wait:") | ||
buf.WriteString(execdetails.FormatDuration(time.Duration(e.fetchAndProbe - e.maxProbe))) | ||
if e.probeCollision > 0 { | ||
buf.WriteString(", probe_collision:") | ||
buf.WriteString(strconv.FormatInt(e.probeCollision, 10)) | ||
} | ||
buf.WriteString("}") | ||
} | ||
if e.spill.round > 0 { | ||
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. Is it possible that e.spill.round is very large? If so, I don't think all the data should be printed. Instead, some aggregated info may be more readable. 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.
It will not be very large. |
||
buf.WriteString(", spill:{round:") | ||
buf.WriteString(strconv.Itoa(e.spill.round)) | ||
buf.WriteString(", partition_num_per_round:") | ||
fmt.Fprintf(buf, "%v", e.spill.partitionNumPerRound) | ||
buf.WriteString(", total_spill_GiB_per_round:") | ||
writeBytesStatsToString(buf, e.spill.totalSpillBytesPerRound) | ||
buf.WriteString(", build_spill_GiB_per_round:") | ||
writeBytesStatsToString(buf, e.spill.spillBuildBytesPerRound) | ||
buf.WriteString("}") | ||
} | ||
return buf.String() | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1047,6 +1047,27 @@ func (e *HashJoinV2Exec) reset() { | |
} | ||
} | ||
|
||
func (e *HashJoinV2Exec) collectSpillStats() { | ||
if e.stats == nil || !e.spillHelper.isSpillTriggered() { | ||
return | ||
} | ||
|
||
round := e.spillHelper.round | ||
if len(e.stats.spill.totalSpillBytesPerRound) < round+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. Will it be possible that length + N < round here? If so, for loop makes sense 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.
It's impossible. |
||
e.stats.spill.totalSpillBytesPerRound = append(e.stats.spill.totalSpillBytesPerRound, 0) | ||
e.stats.spill.spillBuildBytesPerRound = append(e.stats.spill.spillBuildBytesPerRound, 0) | ||
e.stats.spill.partitionNumPerRound = append(e.stats.spill.partitionNumPerRound, 0) | ||
} | ||
|
||
buildSpillBytes := e.spillHelper.getBuildSpillBytes() | ||
probeSpillBytes := e.spillHelper.getProbeSpillBytes() | ||
spilledPartitionNum := e.spillHelper.getSpilledPartitionsNum() | ||
|
||
e.stats.spill.spillBuildBytesPerRound[round] += buildSpillBytes | ||
e.stats.spill.totalSpillBytesPerRound[round] += buildSpillBytes + probeSpillBytes | ||
e.stats.spill.partitionNumPerRound[round] = spilledPartitionNum | ||
} | ||
|
||
func (e *HashJoinV2Exec) startBuildAndProbe(ctx context.Context) { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
|
@@ -1067,6 +1088,7 @@ func (e *HashJoinV2Exec) startBuildAndProbe(ctx context.Context) { | |
e.fetchAndProbeHashTable(ctx) | ||
|
||
e.waiterWg.Wait() | ||
e.collectSpillStats() | ||
e.reset() | ||
|
||
e.spillHelper.spillRoundForTest = max(e.spillHelper.spillRoundForTest, lastRound) | ||
|
@@ -1081,6 +1103,7 @@ func (e *HashJoinV2Exec) startBuildAndProbe(ctx context.Context) { | |
// No more data to restore | ||
return | ||
} | ||
e.spillHelper.round = restoredPartition.round | ||
|
||
if e.memTracker.BytesConsumed() != 0 { | ||
e.isMemoryClearedForTest = false | ||
|
@@ -1090,6 +1113,10 @@ func (e *HashJoinV2Exec) startBuildAndProbe(ctx context.Context) { | |
e.restoredBuildInDisk = restoredPartition.buildSideChunks | ||
e.restoredProbeInDisk = restoredPartition.probeSideChunks | ||
|
||
if e.stats != nil && e.stats.spill.round < lastRound { | ||
e.stats.spill.round = lastRound | ||
} | ||
|
||
e.inRestore = true | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.