Subject Re: [Firebird-Architect] Re: Some benchmarks about 'Order by' - temporary
Author Vlad Horsun
> When does the merging (of multiple runs) happen? [By fetch, on first execute, ..?]
> Is the final merge only in memory or also written to disk?

When data passed into sort they puts into relatively small in-memory buffer
(currently 128KB). When buffer filled it is sorted (by quicksort) and writes to the
temp space as run of level 0. When we got 8 such runs they merged into larger
run - run level 1. When we got 8 runs of level 1 we again merged it in to more
large run - run level 2. After last record passed into sort we have 0..7 runs of level 0,
+ 0..7 runs of level 1, + N runs of level 2. When sorted data is fetched from sort we
merge all of the runs on the fly

Temp space begins from memory and continues on the disk. Maximum amount
of the memory defined by config file settings "TempCacheLimit". By default it is 64MB
which is enough to have 7 runs of level 0 and 7 runs of level 1 and 7 runs of level 2
or 8 runs of level 2. Therefore all merging before the final stage (fetch from sort) fits
into memory part of temp space (i.e. merging of runs of level 0 and level 1).