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 1q8hRW-0001JV-Mn for pgsql-performance@arkaria.postgresql.org; Mon, 12 Jun 2023 13:18:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q8hRU-0006w8-MI for pgsql-performance@arkaria.postgresql.org; Mon, 12 Jun 2023 13:18:44 +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 1q8hRU-0006vz-CW for pgsql-performance@lists.postgresql.org; Mon, 12 Jun 2023 13:18:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q8hRR-001mzU-PN for pgsql-performance@lists.postgresql.org; Mon, 12 Jun 2023 13:18:43 +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 35CDIdLH1166865; Mon, 12 Jun 2023 09:18:39 -0400 From: Tom Lane To: "James Pang (chaolpan)" cc: "pgsql-performance@lists.postgresql.org" Subject: Re: Postgresql equal join on function with columns not use index In-reply-to: References: Comments: In-reply-to "James Pang (chaolpan)" message dated "Mon, 12 Jun 2023 08:09:28 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1166863.1686575919.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 12 Jun 2023 09:18:39 -0400 Message-ID: <1166864.1686575919@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "James Pang (chaolpan)" writes: > We migrate from Oracle to Postgresql14.8, one SQL has regression = in Postgres run in 5800 milliseconds in Postgresql v14.8, but the same S= QL got done in several hundred milliseconds in Oracle database. > With multiple table JOINs, if the join condition is tablea.colum= n1=3Dtableb.column1, optimizer will use the index to filter data in nest l= oops, but if tablea.column1=3Dregexp_replace(tableb.column1....), > Optimizer will not be able to use the index on tablea.column1, then it d= o a table scan and nestloop to produce a lot rows then use tablea.column1=3D= regexp_replace(tableb.column1....) as a filter. As a workaround we create= a view then use tablea.column1=3Dview.column1 that works. > Is it expected ? details as below. It's impossible to comment on this usefully with such a fragmentary description of the problem. Please send a complete, self-contained test case if you want anybody to look at it carefully. https://wiki.postgresql.org/wiki/Slow_Query_Questions regards, tom lane