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.92) (envelope-from ) id 1jAEI2-0004j0-Bv for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2020 14:49:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAEI1-0005Fm-6e for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2020 14:49:25 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1jAEI0-0005Ff-Rj for pgsql-hackers@lists.postgresql.org; Fri, 06 Mar 2020 14:49:24 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jAEHx-000463-VE for pgsql-hackers@postgresql.org; Fri, 06 Mar 2020 14:49:24 +0000 Received: by mail-wr1-x442.google.com with SMTP id v9so2668276wrf.10 for ; Fri, 06 Mar 2020 06:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=OFWZq7F+YYTr7tUMagQ7fpY0UHA8XL7QqNczu+4tDBA=; b=RUFRU3tWFYmaCXuCxs3XcsAOp0hZ9k26uan3Z0yNdhCIV6gupc7uvHX3U9/2z29YJu HkTaCF09AYux4t9KjRwOWhX0gL/TKm1ZX9H7kVJoTcEn9jmBLOYMhc3pN1fwTgfqqJ2d YEWWMiSTXo+zl3gbdcrjU73Ljri7avGRHquUVStoqZ0CZAFgJa63XltBW+fQeeQpPMKv 6xlwrChLUMUXU0NLWB6IW//B6Tl3w0V2dYUYE1AS6c1is+L4mm+KJprTqZGF+zN+LRJK 5dTUmvi0lPDQsoRgfk3xAvx3cSOwBok22LLHjkLUJQlkAopNXkmSmyO4bO3nbvBXQj9F l0TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OFWZq7F+YYTr7tUMagQ7fpY0UHA8XL7QqNczu+4tDBA=; b=WgrxITr4LL4wHSh+aMA3JyGJ44qny6ki9dtKo+/OXSlXb4nXmolb5DEtW1nW0rT/o9 ukBRX4qsZYC4azWXlEZhQe3Nw9QrMGCav5x6UmfaJ+3LR+2+Mnl+juLYj7sldCyPHDeM o6SfPnnVaSj9KPiYUAU+vMaVAJRNDfeOg15nCGzmFuVEXCND7Zk0YxbzOuTSiDJQEvcw wpnGF0orVP6oFgmeTVW+IIne/jIfzaP/wkuL+HMRFrsRmVkB5SxzmoRkkvzshkRsiCDW IK0g3ci7NQ/vP2UlQkSSMvWy6P/9ybayokdF46N6hlaxynj5J76OMP7c+EmNe0pXgMFA QTFA== X-Gm-Message-State: ANhLgQ000TZfCEpM0QIt2XHfcOflAWBxp5Y954fyG0PCd2JWaRd/tV8M cjtEbw8bVDyijRy0orXLyBM/6g== X-Google-Smtp-Source: ADFU+vuy7ShkuPNMigyDUoHUKzDHfLBFCzbKgPVDi9anSLzGXAY3h/IbZ8fkbG2+2Ph3nPp4zLyruw== X-Received: by 2002:adf:f84d:: with SMTP id d13mr4510061wrq.92.1583506160330; Fri, 06 Mar 2020 06:49:20 -0800 (PST) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id y139sm14306164wmd.24.2020.03.06.06.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 06:49:19 -0800 (PST) Date: Fri, 6 Mar 2020 15:49:17 +0100 From: Tomas Vondra To: David Rowley Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Kyotaro Horiguchi , florisvannee@optiver.com, pg@bowt.ie, jesper.pedersen@redhat.com, Alvaro Herrera , thomas.munro@gmail.com, jtc331@gmail.com, rafia.pghackers@gmail.com, Jeff Janes , bhushan.uparkar@gmail.com, PostgreSQL-development , Alexander Korotkov Subject: Re: Index Skip Scan Message-ID: <20200306144917.2esaoyttgimt3lgn@development> References: <20200206.212220.642002310227620136.horikyota.ntt@gmail.com> <20200207162543.zlj2tvcwy7jku6vu@localhost> <20200208131159.5sjcbcjnwdj4q7fa@development> <20200214.172313.259958375378013155.horikyota.ntt@gmail.com> <20200214121820.xvvrkdbykkygfs65@localhost> <20200217162451.nrpy5k63f5y2mwm6@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Mar 04, 2020 at 11:32:00AM +1300, David Rowley wrote: >On Tue, 18 Feb 2020 at 05:24, Dmitry Dolgov <9erthalion6@gmail.com> wrote: >> Here is something similar to what I had in mind. > >(changing to this email address for future emails) > >Hi, > >I've been looking over v32 of the patch and have a few comments >regarding the planner changes. > >I think the changes in create_distinct_paths() need more work. The >way I think this should work is that create_distinct_paths() gets to >know exactly nothing about what path types support the elimination of >duplicate values. The Path should carry the UniqueKeys so that can be >determined. In create_distinct_paths() you should just be able to make >use of those paths, which should already have been created when >creating index paths for the rel due to PlannerInfo's query_uniquekeys >having been set. > +1 to code this in a generic way, using query_uniquekeys (if possible) >The reason it must be done this way is that when the RelOptInfo that >we're performing the DISTINCT on is a joinrel, then we're not going to >see any IndexPaths in the RelOptInfo's pathlist. We'll have some sort >of Join path instead. I understand you're not yet supporting doing >this optimisation when joins are involved, but it should be coded in >such a way that it'll work when we do. (It's probably also a separate >question as to whether we should have this only work when there are no >joins. I don't think I personally object to it for stage 1, but >perhaps someone else might think differently.) > I don't follow. Can you elaborate more? AFAICS skip-scan is essentially a capability of an (index) AM. I don't see how we could ever do that for joinrels? We can do that at the scan level, below a join, but that's what this patch already supports, I think. When you say "supporting this optimisation" with joins, do you mean doing skip-scan for join inputs, or on top of the join? >For storing these new paths with UniqueKeys, I'm not sure exactly if >we can just add_path() such paths into the RelOptInfo's pathlist. >What we don't want to do is accidentally make use of paths which >eliminate duplicate values when we don't want that behaviour. If we >did store these paths in RelOptInfo->pathlist then we'd need to go and >modify a bunch of places to ignore such paths. set_cheapest() would >have to do something special for them too, which makes me think >pathlist is the incorrect place. Parallel query added >partial_pathlist, so perhaps we need unique_pathlist to make this >work. > Hmmm, good point. Do we actually produce incorrect plans with the current patch, using skip-scan path when we should not? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services