Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZgDl-0001Li-Kn for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Aug 2016 15:24:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bZgDl-0007F5-2r for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Aug 2016 15:24:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bZgDj-0007BF-4p for pgsql-hackers@postgresql.org; Tue, 16 Aug 2016 15:24:03 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZgDf-0000Cn-4N for pgsql-hackers@postgresql.org; Tue, 16 Aug 2016 15:24:02 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 3320021C2DCA; Tue, 16 Aug 2016 18:23:58 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ws-ybypSKi0j; Tue, 16 Aug 2016 18:23:58 +0300 (MSK) Received: from [192.168.27.34] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id EB60A21C2DC7; Tue, 16 Aug 2016 18:23:57 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1471361038; bh=YGb7yCeqebWT8S94QdKVaqsYlXs97RbMtxeb/eT9NaM=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=A1JPyCHedZ1wnlyVXNMswNv7lHg8TeGq/NUr80yXv9a/JLWf+K5xNWqk+zJSE5EeO j85OPGiPZYnvWbXXNZNzqglvLM8yYCLq5ozr1lxkJkCBIKIXClWVtFk2O8uP9DmcVP ws/VVT2YTayEdVQ9wNZDT2KdBVBMre7gbJZd7NdY= Subject: Re: Re: GiST optimizing memmoves in gistplacetopage for fixed-size updates [PoC] To: amborodin@acm.org References: <20160725015209.GA240901@alvherre.pgsql> <5c236e0a-7c13-b592-14e4-49355ab3a3bb@postgrespro.ru> Cc: Alvaro Herrera , Michael Paquier , Amit Kapila , Alexander Korotkov , pgsql-hackers , Oleg Bartunov , Heikki Linnakangas , Sergey Mirvoda From: Anastasia Lubennikova Message-ID: Date: Tue, 16 Aug 2016 18:23:57 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org 09.08.2016 19:45, Andrew Borodin: > Here is new version of the patch, now it includes recommendations from > Anastasia Lubennikova. > > > I've investigated anamalous index size decrease. Most probable version > appeared to be true. > Cube extension, as some others, use Guttman's polynomial time split > algorithm. It is known to generate "needle-like" MBBs (MBRs) for > sorted data due to imbalanced splits (splitting 100 tuples as 98 to > 2). Due to previous throw-to-the-end behavior of GiST this imbalance > was further amplificated (most of inserts were going to bigger part > after split). So GiST inserts were extremely slow for sorted data. > There is no need to do exact sorting to trigger this behavior. > This behavior can be fused by implementation of small-m restriction in > split (AFAIR this is described in original R-tree paper from 84), > which prescribes to do a split in a parts no smaller than m, where m > is around 20% of a page capacity (in tuples number). After application > of this patch performance for sorted data is roughly the same as > performance for randomized data. Thank you for explanation. Now it's clear to me. I did some more testing and found nothing special. The declared feature is implemented correctly. It passes all regression tests and improves performance. I still have a few minor nitpicks about the patch style. You can find a style guide on https://www.postgresql.org/docs/9.6/static/source.html 1) remove extra whitespace in README 2) add whitespace: if(ntup == 1) 3) fix comments in accordance with coding conventions /* In case of single tuple update GiST calls overwrite * In all other cases function gistplacetopage deletes * old tuples and place updated at the end * */ + /* Normally here was following assertion + * Assert(ItemIdHasStorage(ii)); + * This assertion was introduced in PageIndexTupleDelete + * But if this function will be used from BRIN index + * this assertion will fail. Thus, here we do not check that + * item has the storage. + * */ 4) remove unrelated changes - data += sizeof(OffsetNumber) * xldata->ntodelete; + data += sizeof(OffsetNumber) *xldata->ntodelete; 5) If the comment is correct, maxalignment is not necessary. + /* tuples on a page are always maxaligned */ + oldsize = MAXALIGN(oldsize); 6) I'd rather use alignednewsize here. + ItemIdSetNormal(tupid, offset + size_diff, newsize); After the cleanup you can change status to "Ready for Committer" without waiting for the response. > If data is randomized this effect of Guttman poly-time split is not in > effect; test from the start of the thread will show no statistically > confident improvement by the patch. > To prove performance increase in randomized case I've composed > modified test https://gist.github.com/x4m/856b2e1a5db745f8265c76b9c195f2e1 > This test with five runs shows following: > Before patch > Insert Time AVG 78 seconds STD 9.5 > Afer patch > Insert Time AVG 68 seconds STD 7.7 > This is marginal but statistically viable performance improvement. > > For sorted data performance is improved by a factor of 3. > Best regards, Andrey Borodin, Octonica & Ural Federal University. > -- Anastasia Lubennikova Postgres Professional: http://www.postgrespro.com The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers