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 1lYc5i-0001WH-Si for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Apr 2021 22:10:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lYc5h-0004a9-AL for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Apr 2021 22:10:01 +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 1lYc5h-0004TX-2x for pgsql-hackers@lists.postgresql.org; Mon, 19 Apr 2021 22:10:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lYc5a-0007mk-EP for pgsql-hackers@postgresql.org; Mon, 19 Apr 2021 22:09:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 13JM9pDc366788; Mon, 19 Apr 2021 18:09:51 -0400 From: Tom Lane To: James Coleman cc: Tomas Vondra , Luc Vlaming , PostgreSQL-development , Robert Haas Subject: Re: "could not find pathkey item to sort" for TPC-DS queries 94-96 In-reply-to: References: <91f3ec99-85a4-fa55-ea74-33f85a5c651f@swarm64.com> <355670.1618688385@sss.pgh.pa.us> <90179.1618766515@sss.pgh.pa.us> Comments: In-reply-to James Coleman message dated "Mon, 19 Apr 2021 16:44:49 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <366786.1618870191.1@sss.pgh.pa.us> Date: Mon, 19 Apr 2021 18:09:51 -0400 Message-ID: <366787.1618870191@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk James Coleman writes: > Two things I wonder: > 1. Should we add tests for the relabel code path? As far as that goes, the Relabel-stripping loops in find_ec_member_matching_expr are already exercised in the core regression tests (I didn't bother to discover exactly where, but a quick coverage test run says that they're hit). The ones in exprlist_member_ignore_relabel are not iterated though. On reflection, the first loop stripping the input node is visibly unreachable by the sole caller, since everything in the exprvars list will be a Var, Aggref, WindowFunc, or PlaceHolderVar. I'm less sure about what is possible in the targetlist that we're referencing, but it strikes me that ignoring relabel on that side is probably functionally wrong: if we have say "f(textcol)" as an expression to be sorted on, but what is in the tlist is textcol::varchar or the like, I do not think setrefs.c will consider that an acceptable match. So now that's seeming like an actual bug --- although the lack of field reports suggests that it's unreachable, most likely because if we do have "f(textcol)" as a sort candidate, we'll have made sure to emit plain "textcol" from the source relation, regardless of whether there might also be a reason to emit textcol::varchar. Anyway I'm now inclined to remove that behavior from find_computable_ec_member, and adjust comments accordingly. > 2. It'd be nice not to have the IS_SRF_CALL duplicated, but that might > add enough complexity that it's not worth it. Yeah, I'd messed around with variants that put more smarts into the bottom-level functions, and decided that it wasn't a net improvement. regards, tom lane