Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bWoBy-0002gl-Nm for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Aug 2016 17:18:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bWoBy-0006pH-5x for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Aug 2016 17:18:22 +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 1bWoAa-0005Iu-OD for pgsql-hackers@postgresql.org; Mon, 08 Aug 2016 17:16:56 +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 1bWoAX-000728-6L for pgsql-hackers@postgresql.org; Mon, 08 Aug 2016 17:16:56 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 491B121C2AFA; Mon, 8 Aug 2016 20:16:51 +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 pbO5A7kz_IlK; Mon, 8 Aug 2016 20:16:51 +0300 (MSK) Received: from [192.168.27.79] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 132DA21C2AF9; Mon, 8 Aug 2016 20:16:51 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1470676611; bh=xzFLOvh7uYMECCq6KqYO7aqQ7KlplZE5mqzgg926xGY=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=kMZgCTpVaXKwk+cgDIxWwF4MASl1Uob0arfw3ZYeh2KqZzHiy2WU5Gzp4VIDM1G71 MTrXZzH2s9J1QFPX7SrlgBo0EgSZfgBNPdJsdoFc9GMVxZh4kZ6/o16AKUt8qZHBig 3zXV41dSQ8O91TjfOkD8Tm2T+0CQky6i8Odz77nY= Subject: Re: Re: GiST optimizing memmoves in gistplacetopage for fixed-size updates [PoC] To: amborodin@acm.org References: <20160725015209.GA240901@alvherre.pgsql> Cc: Alvaro Herrera , Michael Paquier , Amit Kapila , Alexander Korotkov , pgsql-hackers , Oleg Bartunov , Heikki Linnakangas , Sergey Mirvoda From: Anastasia Lubennikova Message-ID: <5c236e0a-7c13-b592-14e4-49355ab3a3bb@postgrespro.ru> Date: Mon, 8 Aug 2016 20:16:50 +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 06.08.2016 19:51, Andrew Borodin: > Anastasia , thank you for your attentive code examine. > > 2016-08-05 21:19 GMT+05:00 Anastasia Lubennikova : >> First of all, shouldn't we use MAXALIGN(oldsize) instead of oldsize? >> Although, I'm quite sure that it was already aligned somewhere before. >> I doubt that the check (size_diff != MAXALIGN(size_diff)) is necessary. >> I'd rather add the check: (offset+size_diff < pd_lower). > Actually, that's a tricky question. There may be different code expectations. > 1. If we expect that not-maxaligned tuple may be placed by any other > routine, we should remove check (size_diff != MAXALIGN(size_diff)), > since it will fail for not-maxaligned tuple. > 2. If we expect that noone should use PageIndexTupleOverwrite with > not-maxaligned tuples, than current checks are OK: we will break > execution if we find non-maxaligned tuples. With an almost correct > message. > I suggest that this check may be debug-only assertion: in a production > code routine will work with not-maxaligned tuples if they already > reside on the page, in a dev build it will inform dev that something > is going wrong. Is this behavior Postgres-style compliant? > > > I agree that pd_lower check makes sense. Pointing out to this comparison I worried about possible call of MAXALIGN for negative size_diff value. Although I don't sure if it can cause any problem. Tuples on a page are always maxaligned. But, as far as I recall, itemid->lp_len can contain non-maxaligned value. So, I'd suggest you to perform MAXALIGN(oldsize) before computing size_diff: size_diff = oldsize - alignednewsize; Since both arguments are maxaligned the check of size_diff is not needed. >> BTW, I'm very surprised that it improves performance so much. >> And also size is reduced significantly. 89MB against 289MB without patch. >> Could you explain in details, why does it happen? > Size reduction is unexpected for me. > There might be 4 plausible explanations. I'll list them ordered by > descending of probability: > 1. Before this patch every update was throwing recently updated tuple > to the end of a page. Thus, in some-how ordered data, recent best-fit > will be discovered last. This can cause increase of MBB's overlap in > spatial index and slightly higher tree. But 3 times size decrease is > unlikely. > How did you obtained those results? Can I look at a test case? Nothing special, I've just run the test you provided in this thread. And check index size via select pg_size_pretty(pg_relation_size('idx')); > 2. Bug in PageIndexTupleDelete causing unused space emersion. I've > searched for it, unsuccessfully. > 3. Bug in PageIndexTupleOVerwrite. I cannot imagine nature of such a > bug. May be we are not placing something not very important and big on > a page? > 4. Magic. > I do not see what one should do with the R-tree to change it's size by > a factor of 3. First three explanations are not better that forth, > actually. > Those 89 MB, they do not include WAL, right? -- 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