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

Use PkScan operator #367

Merged
merged 9 commits into from
Mar 7, 2021
Merged

Use PkScan operator #367

merged 9 commits into from
Mar 7, 2021

Conversation

asdine
Copy link
Collaborator

@asdine asdine commented Mar 7, 2021

This PR modifies the planner to use the stream.PkScan operator when possible.
This operator behaves like an index but is faster and space efficient because it uses
the table tree rather than a separate index tree.

Benchmarks:

Before

$ go test -count=5 -benchmem -run=^$ -bench BenchmarkSelectPk | tee old.txt
goos: linux
goarch: amd64
pkg: github.com/genjidb/genji
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkSelectPk/00001-12                 60174             17452 ns/op            4184 B/op         90 allocs/op
BenchmarkSelectPk/00001-12                 67738             17082 ns/op            4183 B/op         90 allocs/op
BenchmarkSelectPk/00001-12                 71444             16640 ns/op            4183 B/op         90 allocs/op
BenchmarkSelectPk/00001-12                 69579             17069 ns/op            4183 B/op         90 allocs/op
BenchmarkSelectPk/00001-12                 67123             16799 ns/op            4183 B/op         90 allocs/op
BenchmarkSelectPk/00010-12                 63070             18711 ns/op            5224 B/op        135 allocs/op
BenchmarkSelectPk/00010-12                 62373             19149 ns/op            5224 B/op        135 allocs/op
BenchmarkSelectPk/00010-12                 61804             18993 ns/op            5223 B/op        135 allocs/op
BenchmarkSelectPk/00010-12                 61906             19465 ns/op            5226 B/op        135 allocs/op
BenchmarkSelectPk/00010-12                 61243             18744 ns/op            5225 B/op        135 allocs/op
BenchmarkSelectPk/00100-12                 12324             96532 ns/op           15691 B/op        585 allocs/op
BenchmarkSelectPk/00100-12                 12452             95986 ns/op           15687 B/op        585 allocs/op
BenchmarkSelectPk/00100-12                 12182             97492 ns/op           15686 B/op        585 allocs/op
BenchmarkSelectPk/00100-12                 12422             96658 ns/op           15689 B/op        585 allocs/op
BenchmarkSelectPk/00100-12                 12366             98609 ns/op           15685 B/op        585 allocs/op
BenchmarkSelectPk/01000-12                  1333            880389 ns/op          138400 B/op       6830 allocs/op
BenchmarkSelectPk/01000-12                  1354            908564 ns/op          138278 B/op       6830 allocs/op
BenchmarkSelectPk/01000-12                  1345            879852 ns/op          138388 B/op       6830 allocs/op
BenchmarkSelectPk/01000-12                  1336            890207 ns/op          138356 B/op       6830 allocs/op
BenchmarkSelectPk/01000-12                  1342            882389 ns/op          138293 B/op       6830 allocs/op
BenchmarkSelectPk/10000-12                   132           9377784 ns/op         1371696 B/op      69839 allocs/op
BenchmarkSelectPk/10000-12                   129           9044030 ns/op         1370267 B/op      69838 allocs/op
BenchmarkSelectPk/10000-12                   132           9024456 ns/op         1371280 B/op      69839 allocs/op
BenchmarkSelectPk/10000-12                   127           9021765 ns/op         1370703 B/op      69838 allocs/op
BenchmarkSelectPk/10000-12                   132           9436749 ns/op         1370667 B/op      69838 allocs/op

After

$ go test -count=5 -benchmem -run=^$ -bench BenchmarkSelectPk | tee new.txt
goos: linux
goarch: amd64
pkg: github.com/genjidb/genji
cpu: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
BenchmarkSelectPk/00001-12                 59692             18439 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00001-12                 67766             17365 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00001-12                 68274             17324 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00001-12                 68650             17540 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00001-12                 67000             17293 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00010-12                 68598             17529 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00010-12                 65353             17302 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00010-12                 69853             17606 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00010-12                 67478             17089 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00010-12                 62709             17468 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00100-12                 53097             22570 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00100-12                 55345             22118 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00100-12                 54732             22356 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00100-12                 54140             21778 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/00100-12                 53340             22305 ns/op            4632 B/op         95 allocs/op
BenchmarkSelectPk/01000-12                 54985             22117 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/01000-12                 54417             21713 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/01000-12                 55604             22208 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/01000-12                 54969             21824 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/01000-12                 54782             22163 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/10000-12                 54614             22786 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/10000-12                 56102             21710 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/10000-12                 54963             21659 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/10000-12                 55752             21549 ns/op            4648 B/op         97 allocs/op
BenchmarkSelectPk/10000-12                 55063             21579 ns/op            4648 B/op         97 allocs/op

Benchstat:

$ benchstat old.txt new.txt
name               old time/op    new time/op    delta
SelectPk/00001-12    17.0µs ± 3%    17.6µs ± 5%     ~     (p=0.056 n=5+5)
SelectPk/00010-12    19.0µs ± 2%    17.4µs ± 2%   -8.49%  (p=0.008 n=5+5)
SelectPk/00100-12    97.1µs ± 2%    22.2µs ± 2%  -77.10%  (p=0.008 n=5+5)
SelectPk/01000-12     888µs ± 2%      22µs ± 1%  -97.52%  (p=0.008 n=5+5)
SelectPk/10000-12    9.18ms ± 3%    0.02ms ± 4%  -99.76%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
SelectPk/00001-12    4.18kB ± 0%    4.63kB ± 0%  +10.73%  (p=0.016 n=4+5)
SelectPk/00010-12    5.22kB ± 0%    4.63kB ± 0%  -11.34%  (p=0.008 n=5+5)
SelectPk/00100-12    15.7kB ± 0%     4.6kB ± 0%  -70.47%  (p=0.008 n=5+5)
SelectPk/01000-12     138kB ± 0%       5kB ± 0%  -96.64%  (p=0.008 n=5+5)
SelectPk/10000-12    1.37MB ± 0%    0.00MB ± 0%  -99.66%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
SelectPk/00001-12      90.0 ± 0%      95.0 ± 0%   +5.56%  (p=0.008 n=5+5)
SelectPk/00010-12       135 ± 0%        95 ± 0%  -29.63%  (p=0.008 n=5+5)
SelectPk/00100-12       585 ± 0%        95 ± 0%  -83.76%  (p=0.008 n=5+5)
SelectPk/01000-12     6.83k ± 0%     0.10k ± 0%  -98.58%  (p=0.008 n=5+5)
SelectPk/10000-12     69.8k ± 0%      0.1k ± 0%  -99.86%  (p=0.008 n=5+5)

@asdine asdine merged commit 7503df2 into main Mar 7, 2021
@asdine asdine deleted the planner/pk-optimization branch March 7, 2021 13:36
@asdine asdine linked an issue Mar 7, 2021 that may be closed by this pull request
@asdine asdine modified the milestone: v0.11.0 Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should search on primary key be as fast as an indexed field?
1 participant