Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use PLAN mode to get result metadata #388

Merged
merged 4 commits into from Mar 18, 2021

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Mar 10, 2021

Calling PreparedStatement#getMetaData() actually executed the query or DML statement of the PreparedStatement. This PR changes that to only executing the statement in PLAN mode to get the metadata of the statement. That is:

  1. More efficient, as the statement does not need to be executed.
  2. Enables getting the metadata without first specifying a value for each parameter, as PLAN mode is allowed with unbound parameters.

This change also allows calling PreparedStatement#getMetaData() for DML statements. This will result in an empty ResultSetMetaData instance, as DML statements do not return any relevant information for a ResultSetMetaData.

Fixes #387

Getting the result metadata of a PreparedStatement should not execute the query,
but should instead just request the query plan. This will also return the
metadata of the query.
@olavloite olavloite requested a review from a team as a code owner March 10, 2021 12:24
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner-jdbc API. label Mar 10, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 10, 2021
@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #388 (ad22087) into master (27cad43) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #388      +/-   ##
============================================
+ Coverage     71.96%   71.98%   +0.02%     
- Complexity     1132     1135       +3     
============================================
  Files            24       24              
  Lines          3524     3534      +10     
  Branches        539      541       +2     
============================================
+ Hits           2536     2544       +8     
- Misses          769      771       +2     
  Partials        219      219              
Impacted Files Coverage Δ Complexity Δ
...ud/spanner/jdbc/AbstractJdbcPreparedStatement.java 90.00% <ø> (-0.25%) 50.00 <0.00> (-1.00)
...ogle/cloud/spanner/jdbc/AbstractJdbcStatement.java 56.19% <100.00%> (+1.88%) 32.00 <2.00> (+3.00)
...ogle/cloud/spanner/jdbc/JdbcPreparedStatement.java 71.42% <100.00%> (+2.19%) 8.00 <2.00> (+1.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27cad43...ad22087. Read the comment docs.

@thiagotnunes thiagotnunes merged commit 8c7b665 into master Mar 18, 2021
@thiagotnunes thiagotnunes deleted the use-plan-for-metadata branch March 18, 2021 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner-jdbc API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PreparedStatement#getMetaData executes query
2 participants