schemachange icon indicating copy to clipboard operation
schemachange copied to clipboard

Add "--explain-first" to run `explain` on statements

Open akdor1154 opened this issue 2 years ago • 2 comments

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

akdor1154 avatar Sep 27 '21 04:09 akdor1154

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-jhansen avatar Oct 15 '21 05:10 sfc-gh-jhansen