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 1kYbbd-0000eR-A9 for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Oct 2020 21:06:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kYbba-0007z4-L3 for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Oct 2020 21:06:38 +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 ) id 1kYbYR-0002wv-AK for pgsql-hackers@lists.postgresql.org; Fri, 30 Oct 2020 21:03:23 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kYbYO-0005eb-Uq for pgsql-hackers@postgresql.org; Fri, 30 Oct 2020 21:03:22 +0000 Received: by mail-ed1-x542.google.com with SMTP id dn5so8013513edb.10 for ; Fri, 30 Oct 2020 14:03:20 -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=RuAXOmaMEu0f2iB5KZ6Ekf2CDLcz/y3378njbNtzia0=; b=ZttpDUnhE4FvT89cVRf1ncK3m4UvedEtSZUEKBs1h7ANJubxjOjyV3/UgDtOclsHha gCc9Fsr5mbI7hI8aQWcyQ6/mvNvYely3DHloX4TTaB3xrHQNunfd2A7dDDtrD4P8udEh K1020+YF5y2gRCEEp+3gyZ+6WltIvHYqfHZYaYRmdnJN6T9vy9CJz3KcWv1oYPFKXiyy XGEZd4EXOoixmqCx6hj8IS839b48ivuRzXrbRZ3YMmjJRR0Qf75zeETRK2HY5P6qHSSH Z8mv6ye8hQxKW5QtUpyxFzqlwPrIm9Y3pXSJBnazyE1c78gwUR/utZ0EMCRkqfSYSMuc rvEw== 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=RuAXOmaMEu0f2iB5KZ6Ekf2CDLcz/y3378njbNtzia0=; b=LRl9euyghh5HQZ2Ow0qp2RZde1RjcglvkD1TTWqxhQt8HZKiuHX9s3mB3GKMJZ9Wm5 NA8riIAmKq7pRogEPfH4DC3fLLlKhlhnsQaK08JhP1DimPiOWMZGkmYiA8bSYEJHvYGY vE82JBFJqpKRnRoj5s/FNmzQD2WqQWPYR99enCzmhZM6IKivhiHdIQqZTVMREup4ZyeV cqW6D2svHNz/WWiTxM3JWQ0MJJj/onD25yBaz9HB7slXv1v2SRHpmEuzd4iRemJRzXsm 78t/FKC1VzVGqfiaGjbWSd0XhJOcvvMLBTo2Jydu43XZkmlE7eJ/UOrX24NY2Bo3sIou 4l3g== X-Gm-Message-State: AOAM533wAWnckqbnp5FHRZAPj4P9z30FS9+tJ1OKzI1JdVTEnPi948BG b5A107NaUEhvfwAWSMjccPsiPA== X-Google-Smtp-Source: ABdhPJzy6qCzXkUEjcK/6sV6oC613kgUkbtqyeavnPl8Lub6ZeerecExS84L5S54QpDxjH3ZHWclKw== X-Received: by 2002:aa7:d582:: with SMTP id r2mr4358927edq.170.1604091799431; Fri, 30 Oct 2020 14:03:19 -0700 (PDT) Received: from localhost (ip-86-49-245-76.net.upcbroadband.cz. [86.49.245.76]) by smtp.gmail.com with ESMTPSA id j24sm3569509edq.29.2020.10.30.14.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 14:03:18 -0700 (PDT) Date: Fri, 30 Oct 2020 22:03:16 +0100 From: Tomas Vondra To: James Coleman Cc: Jaime Casanova , Pg Hackers Subject: Re: enable_incremental_sort changes query behavior Message-ID: <20201030210316.cbwv4arwp4lcfgx2@development> References: <20201003214440.fe4674dce5q7z4bg@development> <20201029220652.glf4xk2p7wkfisb6@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 Fri, Oct 30, 2020 at 01:26:08PM -0400, James Coleman wrote: >On Thu, Oct 29, 2020 at 6:06 PM Tomas Vondra > wrote: >> >> On Tue, Oct 06, 2020 at 09:37:31AM -0400, James Coleman wrote: >> >On Tue, Oct 6, 2020 at 9:28 AM Jaime Casanova >> > wrote: >> >> Can you please create an entry in the commitfest for this one so we >> >> don't lose track of it? >> > >> >> We're not too far from the next minor release, so I've been looking at >> this fix again and I intend to get it committed shortly (on Monday or >> so). Attached is a slightly modified version of the v4 patch that: >> >> (a) Removes comments about projections added to code that is not >> directly related to the fix. I'm not against adding such comments >> separately. > >Seems fine. Do you want to commit them at the same time (just a >separate commit)? Or have a separate patch? It seems a bit overkill to >start a new thread just for those. > Probably sometime later, as a separate patch. I haven't thought very much about those comments, it just seemed unrelated to the fix so I've removed that for now. Let's not bother with this until after the minor release. >> (b) Fixes comment in expected output of incremental_sort test. > >Thanks. > >> (c) Removes else branch from find_em_expr_usable_for_sorting_rel. It's >> not quite needed thanks to the "return" in the "if" branch. IMO this >> makes it more elegant. > >No objection. > >> I do have two questions about find_em_expr_usable_for_sorting_rel. >> >> (a) Where does the em_is_const check come from? The comment claims we >> should not be trying to sort by equivalence class members, but I can't >> convince myself it's actually true and I don't see it discussed in this >> thread. > >That comes from find_ec_member_for_tle which is called by >prepare_sort_from_pathkeys which we note in the comments contains the >set of rules we need to mirror. > Thanks for the pointer. I'll take a look. >> (b) In find_em_expr_for_rel, which was what was used before, the >> condition on relids was this: >> >> if (bms_is_subset(em->em_relids, rel->relids) && >> !bms_is_empty(em->em_relids)) >> { >> return em->em_expr; >> } >> >> but here we're using only >> >> if (!bms_is_subset(em->em_relids, rel->relids)) >> continue; >> >> Isn't this missing the second bms_is_empty condition? > >I definitely remember intentionally removing that condition. For one, >it's not present in prepare_sort_from_pathkeys. My memory is a bit >fuzzy on all of the whys, but isn't it the case that if we've already >excluded const expressions, that we must have vars (and therefore >rels) present, and therefore the relids bms must be non-empty? >Probably more importantly, we're going to check that an actual em expr >matches, which means the bms subset check is really just an >optimization to avoid unnecessarily scanning the exprs for equality. >Perhaps it's worth adding a comment saying as such? > >By the way, the fact that this is parallel to >prepare_sort_from_pathkeys is the reason the XXX comment is still >there about possibly needing to remove relabel types (since >prepare_sort_from_pathkeys does that). I don't think it's a hard >requirement: the worst case is that by not digging into relabel types >we're being unnecessarily strict. > >Both of these I can add if desired. > Yeah, it'd be good to explain the reasoning why it's fine to have the conditions like this. Thanks. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services