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

Add "--explain-first" to run explain on statements #76

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

akdor1154
Copy link
Contributor

@akdor1154 akdor1154 commented Sep 27, 2021

At our org, we like to run explain on DDL statements before running them. With the notable exception of GRANT, this is supported on almost all DDL statements we normally have deal with, and serves as a very capable pre-check step, e.g. for us to run in feature branch CI runs or as a pre-commit hook. (with EXPLAIN, snowflake not only checks sql syntax, but also column, table, and function references, type compatibility, and probably more)

This pr adds an --explain-first flag to schemachange that will run explain <statement> before running any statements, which enables the above workflow. This also works with dry runs.

One drawback is that not all statements support EXPLAIN - e.g. I have hit GRANT statements but there might be others. Currently this PR is an all-or-nothing approach. This is still useful for us but I could see future work enabling this on a per-statement basis. This is non-trivial though, might need to add a magic var, comment, or something else to the sql code. Would seek your design input before doing anything in this direction.

Sorry for the bombardment of PRs, this is the last one! :)

Will squash before merging, just will await feedback first in case there are other changes / you don't like this direction / etc.

Cheers
Jarrad

@sfc-gh-jhansen
Copy link
Collaborator

Sorry for the slow response here @akdor1154. I will be OOO until next Tuesday, but will look at this then. In the meantime I've left comments on #74 (and #75), and would love to get those published!

@sfc-gh-tmathew
Copy link
Collaborator

@akdor1154 Could you revisit this PR and let us know if you could get the changes to the latest state so that we review it against the latest version and request additional enhancements for a future release.

I can see Explain Plan being useful as part of the dry-run validations to append to a list of pre-checks.

Thoughts?

@sfc-gh-tmathew sfc-gh-tmathew added enhancement New feature or request question Further information is requested labels Nov 2, 2023
@sfc-gh-tmathew sfc-gh-tmathew self-assigned this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants