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 1ezPFe-0007XA-UY for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Mar 2018 16:09:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ezPFd-00083d-Nw for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Mar 2018 16:09:09 +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.89) (envelope-from ) id 1ezPFd-00083T-89 for pgsql-hackers@lists.postgresql.org; Fri, 23 Mar 2018 16:09:09 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ezPFV-0007j1-7J for pgsql-hackers@postgresql.org; Fri, 23 Mar 2018 16:09:08 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 76BD021C24DF; Fri, 23 Mar 2018 19:08:59 +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 39CD021C1C84; Fri, 23 Mar 2018 19:08:59 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1521821339; bh=Mpc+6P2FjXOY+KJz7/B5tAGCyBpQG2y3C0UGupcGnFc=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=maHaGNxuWbx+yXGT8BE7agdajJOHRFM44ke8P+laIVoiHiagAl03Gr5uHUmaKsPbd fO1cq3BkVQdEzeO5zYwhWsR5SsNK0oQKFNs/v5kXbMsZq4tI9kXxCUauAWMiACYHj5 jsTvc/KHTjpqd0ALVEjUC1Liw0yx851iKNuGlFxI= Subject: Re: [HACKERS] Surjective functional indexes To: Alvaro Herrera Cc: Stephen Frost , Michael Paquier , Simon Riggs , Christoph Berg , Thomas Munro , Peter Eisentraut , PostgreSQL Hackers References: <20180322205353.5v6g5zu3owzh43qp@alvherre.pgsql> From: Konstantin Knizhnik Message-ID: <0f342b0f-3bce-61d2-a411-1e5e15036f0b@postgrespro.ru> Date: Fri, 23 Mar 2018 19:08:59 +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: <20180322205353.5v6g5zu3owzh43qp@alvherre.pgsql> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 22.03.2018 23:53, Alvaro Herrera wrote: > The whole IsProjectionFunctionalIndex looks kinda bogus/ugly to me. Set > the boolean to false, but keep evaluating anyway? But then, I thought > the idea was to do this based on the reloption, not by comparing the > expression cost to a magical (unmodifiable) value? The idea is very simple, I tried to explain it in the comments. Sorry if my explanation was not so clear. By default we assume all functional indexes as projectional. This is done by first assignment is_projection = true. Then we check cost of index function. I agree that "magical (unmodifiable) value" used as cost threshold is not a good idea. But I tried to avoid as much as possible adding yet another configuration parameter. I do no think that flexibility here is so important. I believe that in 99% cases functional indexes are projectional, and in all other cases DBA cna explicitly specify it using recheck_on_update index option. Which should override cost threshold: if DBA thinks that recheck is useful for this index, then it should be used despite to previsions guess based on index expression cost. This is why after setting "is_projection" to false because of too large cost of index expression, we  continue work and check index options for explicitly specified value. > > In RelationGetIndexAttrBitmap(), indexattrs no longer gets the columns > corresponding to projection indexes. Isn't that weird/error > prone/confusing? I think it'd be saner to add these bits to both > bitmaps. This bitmap is needed only to mark attributes, which modification prevents hot update. Should I rename rd_indexattr to  rd_hotindexattr or whatever else to avoid confusion? Please notice, that rd_indexattr is used only inside RelationGetIndexAttrBitmap and is not visible from outside. It is returned for INDEX_ATTR_BITMAP_HOT IndexAttrBitmapKind. > Please update the comments ending in heapam.c:4188, and generally all > comments that you should update. Sorry, did you apply projection-7.patch? I have checked all trailing spaces and other indentation issues. At least there is no trailing space at heapam.c:4188... > > Please keep serial_schedule in sync with parallel_schedule. Sorry, once again do not understand your complaint: I have added func_index both to serial and parallel schedule. > Also, pgindent. > -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company