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

(sp_IndexCleanup) Feature Suggestion: Normalize filtered index bodies #490

Open
chadbaldwin opened this issue Oct 23, 2024 · 3 comments
Open

Comments

@chadbaldwin
Copy link

Saw your LinkedIn post. I will likely have more suggestions in the future as I've been working on this exact same script. No one know who I am, so maybe I'll create some suggestions to add features I've added to mine since yours will likely get more people using it 😄

I'm curious to see what you think about this feature/capability.

Here's how I've implemented it in my script:
https://github.com/chadbaldwin/SQL/blob/2f6d41fd8dc121fa340c17e51cf2b48815889647/Scripts/Find%20Overlapping%20Indexes.sql#L85-L110

Is your feature request related to a problem? Please describe.
I regularly run into filtered indexes where the filter is similar but not the same. For example:

IndexA: WHERE ([ColA] = 1 AND [ColB] > 2)
IndexB: WHERE ([ColB] > 2 AND [ColA] = 1)

Those are the "same" but would not be seen as a duplicate.

Describe the solution you'd like
Normalize the definition so that they are comparable even when ordered differently.

Are you ready to build the code for the feature?
I'm happy to see if I can work the feature in...but I'm more interested in your insight of the capability itself. After that I'm happy to submit the PR.

@chadbaldwin
Copy link
Author

chadbaldwin commented Oct 23, 2024

Obviously there is a bit of a gotcha here...if you have a column that contains [sp]AND[sp], it will incorrectly split it...And I would not at all be surprised if someone has a column named...[foo and bar].

@erikdarlingdata
Copy link
Owner

erikdarlingdata commented Oct 23, 2024

@chadbaldwin perhaps it would work better to normalize the column names and expressions first. I can't think of an awesome way to do that off the top of my head.

My larger concern is using the build in string split function. I think I have references to it in here where I was just a bit lazy, but it only being available in compat level 130+ is a show stopped for me to release generally.

Anyway, I'd be happy for any input, feedback, or contributions you might have. You do some neat stuff.

@chadbaldwin
Copy link
Author

Yeah, that's fair. The STRING_SPLIT stuff could easily be changed to use the old school XML method. I'll play around with the idea testing some edge cases like columns with weird names and see if I can come up with a better backward compatible version with less gotchas.

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

No branches or pull requests

2 participants