Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id DB135B5DBC4 for ; Tue, 16 Aug 2011 09:04:51 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 88644-05 for ; Tue, 16 Aug 2011 12:04:45 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og124.obsmtp.com (exprod7og124.obsmtp.com [64.18.2.26]) by mail.postgresql.org (Postfix) with ESMTP id 735A6B5D803 for ; Tue, 16 Aug 2011 09:04:44 -0300 (ADT) Received: from mail-fx0-f51.google.com ([209.85.161.51]) (using TLSv1) by exprod7ob124.postini.com ([64.18.6.12]) with SMTP ID DSNKTkpc211kpE55AqUum1YiS6duvJMZ0xs6@postini.com; Tue, 16 Aug 2011 05:04:45 PDT Received: by fxh10 with SMTP id 10so3999780fxh.10 for ; Tue, 16 Aug 2011 05:04:42 -0700 (PDT) Received: by 10.223.159.8 with SMTP id h8mr7170760fax.3.1313496281925; Tue, 16 Aug 2011 05:04:41 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id i16sm5813186faa.45.2011.08.16.05.04.39 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 16 Aug 2011 05:04:40 -0700 (PDT) Message-ID: <4E4A5CD5.2040601@enterprisedb.com> Date: Tue, 16 Aug 2011 15:04:37 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.18) Gecko/20110626 Icedove/3.1.11 MIME-Version: 1.0 To: Alexander Korotkov CC: Robert Haas , pgsql-hackers Subject: Re: WIP: Fast GiST index build References: <4E31D03D.70206@enterprisedb.com> <4E3977D8.1020506@enterprisedb.com> <4E3FAB1D.1060105@enterprisedb.com> <4E42DFCE.3050904@enterprisedb.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201108/758 X-Sequence-Number: 193513 Looking at the calculation of levelStep: > + /* > + * Calculate levelStep by available amount of memory. We should be able to > + * load into main memory one page of each underlying node buffer (which > + * are in levelStep below). That give constraint over > + * maintenance_work_mem. Also we should be able to have subtree of > + * levelStep level in cache. That give constraint over > + * effective_cache_size. > + * > + * i'th underlying level of sub-tree can consists of > + * i^maxIndexTuplesPerPage pages at maximum. So, subtree of levelStep > + * levels can't be greater then 2 * maxIndexTuplesPerPage ^ levelStep > + * pages. We use some more reserve due to we probably can't take whole > + * effective cache and use formula 4 * maxIndexTuplesPerPage ^ levelStep = > + * effectiveCache. We use similar logic with maintenance_work_mem. We > + * should be able to store at least last pages of all buffers where we are > + * emptying current buffer to. > + */ > + effectiveMemory = Min(maintenance_work_mem * 1024 / BLCKSZ, > + effective_cache_size); > + levelStep = (int) log((double) effectiveMemory / 4.0) / > + log((double) maxIndexTuplesPerPage); > + I can see that that's equal to the formula given in the paper, log_B(M/4B), but I couldn't see any explanation for that formula in the paper. Your explanation makes sense, but where did it come from? It seems a bit pessimistic: while it's true that the a subtree can't be larger than 2 * maxIndexTuplesPerPage ^ levelStep, you can put a tighter upper bound on it. The max size of a subtree of depth n can be calculated as the geometric series: r^0 + r^1 + r^2 + ... + r^n = (1 - r^(n + 1)) / (1 - r) where r = maxIndexTuplesPerPage. For r=2 those formulas are equal, but for a large r and small n (which is typical), the 2 * maxIndexTuplesPerPage^levelStep formula gives a value that's almost twice as large as the real max size of a subtree. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com