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 1pL4n1-0006Fa-48 for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Jan 2023 16:07:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pL4m1-0003Vw-EE for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Jan 2023 16:06:49 +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 1pL4m1-0003Vn-6O for pgsql-bugs@lists.postgresql.org; Thu, 26 Jan 2023 16:06:49 +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 1pL4lu-0003Zi-Pc for pgsql-bugs@lists.postgresql.org; Thu, 26 Jan 2023 16:06:48 +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 30QG6fp12961800; Thu, 26 Jan 2023 11:06:41 -0500 From: Tom Lane To: Pete Storer cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: FW: Query execution failure In-reply-to: References: <2957101.1674746628@sss.pgh.pa.us> Comments: In-reply-to Pete Storer message dated "Thu, 26 Jan 2023 15:43:37 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2961798.1674749201.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 26 Jan 2023 11:06:41 -0500 Message-ID: <2961799.1674749201@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Pete Storer writes: > I'm not sure how to identify which index may be corrupt, if that is the = cause. Regarding a different sort order between tables, if that were the c= ase, wouldn't this query fail in Production as it does in our Development = environment? They are identical with respect to indices and sort order, an= d they both point to the same foreign table, which resides on a MySQL data= base. Meh. You've just got two merge joins in that plan, and three of the four inputs to them are being explicitly sorted, so one would certainly hope that those sorts are consistent. But the fourth input is being sourced directly from the foreign server, and so this query is fundamentally assuming that the foreign server has the same idea of sort ordering as the local one. Evidently that assumption is wrong. I'd check locale settings on your two databases to understand why it doesn't fail on prod. But the long-term solution if you want this to work reliably is probably to force use of C locale on all three databases; that's about the only locale that you can fully trust to be portable. I don't know anything about the mysql FDW, but another possible route to fixing things is to get it to not believe that the remote's sort ordering matches the local one. If the plan were relying on a local sort instead of a remote sort then everything would be fine. regards, tom lane