Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ehAYu-00021V-ES for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2018 08:49:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehAYt-0001NK-F5 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2018 08:49:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ehAYt-0001NA-2L for pgsql-hackers@lists.postgresql.org; Thu, 01 Feb 2018 08:49:39 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ehAYk-0002lh-R2 for pgsql-hackers@postgresql.org; Thu, 01 Feb 2018 08:49:37 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 2DFAC21C06DE; Thu, 1 Feb 2018 11:49:25 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.200] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 77A2321C0651; Thu, 1 Feb 2018 11:49:25 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1517474965; bh=lmwwFDz9WQ3OuL3hZksCjtaYphstAmGAcu6MBuoHuXY=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=dSwUA5CR2UQK9AkXXf+B8NzqRGF28N7CH59KcwYq3JWEsJtw1JxPxvo038pZQgd2+ lNoV3ZzI42Brn7/cQ0lsNWRWmJViwSo0e0amZxJK/VzgQOi3oXI+rgK9C12LexKlL+ zaFzmeXFQFR7gLuUQ+OogM5bU28+9NvAZTHlWWrA= Subject: Re: [HACKERS] Surjective functional indexes To: Simon Riggs Cc: Stephen Frost , Michael Paquier , Alvaro Herrera , Christoph Berg , Thomas Munro , Peter Eisentraut , PostgreSQL Hackers References: <20171214211553.ijxfd4p52nz7qg44@alvherre.pgsql> <623fdf0f-c3d1-7553-e784-f8d5a900239b@postgrespro.ru> <20180106225942.GT2416@tamriel.snowman.net> <40fd1ef1-6227-69d1-9a24-edfef875e006@postgrespro.ru> From: Konstantin Knizhnik Message-ID: <6d781672-d9fd-c809-c835-635c2b9c8f48@postgrespro.ru> Date: Thu, 1 Feb 2018 11:49:24 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01.02.2018 03:10, Simon Riggs wrote: > On 10 January 2018 at 09:54, Konstantin Knizhnik > wrote: > >> (new version attached) > Why this comment? > > Current implementation of projection optimization has to calculate > index expression twice > in case of hit (value of index expression is not changed) and three > times if values are different. > > Old + New for check = 2 > plus calculate again in index = 3 > ? > Sorry, I do not completely understand your question. You do not agree with this statement or you think that this comment is irrelevant in this place? Or you just want to understand why index expression is calculated 2/3 times? If so, then you have answered this question yourself: > Old + New for check = 2 > plus calculate again in index = 3 Yes, we have to calculate the value of index expression for original and updated version of the record. If them are equal, then it is all we have to do with this index: hot update is applicable. In this case we calculate index expression twice. But if them are not equal, then hot update is not applicable and we have to update index. In this case expression will be calculated one more time. So totally three times. This is why, if calculation of index expression is very expensive, then effect of this optimization may be negative even if value of index expression is not changed. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company