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 1jBe9m-0001rU-Tz for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2020 12:38:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jBe9l-0001ZX-ND for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2020 12:38:45 +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 1jBe9l-0001ZQ-BA for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2020 12:38:45 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jBe9j-0007S2-7P for pgsql-hackers@postgresql.org; Tue, 10 Mar 2020 12:38:44 +0000 Received: by mail-wm1-x343.google.com with SMTP id 6so1210379wmi.5 for ; Tue, 10 Mar 2020 05:38:42 -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=pG4UWQyfArACk1utf5162VWgZ4XqxKVM2OZKOiLEVsE=; b=F2uwWP1CQwXFeCJXQmcnOuJ++lG2XVwUsaanKUhdga7zHr7AyT+OZMlnwRLi5SwYUR Za/e2I0dkKNz8fLirbJsRJ3NmYG3MzPDMyDW/JJ737ciCg/R0lMjdZHsGwLDpNzP0Rh4 LP/6JnqYgpUtn9Gkd6oSf7J2lWbIvqI0BndIVC+sBCxBeG66hSUUPIH4+9IaCpC6q2xI yzvSuP2K0bQ9Bd3by1EzMqrLTP3v92U8wYtjqZMMJvtLb64Wa8qUEoxoiPAGSaim59e2 53nCW6U5ibJzoUiHhGTiFIDRJBRd4EspjAewkYLeRKZEADD/LWgXvsm2D5Wy3lxTm+s4 AM4w== 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=pG4UWQyfArACk1utf5162VWgZ4XqxKVM2OZKOiLEVsE=; b=rAnyBms4rAPYMN49/cRGAHXrPZJErO8dN0dq7eFdhVTK33pJdXKO70ZBOTejrQxU7C SW8tt7rWsTme3c0n5anGCbVNWemP4GfsXNM5vUBeCuzDN/7vCbq7TDXZ7aKBBIa9fiph 0WE+txWs00mA79CIXch6jdCZAACAAI7CCvKG6YpMoSfLTYeiJNP60WSucJ/zkCcFuoOR XA9FSfGS8BP0ozgYf3upqfIosQ9rGCeObSD1Z7RfBrIRYcHm1yBkbMK2OBHJsy43Ncr5 yipvSN+ctV1k2W+jGfp/z1BP5m2fXOapCYB2os7YfBNiwldcVI7rxTGdZ8pD6t5iqcjI MmTQ== X-Gm-Message-State: ANhLgQ2Xm2HXz+jno5gmhKjrDq+jeAtvPDuRvV16ZKTwIgRPJR2pVTER Qr2lRnRRdca9HCn8YEG7Xvs= X-Google-Smtp-Source: ADFU+vt/tEtSGp5LQR+iRM+sIvfrqMqciXSG1r5OZWrKMdoQtKxIK0xhWAavQ/jJbCJxkfNT/ZrRQQ== X-Received: by 2002:a7b:cc6a:: with SMTP id n10mr2044462wmj.170.1583843921693; Tue, 10 Mar 2020 05:38:41 -0700 (PDT) Received: from localhost ([185.85.220.198]) by smtp.gmail.com with ESMTPSA id w4sm14699759wrl.12.2020.03.10.05.38.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2020 05:38:40 -0700 (PDT) Date: Tue, 10 Mar 2020 13:39:42 +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: <20200310123942.nse4uyd6yqtb7uyi@localhost> References: <20200207162543.zlj2tvcwy7jku6vu@localhost> <20200208131159.5sjcbcjnwdj4q7fa@development> <20200214.172313.259958375378013155.horikyota.ntt@gmail.com> <20200214121820.xvvrkdbykkygfs65@localhost> <20200217162451.nrpy5k63f5y2mwm6@localhost> <20200308142228.3zb237cd3oedspl2@localhost> <20200309195714.eum3b6e5mogqj3gm@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 Tue, Mar 10, 2020 at 09:29:32AM +1300, David Rowley wrote: > On Tue, 10 Mar 2020 at 08:56, Dmitry Dolgov <9erthalion6@gmail.com> wrote: > > Assuming we'll implement it in a way that we do not know about what kind > > of path type is that in create_distinct_path, then it can also work for > > ProjectionPath or anything else (if UniqueKeys are present). But then > > still EquivalenceMember are used only to figure out correct > > distinctPrefixKeys and do not affect whether or not skipping is applied. > > What do I miss? > > I'm not sure I fully understand the question correctly, but let me > explain further. > > In the 0001 patch, standard_qp_callback sets the query_uniquekeys > depending on the DISTINCT / GROUP BY clause. When building index > paths in build_index_paths(), the 0002 patch should be looking at the > root->query_uniquekeys to see if it can build any index paths that > suit those keys. Such paths should be tagged with the uniquekeys they > satisfy, basically, exactly the same as how pathkeys work. Many > create_*_path functions will need to be modified to carry forward > their uniquekeys. For example, create_projection_path(), > create_limit_path() don't do anything which would cause the created > path to violate the unique keys. This way when you get down to > create_distinct_paths(), paths other than IndexPath may have > uniquekeys. You'll be able to check which existing paths satisfy the > unique keys required by the DISTINCT / GROUP BY and select those paths > instead of having to create any HashAggregate / Unique paths. > > Does that answer the question? Hmm... I'm afraid no, this was already clear. But looks like now I see that I've misinterpreted one part. > 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: I've read it as "an assumption that an EquivalenceMember can only be a Var" results in "the optimisation not working in cases like this". But you've meant that ignoring a ProjectionPath with an IndexPath inside results in this optimisation not working, right? If so, then everything is clear, and my apologies, maybe I need to finally fix my sleep schedule :)