On Thu, Apr 01, 2010 at 10:44:51AM -0400, Pavel Ivanov scratched on the wall:
> > So 58s for count of all records! The count(*) for all records may use
> > the counter from primary key b-tree, is't it?
> 
> What does this mean? I believe there's no any kind of counters in
> b-tree. If you meant counter from auto-increment key then how about
> gaps in the middle?

  If a statement is in the form "SELECT count(*) FROM <table>" there is
  an optimization that short-cuts the standard aggregate functions and
  gets the leaf count directly from a BTree.

  However, I believe you are correct that the BTree does not keep a
  global leaf count in the header, so the whole tree must be loaded and
  walked.  The optimization will favor a low-column index BTree over the
  table root BTree, since this will typically require less I/O.  Time is
  also saved in short-cutting the column loading and aggregation functions
  (countStep() and countFinalize()).  But in the end, it looks like
  most of the tree is still loaded.

  See the function isSimpleCount() in the source for more specifics.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor."   "I'll go home and see if I can scrounge up a ruler
 and a piece of string."  --from Anathem by Neal Stephenson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to