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 1izepo-00020z-7E for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Feb 2020 10:56:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1izepm-0005X6-T5 for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Feb 2020 10:56:34 +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 1izepm-0005Wy-Hf for pgsql-hackers@lists.postgresql.org; Thu, 06 Feb 2020 10:56:34 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1izepk-0005U6-UO for pgsql-hackers@postgresql.org; Thu, 06 Feb 2020 10:56:34 +0000 Received: by mail-wm1-x341.google.com with SMTP id a5so5806444wmb.0 for ; Thu, 06 Feb 2020 02:56:32 -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=YS0MlZ65KWLMt7a9LA4e1GnK1MOmtw/ZTnuyF9Q9iso=; b=uOU+LLhPmzXHnyUxhimzi0lwRip375yBF910fcPDhqiRWcUJYpSSXpWnqY9Q5SRH5Z SPBGYmuQw7aQBkL8yVDfcXQ2EHDdo43GlXodrcP/jn4o1wa0WmMfncUSjGH5eAoDxdRn 7KEzrqhCMtjLsDHAhA7kc19klwP6o0V+RllDvyoB7CpBNXNsHfYUkKwTHzXeQRCdAQ0n oxEkv8WWnOpYxtzx5sBOmqZsQqIfZu0Dt33YGjtGIXahd73xT43jy+i3H+MLcz5KxzBr kXyDmkgzdOWLbE+n8o4+327e8cWy19aAptwmAZlxyA+2WVxRmbH4pcY9//QOGVoNRDZy CWnw== 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=YS0MlZ65KWLMt7a9LA4e1GnK1MOmtw/ZTnuyF9Q9iso=; b=UdGQfCYivQujiWJYzxATEfef83ld854Q4U3yOh+ySl1erog4sk8MisytZrUzZaPyqL /IwDI6YZeBCHjilezGqekM+2CS8AbmLb9gudehQtIvV81fadcDUzUqkfWL6PKo5MqVcF ts8x9yPJqKZb3Oy2l974SrVwmJ7zc16mgN1c7c/0S/Fcf961IZGcwticUAZR16xkDTsS ANd5WKTkDXp5kU9Ej82eSW+z9p8Ic//fBwOmoIbjOuFrf2fViKH31M4qKoj19zVWWG2o wHwJ3g0Y7cMr34DhE/RexI0Bz4HUYK/0tF45rYWUPygJ7T7gqdNMr0jv6g4X6PtAH3GK R9ag== X-Gm-Message-State: APjAAAWhUwuUI4B+lwfkfTHZaUTr0G9BjKR7s5oqDofZ9z5g0sboGRSj GTX4SATvGkc4VOS0MjjqSjQ= X-Google-Smtp-Source: APXvYqxKU50tgmzP8JNmhgKUld9urrO/srwZX6kmHQmqxK8IrkZA8MOlU+80hfAYYiM3RFrTqCPPyA== X-Received: by 2002:a05:600c:217:: with SMTP id 23mr3887986wmi.124.1580986591870; Thu, 06 Feb 2020 02:56:31 -0800 (PST) Received: from localhost ([185.85.220.201]) by smtp.gmail.com with ESMTPSA id z19sm3066837wmi.35.2020.02.06.02.56.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Feb 2020 02:56:31 -0800 (PST) Date: Thu, 6 Feb 2020 11:57:07 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Kyotaro Horiguchi Cc: florisvannee@Optiver.com, pg@bowt.ie, jesper.pedersen@redhat.com, david.rowley@2ndquadrant.com, tomas.vondra@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: <20200206105707.fuidmdsi6oapieoz@localhost> References: <20200204200205.ip5c2mzy3i2okqey@localhost> <5be025f30d8e45cda167c58b5d5e72d2@opammb0561.comp.optiver.com> <20200205163730.eqvoxh6eb3do52r5@localhost> <20200206.102450.1514793516830965023.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200206.102450.1514793516830965023.horikyota.ntt@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > 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 > > > On Tue, Feb 04, 2020 at 08:34:09PM +0000, Floris Van Nee wrote: > > > > > > > this point me and Jesper inclined to go with the second option. But maybe > > > > I'm missing something, are there any other suggestions? > > > > > > Unfortunately I figured this would need a more invasive fix. I tend to agree that it'd be better to not skip in situations like this. I think it'd make most sense to make any plan for these 'prepare/fetch' queries would not use skip, but rather a materialize node, right? > > > > Yes, sort of, without a skip scan it would be just an index only scan > > with unique on top. Actually it's not immediately clean how to achieve > > this, since at the moment, when planner is deciding to consider index > > skip scan, there is no information about neither direction nor whether > > we're dealing with a cursor. Maybe we can somehow signal to the decision > > logic that the root was a DeclareCursorStmt by e.g. introducing a new > > field to the query structure (or abusing an existing one, since > > DeclareCursorStmt is being processed by standard_ProcessUtility, just > > for a test I've tried to use utilityStmt of a nested statement hoping > > that it's unused and it didn't break tests yet). > > Umm. I think it's a wrong direction. While defining a cursor, > default scrollability is decided based on the query allows backward > scan or not. That is, the definition of backward-scan'ability is not > just whether it can scan from the end toward the beginning, but > whether it can go back and forth freely or not. In that definition, > the *current* skip scan does not supporting backward scan. If we want > to allow descending order-by in a query, we should support scrollable > cursor, too. > > 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?