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 1gL9LI-0005er-SY for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Nov 2018 16:09:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gL9LG-0008UJ-8R for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Nov 2018 16:09:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gL9LF-0008RW-N2 for pgsql-hackers@lists.postgresql.org; Fri, 09 Nov 2018 16:09:06 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gL9LB-0002f9-Ub for pgsql-hackers@postgresql.org; Fri, 09 Nov 2018 16:09:04 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id CDBEF21C62D2; Fri, 9 Nov 2018 19:08:58 +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 6D0F221C62D1; Fri, 9 Nov 2018 19:08:58 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1541779738; bh=0JvM6IO8b+LWXFfUXkC21x1Y/uE9Xm7fMygVXtJs2wQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=ST71517gayLMIcI3x1Ak5tZVom796zCd88rvq4uxdMT0aSRUok0uVgWOBTKeEoSmO Aa5YTeY3EvZICdzg3fcZD0G71RRxjBCd4nS/omv4MIYac6nm32NiCLl5xZql9uNh3D 3aqzg8hfIE2b9g+hTK9YpKyL21NadZu0HXiIizgo= Subject: Re: [HACKERS] Surjective functional indexes To: Tom Lane Cc: Alvaro Herrera , Laurenz Albe , Simon Riggs , Robert Haas , Andres Freund , Stephen Frost , Michael Paquier , Christoph Berg , Thomas Munro , Peter Eisentraut , PostgreSQL Hackers References: <20181108190559.ylzufqr2jjvml32f@alvherre.pgsql> <11218.1541718055@sss.pgh.pa.us> <12290.1541719635@sss.pgh.pa.us> From: Konstantin Knizhnik Message-ID: <188663b1-3392-2e2a-0f41-cf1e1e3200ae@postgrespro.ru> Date: Fri, 9 Nov 2018 19:08:58 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <12290.1541719635@sss.pgh.pa.us> 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 09.11.2018 2:27, Tom Lane wrote: > I wrote: >> The bigger picture here, and the reason for my skepticism about having >> any intelligence in the enabling logic, is that there is no scenario >> in which this code can be smarter than the user about what to do. >> We have no insight today, and are unlikely to have any in future, about >> whether a specific index expression is many-to-one or not. > Hmm ... actually, I take that back. Since we're only interested in this > for expression indexes, we can expect that statistics will be available > for the expression index, at least for tables that have been around > long enough that UPDATE performance is really an exciting topic. > So you could imagine pulling up the stadistinct numbers for the index > column(s) and the underlying column(s), and enabling the optimization > when their ratio is less than $something. Figuring out how to merge > numbers for multiple columns might be tricky, but it's not going to be > completely fact-free. (I still think that the cost-estimate logic is > quite bogus, however.) > > Another issue in all this is the cost of doing this work over again > after any relcache flush. Maybe we could move the responsibility > into ANALYZE? > > BTW, the existing code appears to be prepared to enable this logic > if *any* index column is an expression, but surely we should do so > only if they are *all* expressions? > > regards, tom lane From my point of view "auto" value should be default, otherwise it has not so much sense. If somebody decides to switch on this optimization for some particular index, then it will set it to "on", not "auto". So I agree with your previous opinion, that if this optimization is disabled by default, then it is enough to have boolean parameter. Concerning muticolumn indexes: why we should apply this optimization only if *all* of index columns are expressions? Assume very simple example: we have some kind of document storage represented by the following table:      create table document(owner integer, name text, last_updated timestamp, description json); So there are some static document attributes (name, date,...) and some dynamic, stored in json field. Consider that most frequently users will search among their own documents. So we may create index like this:      create index by_title on documents(owner,(description->>'title')); Document description may include many attributes which are updated quite frequently, like "comments", "keywords",... But "title" is rarely changed, so this optimization will be very useful for such index. -- Konstantin Knizhnik Postgres Professional: http://www.postgrespro.com The Russian Postgres Company