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 1epBLH-0003De-NP for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Feb 2018 11:16:44 +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 1epBLG-00065W-AW for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Feb 2018 11:16:42 +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 1epBLF-00065L-Ri for pgsql-hackers@lists.postgresql.org; Fri, 23 Feb 2018 11:16:42 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1epBL8-0006ZI-1I for pgsql-hackers@postgresql.org; Fri, 23 Feb 2018 11:16:40 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 02E9D21C2718; Fri, 23 Feb 2018 14:16:31 +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 BD56921C2347; Fri, 23 Feb 2018 14:16:30 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1519384590; bh=+lX7YHOPif+9+VyDCb0S7g6PspXl9WOpPSynEFfE6i8=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=hap2RCsfAmI/EzfUJc8K5lTLbzlIMcD3EqZMix6meLOLsaV3EiRc3lDaMwBy0R/0M Yq8iVmRRQ0Xuv5umEhP3fkYWKGKOU6Vv/qNP9EPjEwGFVp2iPeZWrIiD7oOzUmPvmP YVplnzmC4MHd+FaDAPqIZxCPOEWd2JkJeMYuXy/o= 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> <886b103b-7ecf-ca2e-6159-8c355258d936@postgrespro.ru> <754.1519343998@sss.pgh.pa.us> From: Alexander Kuzmenkov Message-ID: Date: Fri, 23 Feb 2018 14:16:30 +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: <754.1519343998@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ah, I understand now. We can lie to the executor about the order, because when we are moving based on the second outer column, we have a stretch of equal values in the inner column, so we can consider them to be sorted whatever way we need. The patch applies cleanly, make check-world passes. In create_mergejoin_plan:     * implied inner ordering is then "ORDER BY x, y, x", but the pathkey     * drops the second sort by x as redundant, and this code must cope. -- should this read "the pathkey machinery drops"? -- Alexander Kuzmenkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company