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.89) (envelope-from ) id 1j0PuA-0002vN-Al for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Feb 2020 13:12:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j0Pu7-0003E2-1N for pgsql-hackers@arkaria.postgresql.org; Sat, 08 Feb 2020 13:12:11 +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 ) id 1j0Pu6-0003Bu-G5 for pgsql-hackers@lists.postgresql.org; Sat, 08 Feb 2020 13:12:10 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j0Pu3-0003PJ-I9 for pgsql-hackers@postgresql.org; Sat, 08 Feb 2020 13:12:08 +0000 Received: by mail-wr1-x441.google.com with SMTP id w15so2080039wru.4 for ; Sat, 08 Feb 2020 05:12:07 -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=GsvWdGgYYpuIKKxwMvrrPMPTz0VhdiIz1U9XDKae0sE=; b=aWwgl7/5Zcs2KMTR9HKgEYfbi9d8JWb44xqYhWB+9DmPrUlz0ZsxEMusE2ZQrFalTy Sokz8LYE97zkRabqteLmDZuGs1b1eB/xjdUi1CjHp9UwyexUufir148XfqcDN5FJTlIK NDjxIozciLb5KTInTQ3LFPE7n9mZc1P1Wr/aCBMeLbBPSVfJwRYRb1N5FD474vmmRzzb fhyIXKmReT7R9pfB3y328D1PEwC10STQsW24PMzwleWjWRZM668w6J4WPYxMeOqY3L8b F4lJwObBhvkyGE/58SHOkKqKYZ9QZqadj7z4OIVbAC0GoFZFFe8ep0MHTRGg3DbmnlO7 yf5A== 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=GsvWdGgYYpuIKKxwMvrrPMPTz0VhdiIz1U9XDKae0sE=; b=gaz6cZ7KFld7BOxq4wrnYdNr3YLPpaKXIjyrY7peBqBVW42UqPSh4RB94EZtGmrelf X7irTglhaLDZ1v9Eg0NZj7kk8F+hbFeD9cAmqj/VsN2ysRVtDRkY1wxDa/zVR+yMbtm+ MN/7C8KEQAqXvrDnDIFcaVlK8vOFlziyETRhrB4i4lAzFqzOtWOsRW0nzIGX9FRGz4c4 y5joL+LgdzoXlTJU8ToQp8P6rw3ac4lOTygP0z+u9C045LYno/ElWnj7knahX2ZYf+5o Vqkl38+aUyIhRt3Vpi7El2+o4tZtaiwSzQTfhKNNzHsLgaGytgZpmzY4qKitGbeqrmQ/ Y2sA== X-Gm-Message-State: APjAAAUucY2uCfOev4yDa96+B5Ea3RrJv3ZRKxSPRDiDPbhpKzL9kILS rbM6EJ69/q6uzsG5TRuF5OHYkg== X-Google-Smtp-Source: APXvYqyjst+M0W/Qs8vQmXdZuIwUf88QSCOZgO0cpHk5BtTUXCYFlQH8Gpsht5LyuHODqF78v1nDyQ== X-Received: by 2002:a5d:558c:: with SMTP id i12mr5255117wrv.315.1581167526131; Sat, 08 Feb 2020 05:12:06 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id 133sm7891595wme.32.2020.02.08.05.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2020 05:12:04 -0800 (PST) Date: Sat, 8 Feb 2020 14:11:59 +0100 From: Tomas Vondra To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Kyotaro Horiguchi , florisvannee@optiver.com, pg@bowt.ie, jesper.pedersen@redhat.com, david.rowley@2ndquadrant.com, alvherre@2ndquadrant.com, thomas.munro@gmail.com, jtc331@gmail.com, rafia.pghackers@gmail.com, jeff.janes@gmail.com, bhushan.uparkar@gmail.com, pgsql-hackers@postgresql.org, a.korotkov@postgrespro.ru Subject: Re: Index Skip Scan Message-ID: <20200208131159.5sjcbcjnwdj4q7fa@development> References: <20200205163730.eqvoxh6eb3do52r5@localhost> <20200206.102450.1514793516830965023.horikyota.ntt@gmail.com> <20200206105707.fuidmdsi6oapieoz@localhost> <20200206.212220.642002310227620136.horikyota.ntt@gmail.com> <20200207162543.zlj2tvcwy7jku6vu@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200207162543.zlj2tvcwy7jku6vu@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Feb 07, 2020 at 05:25:43PM +0100, Dmitry Dolgov wrote: >> On Thu, Feb 06, 2020 at 09:22:20PM +0900, Kyotaro Horiguchi wrote: >> At Thu, 6 Feb 2020 11:57:07 +0100, Dmitry Dolgov <9erthalion6@gmail.com> wrote in >> > > On Thu, Feb 06, 2020 at 10:24:50AM +0900, Kyotaro Horiguchi wrote: >> > > At Wed, 5 Feb 2020 17:37:30 +0100, Dmitry Dolgov <9erthalion6@gmail.com> wrote in >> > > We could add an additional parameter "in_cursor" to >> > > ExecSupportBackwardScan and let skip scan return false if in_cursor is >> > > true, but I'm not sure it's acceptable. >> > >> > I also was thinking about whether it's possible to use >> > ExecSupportBackwardScan here, but skip scan is just a mode of an >> > index/indexonly scan. Which means that ExecSupportBackwardScan also need >> > to know somehow if this mode is being used, and then, since this >> > function is called after it's already decided to use skip scan in the >> > resulting plan, somehow correct the plan (exclude skipping and try to >> > find next best path?) - do I understand your suggestion correct? >> >> I didn't thought so hardly, but a bit of confirmation told me that >> IndexSupportsBackwardScan returns fixed flag for AM. It seems that >> things are not that simple. > >Yes, I've mentioned that already in one of the previous emails :) The >simplest way I see to achieve what we want is to do something like in >attached modified version with a new hasDeclaredCursor field. It's not a >final version though, but posted just for discussion, so feel free to >suggest any improvements or alternatives. IMO the proper fix for this case (moving forward, reading backwards) is simply making it work by properly checking deleted tuples etc. Not sure why that would be so much complex (haven't tried implementing it)? I think making this depend on things like declared cursor etc. is going to be tricky, may easily be more complex than checking deleted tuples, and the behavior may be quite surprising. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services