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

VAULT-5827 Don't prepare SQL queries before executing them #15166

Merged
merged 2 commits into from
Apr 26, 2022

Conversation

swenson
Copy link
Contributor

@swenson swenson commented Apr 25, 2022

We don't support proper prepared statements, i.e., preparing once and
executing many times since we do our own templating. So preparing our
queries does not really accomplish anything, and can have severe
performance impacts (see
hashicorp/vault-plugin-database-snowflake#13
for example).

This behavior seems to have been copy-pasted for many years but not for
any particular reason that we have been able to find. First use was in
#15

So here we switch to new methods suffixed with Direct to indicate
that they don't Prepare before running Exec, and switch everything
here to use those. We maintain the older methods with the existing
behavior (with Prepare) for backwards compatibility.

We don't support proper prepared statements, i.e., preparing once and
executing many times since we do our own templating. So preparing our
queries does not really accomplish anything, and can have severe
performance impacts (see
hashicorp/vault-plugin-database-snowflake#13
for example).

This behavior seems to have been copy-pasted for many years but not for
any particular reason that we have been able to find. First use was in
#15

So here we switch to new methods suffixed with `Direct` to indicate
that they don't `Prepare` before running `Exec`, and switch everything
here to use those. We maintain the older methods with the existing
behavior (with `Prepare`) for backwards compatibility.
@swenson swenson requested a review from a team April 25, 2022 18:39
@@ -95,7 +95,7 @@ func (b *backend) pathCredsCreateRead(ctx context.Context, req *logical.Request,
"name": username,
"password": password,
}
if err := dbtxn.ExecuteTxQuery(ctx, tx, m, query); err != nil {
if err := dbtxn.ExecuteTxQueryDirect(ctx, tx, m, query); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The database secret engines under builtin/logical/ that's not database/ such as this one (aka "Standalone DB Engines") are deprecated and will be removed in the near future. Doesn't hurt to update them, but note that we will be dropping them soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just changing all uses of the existing functions in vault :)

Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@swenson
Copy link
Contributor Author

swenson commented Apr 26, 2022

Thanks everyone!

@swenson swenson merged commit f8e907e into main Apr 26, 2022
@swenson swenson deleted the VAULT-5827-dbtxn branch April 26, 2022 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants