Self-join stats estimation is particularly expensive because all of the buckets exactly overlap. If the index is unique, the cardinality distribution will not change. If the index is non-unique, the cardinality will expand proportional to rowCount/distinctCount.
before
BenchmarkOltpJoinScan-12 1766 694524 ns/op 462834 B/op 8240 allocs/op
after
BenchmarkOltpJoinScan-12 2460 481166 ns/op 193569 B/op 7129 allocs/op
Self-join stats estimation is particularly expensive because all of the buckets exactly overlap. If the index is unique, the cardinality distribution will not change. If the index is non-unique, the cardinality will expand proportional to
rowCount/distinctCount
.sysbench perf here: https://github.com/dolthub/dolt/pull/8159