Small. Fast. Reliable.
Choose any three.
*** 2,7 ****
--- 2,17 ----
  
  ----
  
+ *store interior nodes inline*
+ 
+ Currently, for various reasons the leaf nodes must be a contiguous range of block ids.  Thus, the interior nodes at height 1 are accumulated in memory, then flushed to the next range of blocks (and so on up the tree, thought height 1 is obviously most interesting).  The memory footprint is N/C, with C being really rather large.  The 64kdoc segment in the Enron corpus has only 85 interior blocks total, implying a memory footprint under 170k.  But the 1mdoc segment is going to need a couple megabytes.
+ 
+ Since the blocks encode their height in the first byte, it would be easy to have segment merges skip interior nodes which were stored inline.  This would only be of slight impact on merge performance, since interior blocks are only perhaps half a percent of total blocks.  Then interior nodes could just be flushed as needed.
+ 
+ The problem is that interior nodes rely on their subtree nodes being contiguous.  This would hold for the height 1 nodes (their leaf nodes would be contiguous), but the height 2 and above nodes would need to be encoded differently.  The 64kdoc segment had 20k leaf nodes, implying that level-1 interior nodes would be about 230 blockids apart.  Adding a delta-encoded blockid per term at level 2 and above would thus be perhaps 2 bytes per term, which might reduce the fanout there from 230 to 180 or so.  That doesn't seem too bad.
+ 
+ ----
+ 
  *smaller rowids in %_segments*
  
  The current system stores all blocks in a single =%_segments= table which is keyed by rowid.  When we do a merge, the newly created blocks are necessarily receiving a higher rowid than the blocks the merged data is coming from, which blocks are eventually deleted.  Since the new segment uses higher rowids, the deletes rowids cannot be reclaimed.