Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5Wpk-0003jx-NL for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Sep 2018 14:00:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5Wpi-00049f-Nh for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Sep 2018 13:59:58 +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.89) (envelope-from ) id 1g5Wpi-00049Y-GX for pgsql-hackers@lists.postgresql.org; Thu, 27 Sep 2018 13:59:58 +0000 Received: from mail-qt1-f179.google.com ([209.85.160.179]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g5Wpf-0007Hx-7w for pgsql-hackers@postgresql.org; Thu, 27 Sep 2018 13:59:57 +0000 Received: by mail-qt1-f179.google.com with SMTP id x23-v6so2841305qtr.1 for ; Thu, 27 Sep 2018 06:59:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :organization:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=eiMyPXcCkfyr+6M99h0DVOGleQcXFNtpoo6S/pL5RjU=; b=UQWlGWErRR/GpJ1uWkMcUqB+hhR+WXs9azY55sQ5Aa4P8p4igleM1lxqnGhKOeegAD WZr+q+iQ0UphMAvPq1ZtmdLphj3AL9N/a+9rnQcK70FCmYrBI0Facj6ndtRFuYWtcB5p r/FTHJDd98qEuCzcDR2eLdM5NpB0AhPK5nw6kCliqKFeJkLcVsz1uysD8rsTJgWqMjT9 M4AFSRBj0bORvZC6bCGpglSzdp4H6JBb7WV6fn0zdHScckkk6YPDnMU9a/JK+fP1ujey Whi6up+HGs0/Wt6EZoFOFlX8aZhDyWPPEGG32U43LwAOvg3L2I+MTGma3/brJC62Kt+E jcDA== X-Gm-Message-State: ABuFfoi23+Zu/mfI6pGqrDzMNFWXzxaXq93bqZDQRSY7HP6A2NmFK4gz 7dbcIZh65Qm4i57V04oEyOtZMQ== X-Google-Smtp-Source: ACcGV60ccH9AUzO3Ok4defWdtVMjZW5r4VgpUozp7DqKxNVl5nQwBMYlZmy0Yka2OgsfqDQohak2xQ== X-Received: by 2002:a0c:c252:: with SMTP id w18-v6mr8359427qvh.183.1538056793034; Thu, 27 Sep 2018 06:59:53 -0700 (PDT) Received: from localhost.localdomain (c-24-61-8-151.hsd1.ma.comcast.net. [24.61.8.151]) by smtp.gmail.com with ESMTPSA id n83-v6sm877884qki.60.2018.09.27.06.59.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 06:59:51 -0700 (PDT) Reply-To: jesper.pedersen@redhat.com Subject: Re: Index Skip Scan To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: a.kuzmenkov@postgrespro.ru, 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: Jesper Pedersen Organization: Red Hat Message-ID: Date: Thu, 27 Sep 2018 09:59:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. As a first approximation, imagine that we somehow skipped >>> equal tuples inside _bt_next instead of sending them to the parent >>> Unique node. This would already be marginally faster than Unique + Index >>> scan. A more practical implementation would be to remember our position >>> in tree (that is, BTStack returned by _bt_search) and use it to skip >>> pages in bulk. This looks straightforward to implement for a tree that >>> does not change, but I'm not sure how to make it work with concurrent >>> modifications. Still, this looks a worthwhile direction to me, because >>> if we have a strictly faster skip scan, we can just use it always and >>> not worry about our unreliable statistics. What do you think? >>> >> >> 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. > Probably it would be easier and more > straightforward to go with the idea of dynamic fallback then. The first naive > implementation that I came up with is to wrap an index scan node into a unique, > and remember estimated number of groups into IndexOnlyScanState, so that we can > check if we performed much more skips than expected. With this approach index > skip scan will work a bit slower than in the original patch in case if > ndistinct is correct (because a unique node will recheck rows we returned), and > fallback to unique + index only scan in case if planner has underestimated > ndistinct. > I think we need a comment on this in the patch, as 10 * node->ioss_PlanRows looks a bit random. Thanks for your contribution ! Best regards, Jesper