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 1jIJ3e-0001Ev-HG for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2020 21:31:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jIJ2f-0006SQ-BN for pgsql-hackers@arkaria.postgresql.org; Sat, 28 Mar 2020 21:30:57 +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 ) id 1jIJ2e-0006SJ-Vt for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2020 21:30:57 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jIJ2c-00043G-3t for pgsql-hackers@lists.postgresql.org; Sat, 28 Mar 2020 21:30:56 +0000 Received: by mail-wr1-x444.google.com with SMTP id 31so16211268wrs.3 for ; Sat, 28 Mar 2020 14:30:53 -0700 (PDT) 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=3CI5fOruR8OsNxcEgqpNGbEwlrv02bPCDtkdIsk6Gb8=; b=B+C9uKAwezU0fob3iYZm9Qa5Oi9TnO4H3ek0JW4EJy390vPmDzEclV5JvgEIs+GJGH A+yqr8PWTBVammK7sD5z1xR+XjQKhrb52goSUGM+BfWCAbPl6exh8KRVlJKWkgiRC/9I nfGeldAe8ZrCk+il/cq4kOyRYkBvvanUPgB8sZ4VQugrlA4dQCYrq3XeiZiaERE7BGqj fPTGAfBQ/Uv6gyKopWdL1DvzEhVOgFU00819heq1mBoEvEHJUSPpSh1yXyiqxBD6MLoT DxIewfPF53FJlY+NU/i/KqHNieAx7GdEOQQxz2PXhJf/O+sfQSATTEamk+pd2A1eJBMc 0weA== 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=3CI5fOruR8OsNxcEgqpNGbEwlrv02bPCDtkdIsk6Gb8=; b=T7eEbMBRqL1kTnl0rxqrKCXmkbqqckFndmY1v+wPUD/dguFLbg+vBsWVhbZv5YZJCK ykH3ZiXGspiwuXbBi9mLT8KecHovcKZ8qmikpqoe2qKJhsZ2etYWMdSopsebjIdEGhWB qqFuzV7vN/SqyGsG/ViVw4QJmB+5eI9FTgeDOE1/nexcPmY10dTypfF5MB5qpcXxZc5h 7KFozeueBJj4R9xpKrL1ZLYldVFsk9rwKLAArecgcWQOm4kiuXOkZVYbkluJMIonFcmw DReIq0Sbzf2K9Mq3Cl3w3FXYaYpWYjuze8LEcDTA0QcsEqOSRaFbnoh/HhZg6WPRddZ2 qmMQ== X-Gm-Message-State: ANhLgQ35GjEDw2qvqmqqNXys9Yj8IsLiloNtgo4dV0T1OOUgXD9uOqG/ CaZC1rShrsTsjwQrSjatnqccJw== X-Google-Smtp-Source: ADFU+vvVW7n2zZvo0iTM1LHf7aeARiYDx7YZ2qZpZ+01CLBtoXSpjDgT9iff7fothkeqQNqUDc5tmg== X-Received: by 2002:a5d:5447:: with SMTP id w7mr6471509wrv.299.1585431053080; Sat, 28 Mar 2020 14:30:53 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id i19sm14286797wmb.44.2020.03.28.14.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 14:30:52 -0700 (PDT) Date: Sat, 28 Mar 2020 22:30:50 +0100 From: Tomas Vondra To: James Coleman Cc: Alvaro Herrera , Michael Paquier , Rafia Sabih , Peter Geoghegan , Simon Riggs , Shaun Thomas , Dmitry Dolgov <9erthalion6@gmail.com>, Alexander Korotkov , Tom Lane , PostgreSQL Developers , Andreas Karlsson Subject: Re: [PATCH] Incremental sort (was: PoC: Partial sort) Message-ID: <20200328213050.byyeuozylnxv2bhf@development> References: <20200324230831.5zvjpgayh35bxedp@development> <20200328011913.btjuwwkhieav3aod@development> <20200328025830.6v6ogkseohakc32q@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Mar 28, 2020 at 10:19:04AM -0400, James Coleman wrote: >On Fri, Mar 27, 2020 at 10:58 PM Tomas Vondra > wrote: >> >> ... >> >> The more I look at pathkeys_useful_for_ordering() the more I think the >> get_useful_pathkeys_for_relation() function should look more like it >> than the postgres_fdw one ... > >If we go down that path (and indeed this is actually implied by >removing the volatile check too), doesn't that really just mean (at >least for now) that get_useful_pathkeys_for_relation goes away >entirely and we effectively use root->query_pathkeys directly? The >only thing your lose them is the check that each eclass has a member >in the rel. But that check probably wasn't quite right anyway: at >least for incremental sort (maybe not regular sort), I think we >probably don't necessarily care that the entire list has members in >the rel, but rather that some prefix does, right? The idea there would >be that we could create a gather merge here that supplies a partial >ordering (that prefix of query_pathkeys) and then above it the planner >might place another incremental sort (say above a join), or perhaps >even a join above that would actually be sufficient (since many joins >are capable of providing an ordering anyway). > >I've attached (added prefix .txt to avoid the cfbot assuming this is a >full series) an idea in that direction to see if we're thinking along >the same route. You'll want to apply and view with `git diff -w` >probably. > Hmmm, I'm not sure the patch is quite correct. Firstly, I suggest we don't remove get_useful_pathkeys_for_relation entirely, because that allows us to add more useful pathkeys in the future (even if we don't consider pathkeys useful for merging now). We could also do the EC optimization in the function, return NIL and not loop over partial_pathlist at all. That's cosmetic issue, though. More importantly, I'm not sure this makes sense: /* consider incremental sort for interesting orderings */ useful_pathkeys = truncate_useless_pathkeys(root, rel, subpath->pathkeys); ... is_sorted = pathkeys_common_contained_in(useful_pathkeys, subpath->pathkeys, &presorted_keys); I mean, useful_pathkeys is bound to be a sublist of subpath->pathkeys, right? So how could this ever return is_sorted=false? The whole point is to end up with query_pathkeys (or whatever pathkeys we deem useful), but this does not do that. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services