dolthub / go-mysql-server

A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go.
Apache License 2.0
2.32k stars 199 forks source link

[memo] assume self-join stats cardinality continuity #2606

Closed max-hoffman closed 1 month ago

max-hoffman commented 1 month ago

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

sysbench perf here: https://github.com/dolthub/dolt/pull/8159

nicktobey commented 1 month ago

The new file sql/query_props.go seems unusued and not connected to the rest of the PR.

Otherwise, this looks good.

max-hoffman commented 1 month ago

Whoops thanks for flagging, didn't mean for that to sneak by me.