perf(bigquery-jdbc): optimize getExportedKeys performance using hybrid metadata lookup#13734
perf(bigquery-jdbc): optimize getExportedKeys performance using hybrid metadata lookup#13734keshavdandeva wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the getExportedKeys method in BigQueryDatabaseMetaData to use a SQL-based approach instead of the REST API metadata scan when both catalog and schema are provided. It also introduces an early return for PCNT catalog schemas and adds corresponding integration tests. The review feedback suggests optimizing performance by lazy-loading and caching the SQL template file instead of reading it from the classpath on every query, and removing the redundant RTRIM function from the SQL query to allow BigQuery to utilize metadata optimizations.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request optimizes the getExportedKeys method in BigQueryDatabaseMetaData by executing a SQL query against INFORMATION_SCHEMA instead of scanning metadata via the REST API, and adds integration tests for PCNT tables. The reviewer identified three key issues: correctness bugs in the SQL query related to multi-column foreign keys and duplicate rows, a potential SQL injection vulnerability when formatting parameters into backtick-quoted identifiers, and synchronization overhead in loading the SQL file content which can be optimized using the lazy initialization holder class idiom.
b/534326814
This PR optimizes
DatabaseMetaData.getExportedKeys()by restoring the highly performantINFORMATION_SCHEMASQL lookup path, correcting a performance regression introduced when the method was migrated to sequential REST API lookups.To ensure complete contract safety across both standard native tables and external REST catalog tables (PCNT tables), we implement a hybrid routing strategy:
If
schemacontains a dot (.), we bypass SQL execution entirely and return a structured emptyResultSetinstantly.If either
catalogorschemaarguments arenull(representing wildcard metadata searches), the driver falls back to retrieving constraints concurrently via the Java Client REST API.For targeted native table queries, the driver executes the optimized
DatabaseMetaData_GetExportedKeys.sqlquery template.Integration Tests
ITDatabaseMetadataTest.javafor:testGetPrimaryKeys_pcntTabletestGetImportedKeys_pcntTabletestGetExportedKeys_pcntTabletestGetCrossReference_pcntTable