Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-20 Thread Tom Lane
James Coleman writes: > On Mon, Apr 19, 2021 at 7:10 PM Tom Lane wrote: >> After some more testing, that seems like a good thing to do, >> so here's a v4. > This all looks good to me. Pushed, thanks for reviewing! regards, tom lane

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-20 Thread Tom Lane
ilm...@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) writes: > ilm...@ilmari.org (Dagfinn Ilmari Mannsåker) writes: >> There are 10 instances of this exact loop scattered around the codebase. >> Is it worth it turning it into a static inline function? > Something like the attached, maybe?

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-20 Thread James Coleman
On Tue, Apr 20, 2021 at 7:11 AM Dagfinn Ilmari Mannsåker wrote: > > ilm...@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > > > Tom Lane writes: > > > >> +/* We ignore binary-compatible relabeling on both ends */ > >> +while (expr && IsA(expr, RelabelType)) > >> +expr = ((Relab

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-20 Thread Dagfinn Ilmari Mannsåker
ilm...@ilmari.org (Dagfinn Ilmari Mannsåker) writes: > Tom Lane writes: > >> +/* We ignore binary-compatible relabeling on both ends */ >> +while (expr && IsA(expr, RelabelType)) >> +expr = ((RelabelType *) expr)->arg; > > There are 10 instances of this exact loop scattered ar

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-20 Thread Dagfinn Ilmari Mannsåker
Tom Lane writes: > + /* We ignore binary-compatible relabeling on both ends */ > + while (expr && IsA(expr, RelabelType)) > + expr = ((RelabelType *) expr)->arg; There are 10 instances of this exact loop scattered around the codebase. Is it worth it turning it into a static i

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread James Coleman
On Mon, Apr 19, 2021 at 7:10 PM Tom Lane wrote: > > I wrote: > > Anyway I'm now inclined to remove that behavior from > > find_computable_ec_member, and adjust comments accordingly. > > After some more testing, that seems like a good thing to do, > so here's a v4. This all looks good to me. Jame

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread Tom Lane
I wrote: > Anyway I'm now inclined to remove that behavior from > find_computable_ec_member, and adjust comments accordingly. After some more testing, that seems like a good thing to do, so here's a v4. regards, tom lane diff --git a/src/backend/optimizer/path/equivclass.

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread Tom Lane
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 tes

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread Tom Lane
I wrote: > I'm not wedded to that name, certainly, but it seems like neither > of these is quite getting at the issue. An EC can be sorted on, > by definition, but there are some things we don't want to sort > on till the final output step. I was trying to think of something > using the terminolo

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread Tom Lane
James Coleman writes: > I forgot to comment on this in my previous email, but it seems to me > that relation_has_safe_ec_member, while less wordy, isn't quite > descriptive enough. Perhaps something like > relation_has_sort_safe_ec_member? I'm not wedded to that name, certainly, but it seems like

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread James Coleman
On Sat, Apr 17, 2021 at 3:39 PM Tom Lane wrote: > ... > Also, I don't much care for either the name or API of > find_em_expr_usable_for_sorting_rel. The sole current caller only > really needs a boolean result, and if it did need more than that > it'd likely need the whole EquivalenceMember not j

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-19 Thread James Coleman
On Sun, Apr 18, 2021 at 1:21 PM Tom Lane wrote: > > I wrote: > > I think it's time for some refactoring of this code so that we can > > actually share the logic. Accordingly, I propose the attached. > > After sleeping on it, here's an improved version that gets rid of > an unnecessary assumption

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-18 Thread Tom Lane
I wrote: > I think it's time for some refactoring of this code so that we can > actually share the logic. Accordingly, I propose the attached. After sleeping on it, here's an improved version that gets rid of an unnecessary assumption about ECs usually not containing both parallel-safe and parall

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-17 Thread Tom Lane
[ sorry for not getting to this thread till now ] Tomas Vondra writes: > 3) Shouldn't find_em_expr_usable_for_sorting_rel now mostly mimic what > prepare_sort_from_pathkeys does? That is, try to match the entries > directly first, before the new pull_vars() business? Yeah. I concur that the pro

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-15 Thread Zhihong Yu
On Thu, Apr 15, 2021 at 6:27 PM Tomas Vondra wrote: > > > On 4/15/21 7:35 PM, James Coleman wrote: > > On Thu, Apr 15, 2021 at 5:33 AM Luc Vlaming wrote: > >> > >> On 15-04-2021 04:01, James Coleman wrote: > >>> On Wed, Apr 14, 2021 at 5:42 PM James Coleman > wrote: > > On Mon, Apr 12

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-15 Thread Tomas Vondra
On 4/15/21 7:35 PM, James Coleman wrote: > On Thu, Apr 15, 2021 at 5:33 AM Luc Vlaming wrote: >> >> On 15-04-2021 04:01, James Coleman wrote: >>> On Wed, Apr 14, 2021 at 5:42 PM James Coleman wrote: On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra wrote: > > On 4/12/21 2:24

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-15 Thread Tomas Vondra
On 4/15/21 2:21 AM, Robert Haas wrote: > On Wed, Apr 14, 2021 at 8:20 PM James Coleman wrote: >>> Hmm, could be. Although, the stack trace at issue doesn't seem to show >>> a call to create_incrementalsort_plan(). >> >> The changes to gather merge path generation made it possible to use >> thos

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-15 Thread James Coleman
On Thu, Apr 15, 2021 at 5:33 AM Luc Vlaming wrote: > > On 15-04-2021 04:01, James Coleman wrote: > > On Wed, Apr 14, 2021 at 5:42 PM James Coleman wrote: > >> > >> On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra > >> wrote: > >>> > >>> On 4/12/21 2:24 PM, Luc Vlaming wrote: > Hi, > >

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-15 Thread Luc Vlaming
On 15-04-2021 04:01, James Coleman wrote: On Wed, Apr 14, 2021 at 5:42 PM James Coleman wrote: On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra wrote: On 4/12/21 2:24 PM, Luc Vlaming wrote: Hi, When trying to run on master (but afaik also PG-13) TPC-DS queries 94, 95 and 96 on a SF10 I get th

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread James Coleman
On Wed, Apr 14, 2021 at 5:42 PM James Coleman wrote: > > On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra > wrote: > > > > On 4/12/21 2:24 PM, Luc Vlaming wrote: > > > Hi, > > > > > > When trying to run on master (but afaik also PG-13) TPC-DS queries 94, > > > 95 and 96 on a SF10 I get the error "cou

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread James Coleman
On Wed, Apr 14, 2021 at 8:21 PM Robert Haas wrote: > > On Wed, Apr 14, 2021 at 5:43 PM James Coleman wrote: > > The query in question is: > > select count(*) > > from store_sales > > ,household_demographics > > ,time_dim, store > > where ss_sold_time_sk =

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread James Coleman
On Wed, Apr 14, 2021 at 8:21 PM Robert Haas wrote: > > On Wed, Apr 14, 2021 at 5:43 PM James Coleman wrote: > > The query in question is: > > select count(*) > > from store_sales > > ,household_demographics > > ,time_dim, store > > where ss_sold_time_sk =

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread Robert Haas
On Wed, Apr 14, 2021 at 8:20 PM James Coleman wrote: > > Hmm, could be. Although, the stack trace at issue doesn't seem to show > > a call to create_incrementalsort_plan(). > > The changes to gather merge path generation made it possible to use > those paths in more cases for both incremental sort

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread Robert Haas
On Wed, Apr 14, 2021 at 5:43 PM James Coleman wrote: > The query in question is: > select count(*) > from store_sales > ,household_demographics > ,time_dim, store > where ss_sold_time_sk = time_dim.t_time_sk > and ss_hdemo_sk = household_demogra

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread James Coleman
On Wed, Apr 14, 2021 at 8:16 PM Robert Haas wrote: > > On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra > wrote: > > Could be related to incremental sort, which allowed some gather merge > > paths that were impossible before. We had a couple issues related to > > that fixed in November, IIRC. > > Hmm

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread Robert Haas
On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra wrote: > Could be related to incremental sort, which allowed some gather merge > paths that were impossible before. We had a couple issues related to > that fixed in November, IIRC. Hmm, could be. Although, the stack trace at issue doesn't seem to show

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-14 Thread James Coleman
On Mon, Apr 12, 2021 at 8:37 AM Tomas Vondra wrote: > > On 4/12/21 2:24 PM, Luc Vlaming wrote: > > Hi, > > > > When trying to run on master (but afaik also PG-13) TPC-DS queries 94, > > 95 and 96 on a SF10 I get the error "could not find pathkey item to sort". > > When I disable enable_gathermerge

Re: "could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-12 Thread Tomas Vondra
On 4/12/21 2:24 PM, Luc Vlaming wrote: > Hi, > > When trying to run on master (but afaik also PG-13) TPC-DS queries 94, > 95 and 96 on a SF10 I get the error "could not find pathkey item to sort". > When I disable enable_gathermerge the problem goes away and then the > plan for query 94 looks like

"could not find pathkey item to sort" for TPC-DS queries 94-96

2021-04-12 Thread Luc Vlaming
Hi, When trying to run on master (but afaik also PG-13) TPC-DS queries 94, 95 and 96 on a SF10 I get the error "could not find pathkey item to sort". When I disable enable_gathermerge the problem goes away and then the plan for query 94 looks like below. I tried figuring out what the problem i