Make index macros not recreate indexes on incremental models #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you create indexes on an incremental model like this:
You get this error on subsequent runs:
This can be avoided by dropping the indexes in a pre-hook, but that leads to the index being recreated from scratch for all rows in the table. On a large incremental model that's probably not ideal in most cases.
This PR adds a check to the macros to only create the index if it doesn't exist yet. This way SQL server only adds the newly merged values to the index and doesn't reprocess all rows.
I don't think this would create any breaking changes for existing users of the macros. If they are already dropping indexes, it would not affect them.
And if they are using indexes on non-incremental models, then it should also not make a difference.
I have been using these macros for several months in production now and haven't had any issues.
This addresses the issue #25 I raised about this.