Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNG20-00022F-MU for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Nov 2018 11:41:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gNG1x-0004nH-Rk for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Nov 2018 11:41:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNG1x-0004Mm-AM for pgsql-hackers@lists.postgresql.org; Thu, 15 Nov 2018 11:41:53 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gNG1p-0008TN-BW for pgsql-hackers@postgresql.org; Thu, 15 Nov 2018 11:41:51 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 323E821C770F; Thu, 15 Nov 2018 14:41:42 +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.182] (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 E177321C770D; Thu, 15 Nov 2018 14:41:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1542282102; bh=PNdu9RM+VFl3NX9oHKpz084YnC6CsNFKpbWVhl2oN/k=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=PP5smFh4Ykv8/DMCxYSevNwXpWbtAPDKuBoWNIVsLAaEoHaHtBv/fke5K6OHaAC5U 8MaS9IJQ6sm2LwF4188owGbYngvWNCDn5QrCyEr6VhgMwvZAXfc+qt9JAsoBzB3Pln FjPAY1z3KlzC3pC/sCyzmGUxjq0lWY32PWeL5+L0= Subject: Re: Index Skip Scan To: jesper.pedersen@redhat.com, Dmitry Dolgov <9erthalion6@gmail.com> Cc: pg@bowt.ie, Thomas Munro , Bhushan Uparkar , PostgreSQL-development , Alexander Korotkov References: <707b6f68-16fa-7aa7-96e5-eeb4865e6a30@redhat.com> <89F84E17-D684-4717-B66F-0F05CB00168E@gmail.com> <522092c7-3cb7-a1ec-410b-dfa97ae722f3@postgrespro.ru> <11b7c9d1-ae00-4385-97b2-fcd45f0a1a71@redhat.com> <3cfd317e-2a8b-8681-0833-8f2ead3af4d4@postgrespro.ru> From: Alexander Kuzmenkov Message-ID: Date: Thu, 15 Nov 2018 14:41:41 +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: 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 9/27/18 16:59, Jesper Pedersen wrote: > Hi Dmitry, > > On 9/15/18 3:52 PM, Dmitry Dolgov wrote: >>> On Thu, 13 Sep 2018 at 21:36, Alexander Kuzmenkov >>> wrote: >>> El 13/09/18 a las 18:39, Jesper Pedersen escribió: >>>> I think we can improve this, >>>> and the skip scan can be strictly faster than index scan regardless of >>>> the data. >>>> <...> >>>> >>> >>> This is something to look at -- maybe there is a way to use >>> btpo_next/btpo_prev instead/too in order to speed things up. Atm we >>> just >>> have the scan key in BTScanOpaqueData. I'll take a look after my >>> upcoming vacation; feel free to contribute those changes in the >>> meantime >>> of course. >> >> But having this logic inside _bt_next means that it will make a >> non-skip index >> only scan a bit slower, am I right? > > Correct. Well, it depends on how the skip scan is implemented. We don't have to make normal scans slower, because skip scan is just a separate thing. My main point was that current implementation is good as a proof of concept, but it is inefficient for some data and needs some unreliable planner logic to work around this inefficiency. And now we also have execution-time fallback because planning-time fallback isn't good enough. This looks overly complicated. Let's try to design an algorithm that works well regardless of the particular data and doesn't need these heuristics. It should be possible to do so for btree. Of course, I understand the reluctance to implement an entire new type of btree traversal. Anastasia Lubennikova suggested a tweak for the current method that may improve the performance for small groups of equal values. When we search for the next unique key, first check if it is contained on the current btree page using its 'high key'. If it is, find it on the current page. If not, search from the root of the tree like we do now. This should improve the performance for small equal groups, because there are going to be several such groups on the page. And this is exactly where we have the regression compared to unique + index scan. By the way, what is the data for which we intend this feature to work? Obviously a non-unique btree index, but how wide are the tuples, and how big the equal groups? It would be good to have some real-world examples. -- Alexander Kuzmenkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company