Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1klbm5-00035E-Ih for pgsql-hackers@arkaria.postgresql.org; Sat, 05 Dec 2020 17:55:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1klblX-0003Mx-Sb for pgsql-hackers@arkaria.postgresql.org; Sat, 05 Dec 2020 17:54:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1klblX-0003Mq-Jx for pgsql-hackers@lists.postgresql.org; Sat, 05 Dec 2020 17:54:39 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1klblS-0000mN-6l for pgsql-hackers@postgresql.org; Sat, 05 Dec 2020 17:54:38 +0000 Received: by mail-ed1-x532.google.com with SMTP id dk8so6410324edb.1 for ; Sat, 05 Dec 2020 09:54:33 -0800 (PST) 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=fUWc9W4a40amGc2qIQHND3tbQhPdkDzBZRS6WaouQwc=; b=rU9P8MhtrGo7ZwHsntw2F56q54GYnpTg4zOYUHFPqrR16bwgj8D8KF1CQAsVuPAx3Z 92wH4wepykMSUXr7gRPa/xd8LMbQ8taqHeytV7QVcRpq1V2FwiskRi5iZvEkfp5LfbFB Uvx4rrK5heRvetQ0i2HHG9URWim0MT7nIlWntDKprXtYwjM6nb+ETx4Kv5r9pDPmN9b7 7uwkP1LprQiyL1caV1Zg+lH/rEOCEChHrQy61YLIAdqkEReoMS+Kdk2Z/3BrATe7qe3T OZ72McJ6bweLjJFMh7hwsAe9dl6sIFLDJ2gSqcjarIkC8YOwf+TfTY2h83imQXCV5KVj 0scg== 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=fUWc9W4a40amGc2qIQHND3tbQhPdkDzBZRS6WaouQwc=; b=b/gZsVXy1olrv50Mb83g1Jq6OpRz+cqdOr3nu5x+IOLKbX0cqi7XGenOMV0/MYcRkw e7MvcvjuvAsjgkUgS51guUkgBRZqKABzZAHs52U9Za6x+CowCkjygNCdpKU3/XNSdNKL T8/Ns8z/mdOp4N6kiMg7w6BEdOelWgItz4SQhnHffrTxwUpOT+AiwfMzINO0+gqinI+Y t2N36Zj+LQCiu0P3eWepgs/CFX8XfkGdAO4tKwL/2/kbZ1wwOPijwA0ZvFNYnLl83Hpj 4n29ImGc5eg/j3y/LadUsuhPL6tliHGDwJ8KP/qlVpgVX3Eu6CcMJQjPqCrhD9F3T8It BivA== X-Gm-Message-State: AOAM533ZloyangHjrd+HMP58qahWU23G5A7zQfXiiHHTOTlMZd7O4+6e gAHd16qPIssXOTtc6KZN5iw= X-Google-Smtp-Source: ABdhPJwEkT7NC21k9AyN0PgPl6rnWVlgCM5fjimbMr+404h3ji1B8onQG36KYSmhxP1Gz/rv+gWGPA== X-Received: by 2002:a50:a444:: with SMTP id v4mr13441362edb.175.1607190871737; Sat, 05 Dec 2020 09:54:31 -0800 (PST) Received: from localhost (dslb-094-222-016-204.094.222.pools.vodafone-ip.de. [94.222.16.204]) by smtp.gmail.com with ESMTPSA id p35sm6355872edd.58.2020.12.05.09.54.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Dec 2020 09:54:30 -0800 (PST) Date: Sat, 5 Dec 2020 18:55:42 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Heikki Linnakangas Cc: Peter Geoghegan , PostgreSQL-development , Jesper Pedersen , David Rowley , Floris Van Nee , Kyotaro Horiguchi , Thomas Munro , Tomas Vondra , Andy Fan , Dilip Kumar Subject: Re: Index Skip Scan (new UniqueKeys) Message-ID: <20201205175542.fqrhbhp3co7cgvkj@localhost> References: <20200711161258.5modwkdeszhf55ux@localhost> <20200727102431.mjspwec4yhzeyny2@localhost> <20200815141240.wuyc6ijkmnywywtn@localhost> <20201006152039.xs2ul7il52sowhlu@localhost> <20201024164553.tel5uynf2dzyh4az@localhost> <598ff988-5ebb-f6f7-0c9d-82208dff3bbd@iki.fi> <20201201202119.jcsr7z6cdiffuops@localhost> <6020ad2b-357f-da90-de7b-60b79452fc66@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6020ad2b-357f-da90-de7b-60b79452fc66@iki.fi> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Tue, Dec 01, 2020 at 10:59:22PM +0200, Heikki Linnakangas wrote: > > > > - Does this optimization apply to bitmap index scans? > > > > No, from what I understand it doesn't. > > Would it be hard to add? Don't need to solve everything in the first > version of this, but I think in principle you could do the same > optimization for bitmap index scans, so if the current API can't do it, > that's maybe an indication that the API isn't quite right. I would expect it should not be hard as at the moment all parts seems relatively generic. But of course I need to check, while it seems no one had bitmap index scans in mind while developing this patch. > > > I'm actually a bit confused why we need this condition. The IndexScan > > > executor node should call amskip() only after checking the additional quals, > > > no? > > > > This part I don't quite get, what exactly you mean by checking the > > additional quals in the executor node? But at the end of the day this > > condition was implemented exactly to address the described issue, which > > was found later and added to the tests. > > As I understand this, the executor logic goes like this: > > query: SELECT DISTINCT ON (a, b) a, b FROM foo where c like '%y%' and a > like 'a%' and b = 'b'; > > 1. Call index_beginscan, keys: a >= 'a', b = 'b' > > 2. Call index_getnext, which returns first row to the Index Scan node > > 3. Evaluates the qual "c like '%y%'" on the tuple. If it's false, goto step > 2 to get next tuple. > > 4. Return tuple to parent node > > 5. index_amskip(), to the next tuple with a > 'a'. Goto 2. > > The logic should work fine, even if there are quals that are not indexable, > like "c like '%y'" in the above example. So why doesn't it work? What am I > missing? To remind myself how it works I went through this sequence, and from what I understand the qual "c like '%y%'" is evaluated in this case in ExecQual, not after index_getnext_tid (and values returned after skipping are reported as filtered out). So when it comes to index_skip only quals on a & b were evaluated. Or did you mean something else? Another small detail is that in the current implementation there is no goto 2 in the last step. Originally it was like that, but since skipping return an exact position that we need there was something like "find a value, then do one step back so that index_getnext will find it". Unfortunately this stepping back part turns out to be a source of troubles, and getting rid of it even allowed to make code somewhat more concise. But of course I'm open for suggestions about improvements.