Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eozvX-0007I1-CR for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Feb 2018 23:05:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eozvW-0002uf-7l for pgsql-hackers@arkaria.postgresql.org; Thu, 22 Feb 2018 23:05:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eozvV-0002uI-QD for pgsql-hackers@lists.postgresql.org; Thu, 22 Feb 2018 23:05:22 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eozvR-0006C4-Mn for pgsql-hackers@postgresql.org; Thu, 22 Feb 2018 23:05:20 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 07A4521C26DF; Fri, 23 Feb 2018 02:05:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.1.63] (unknown [46.39.228.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id D068021C24EE; Fri, 23 Feb 2018 02:05:11 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1519340711; bh=wp/+M6Vzqilt/oaEzb4Fd5wlkopohjkNSQZQhhLHlBA=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=faCcRBCinsRgEoFRL7Q9+EB2XBLV2JwC1OWqgrg+aFcZNcaiTtQUYtyodp9jmx+mM OnRlWeFt9NJGFXDAm3XOGAJ/b/orWEQ/TZXMJ8M+oZi28ByQijHymMYmrHdLDWUNi4 MRyffKNDswPVYsvPJlDnt3OV+7C6nN1KWj5Nq2AI= Subject: Re: ERROR: left and right pathkeys do not match in mergejoin To: Tom Lane Cc: PostgreSQL-development References: <5dad9160-4632-0e47-e120-8e2082000c01@postgrespro.ru> <20796.1519322593@sss.pgh.pa.us> From: Alexander Kuzmenkov Message-ID: <886b103b-7ecf-ca2e-6159-8c355258d936@postgrespro.ru> Date: Fri, 23 Feb 2018 02:05:10 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20796.1519322593@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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