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 1jBOVi-00019T-9Q for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2020 19:56:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jBOVg-000418-Hi for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2020 19:56:20 +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 <9erthalion6@gmail.com>) id 1jBOVg-000411-2i for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2020 19:56:20 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jBOVd-0007wy-HV for pgsql-hackers@postgresql.org; Mon, 09 Mar 2020 19:56:18 +0000 Received: by mail-wm1-x341.google.com with SMTP id a132so875314wme.1 for ; Mon, 09 Mar 2020 12:56:17 -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=HIbY8SWZ7c6AD9AUt0AEh4t53uw3rLUK4EieA65JF6A=; b=FcLR0CRaZXyFTGxx/ClVYbrIDQspRFzEuPqTLJQQgWpQt6MH+h61k0JXSqqNSFXogD xMB8HoYGz76c/pW+CR/Lafk5UwmAsd8j21c7HjrlbRtwCgcPuSxbTmsyBJ+5fAyDTorZ rGclh6fOYXfjjS2iYmBe22hrjpkJ2Qlw2aYn/UCdyS2n47rSo7B5nncBdK10aKG5Kasy jnUhLsM7PAaEClSaWpkTxNRnQPGqqIcR5UaNXHSLrpkvfqL5dt6dKSAU4ZfZR/HHoUJR IU+1XiguTeFDRlJwlnw8npFkYLRs14IUl0Hux1JnaoQNdLrfc4BBSGtyw4YRWToZR3J9 O5Aw== 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=HIbY8SWZ7c6AD9AUt0AEh4t53uw3rLUK4EieA65JF6A=; b=VImkMnKC0Ak/+URo3gdw1lvs2/gOAXkadCKEKSqIED2QLBodknB9bPwku+PLade0WV j25RbMSYku7mV1aPqV0WSJN3WVMHbCv7U+D54MoNRnbM2Lkel4PlsnFt25uDjSSIG93o ylQdqy96gB4COCuORj+gs0vACdtoBkcfv0Y1QmwsThtTnB4bNgLIlXLtwK5SM8lpcI7K 7oqnRTJXSZGx17uWwo9HB4PYglYQnH20kHR27aEcMheph+L2VyXNTxjC2iQlvTPSm4l5 IcLdpPb7vP+YxMXUa+CgT3zcbX/m6mDrmzHiN4JcFteeHLDXHwEjetl2ouRAqTC1P6XM Uh8A== X-Gm-Message-State: ANhLgQ1vB4FF35rC1PDl/oeNZT745QT5ujFmIgwhJOOEsd2gaptzdzfv ouSU5aFTRNV0Rar2v692W1U= X-Google-Smtp-Source: ADFU+vs7DXndDGUxixoCt2AA9bMexnE9usYaB8cWGHGlv86fEIR/lWHcL3n4ms4M9dbogQUzkZz8iA== X-Received: by 2002:a05:600c:248:: with SMTP id 8mr499700wmj.182.1583783775406; Mon, 09 Mar 2020 12:56:15 -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 o10sm15771926wru.38.2020.03.09.12.56.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Mar 2020 12:56:14 -0700 (PDT) Date: Mon, 9 Mar 2020 20:57:14 +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: <20200309195714.eum3b6e5mogqj3gm@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> <20200308142228.3zb237cd3oedspl2@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 Mon, Mar 09, 2020 at 10:27:26AM +1300, David Rowley wrote: > > > > 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? > > create_distinct_paths() shouldn't know any details specific to the > pathtype that it's using or considering using. All the details should > just be in Path. e.g. uniquekeys, pathkeys, costs etc. There should be > no IsA(path, ...). Please have a look over the details in my reply to > Tomas. I hope that reply has enough information in it, but please > reply there if I've missed something. Yes, I've read this reply, just wanted to ask here, since I had other questions as well. Speaking of which: > > > On Wed, Mar 04, 2020 at 11:32:00AM +1300, David Rowley wrote: > > > 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. I'm probably missing something, so to eliminate any misunderstanding from my side: > > > 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) In this particular example skipping is not applied because, as you've mentioned, we're dealing with ProjectionPath (not IndexScan / IndexOnlyScan). Which means we're not even reaching the code with EquivalenceMember, so I'm still not sure how do they connected? 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?