Re: ERROR: left and right pathkeys do not match in mergejoin - Mailing list pgsql-hackers

From Alexander Kuzmenkov
Subject Re: ERROR: left and right pathkeys do not match in mergejoin
Date
Msg-id 886b103b-7ecf-ca2e-6159-8c355258d936@postgrespro.ru
Whole thread Raw
In response to Re: ERROR: left and right pathkeys do not match in mergejoin  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ERROR: left and right pathkeys do not match in mergejoin
List pgsql-hackers
El 22/02/18 a las 21:03, Tom Lane escribió:
> The third possibility is to decide that create_mergejoin_plan is being
> overly paranoid and it's okay to extract merge details from a "redundant"
> path key even though it specifies the opposite sort order from what the
> current merge clause seems to need.

This check looks necessary to me, because merge join can't work with 
such a combination of outer pathkeys and merge clauses. The order of 
outer and inner column must be the same. Here, two outer columns with 
different orders are compared to the same inner column, so there will be 
mismatch one way or another. Consider the original query with some 
sample data:

     outer     inner
   desc  asc   desc
    i2   k2     i1
------------------
-> 1    0      1 <-
    1    1      0
    1    2
    0

The merge join starts at tuples marked with arrows. It finds that the 
outer tuple is less than the inner, so it advances the inner pointer, 
and loses the tuple with i1 = 1.

So, if we can't do a merge join on these clauses with these pathkeys 
anyway, it is OK to discard some of them in 
find_mergeclauses_for_pathkey. This helps the case when we use the 
existing order of outer relation. Also, we should take care not to 
create such combinations in select_outer_pathkeys_for_merge, when it 
tries to match root->query_pathkeys.

-- 
Alexander Kuzmenkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company



pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: Translations contributions urgently needed
Next
From: Robert Haas
Date:
Subject: Re: Typo in predicate.c comment