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 1jAwpB-0006vb-SA for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Mar 2020 14:22:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAwoB-0008DD-Rj for pgsql-hackers@arkaria.postgresql.org; Sun, 08 Mar 2020 14:21:35 +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 <9erthalion6@gmail.com>) id 1jAwoB-0008D6-GJ for pgsql-hackers@lists.postgresql.org; Sun, 08 Mar 2020 14:21:35 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jAwo7-0000sd-U4 for pgsql-hackers@postgresql.org; Sun, 08 Mar 2020 14:21:34 +0000 Received: by mail-ed1-x544.google.com with SMTP id a13so8852513edh.3 for ; Sun, 08 Mar 2020 07:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YQZ8xgJlaFZc78Ajdcoz6/+RT3h9CqPTXkmFzu2vl28=; b=Tx6MAGTdrCNnAQO9toN2fOF5YZz/MLo7m+h1cCpWRJHzmx2cjh8eBCQJSQ4BkW6Nu3 V5lykT0ywO9H3EsU6//6gkOZopyg/kbnPpE8tHtLd3wjlkDrhqVuMUCG7sHChrwo40Tq TNSKUSa5DjOgqIKJq4Kb8hiMDCildJG4w56JxMUZko+HQ2FOvjqHyffaEACXK/Z8z8aj JAr8bkUPXO8FyrtVF7LNOblHcwIq9nKhXgh/AwlnuTpvXS52frj+PWwdIGRPQiu7OkQo r0uPXmZMK8kRYY/piWC5oqDNPATkNp9YFJT1XjY4zD2b0/nhYqUpAF4TUTcxYBFUpOuU JX+Q== 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=YQZ8xgJlaFZc78Ajdcoz6/+RT3h9CqPTXkmFzu2vl28=; b=oV0rZ2rUUPTjutU4lQmUe2nyhk4jmJFWycNwgBDZgOD0F0sQgYpDcJQ+mbTnGDKIM1 qTuZ3z13BKz3qzpyolTEoQeIPTFSqJHUqqwdjZSllNPS3tZCFpYaVxJJASUN14SGaFJQ 5mkQi0zhwuCF6wPZGuBx1a5EhaIdmLmC89fL6vnGzqpnfBNNwXDPZitK/BtRr94uOE6s EE1ILYyz4x5zlI1wq6FYr9gtntkyc4yuFU9JfzOIOn26YTXCnKQBUnBPzegZ8AoiF2Jh cm99pc1jWGyT06P0ZwTsHHJm2Lnkg7TZe11dzX+X0KbiS+9TtAkmXAL5ThJdqhD2LfBi ySoA== X-Gm-Message-State: ANhLgQ1ZzhYKNQLsS0b40XBqdtFM+2HtuNV0KsPFxd3e+9FnZ22hnMVF UMsAro3LsRH/TpgpDqGQZi8= X-Google-Smtp-Source: ADFU+vscBUVmUW6leLs/yAYKkhGIgHEDLHCyNy8gPwOWCuPjlwf/IfHMVbMb5UfnnfYWiTsA6H1e3w== X-Received: by 2002:aa7:c842:: with SMTP id g2mr13272104edt.234.1583677290546; Sun, 08 Mar 2020 07:21:30 -0700 (PDT) Received: from localhost (dslb-094-222-004-201.094.222.pools.vodafone-ip.de. [94.222.4.201]) by smtp.gmail.com with ESMTPSA id q20sm941847ejx.5.2020.03.08.07.21.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Mar 2020 07:21:29 -0700 (PDT) Date: Sun, 8 Mar 2020 15:22:28 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: David Rowley Cc: Kyotaro Horiguchi , Tomas Vondra , 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: <20200308142228.3zb237cd3oedspl2@localhost> 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 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: > > I've been looking over v32 of the patch and have a few comments > regarding the planner changes. Thanks for the commentaries! > 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. Just for me to clarify. The idea is to "move" information about what path types support skipping into UniqueKeys (derived from PlannerInfo's query_uniquekeys), but other checks (e.g. if index am supports that) still perform in create_distinct_paths? > Also, should create_grouping_paths() be getting the same code? > Jesper's UniqueKey patch seems to set query_uniquekeys when there's a > GROUP BY with no aggregates. So it looks like he has intended that > something like: > > SELECT x FROM t GROUP BY x; > > should work the same way as > > SELECT DISTINCT x FROM t; > > but the 0002 patch does not make this work. Has that just been overlooked? I believe it wasn't overlooked in 0002 patch, but rather added just in case in 0001. I guess there are no theoretical problems in implementing it, but since we wanted to keep scope of the patch under control and concentrate on the existing functionality it probably makes sense to plan it as one of the next steps? > There's also some weird looking assumptions that an EquivalenceMember > can only be a Var in create_distinct_paths(). I think you're only > saved from crashing there because a ProjectionPath will be created > atop of the IndexPath to evaluate expressions, in which case you're > not seeing the IndexPath. This results in the optimisation not > working in cases like: > > postgres=# create table t (a int); create index on t ((a+1)); explain > select distinct a+1 from t; > CREATE TABLE > CREATE INDEX > QUERY PLAN > ----------------------------------------------------------- > HashAggregate (cost=48.25..50.75 rows=200 width=4) > Group Key: (a + 1) > -> Seq Scan on t (cost=0.00..41.88 rows=2550 width=4) Yes, I need to fix it. > Using unique paths as I mentioned above should see that fixed. I'm a bit confused about this statement, how exactly unique paths should fix this?