Message-ID: From: "davecramer (@davecramer)" To: "pgjdbc/pgjdbc" Date: Mon, 17 Feb 2025 17:59:53 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3511: Performance Regression in JDBC Driver 42.7.5 - getCrossReference In-Reply-To: References: List-Id: X-GitHub-Author-Login: davecramer X-GitHub-Comment-Id: 2663802581 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3511 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3511#issuecomment-2663802581 Content-Type: text/plain; charset=utf-8 > The slowness is caused by the where clause now checking that the catalog name matches the current database name: > > [pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java](https://github.com/pgjdbc/pgjdbc/blob/6437a20cac2d544bee36e79082bdad0a34704585/pgjdbc/src/main/java/org/postgresql/jdbc/PgDatabaseMetaData.java#L2525) > > Line 2525 in [6437a20](/pgjdbc/pgjdbc/commit/6437a20cac2d544bee36e79082bdad0a34704585) > > sql += " AND current_database() = " + escapeQuotes(primaryCatalog); > Previously, this check was omitted. A check is required to avoid incorrect behaviour. For example, in the old version, if there was a typo or inaccessible database for the `primaryCatalog` parameter, then getCrossReference would return results for the current database instead of empty results. > > If you're calling getCrossReference directly for the current database, you can set `primaryCatalog` (and `foreignCatalog`) to null, and the performance is similar to the old version. If this is the only reason for doing this then do this without using SQL as the connection knows the database