-
Notifications
You must be signed in to change notification settings - Fork 37
[Comments] Clean up your queries and simplify logic with CROSS APPLY #5
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
Comments
Something to note is that this technique doesn't work if the expression includes window functions, as it changes the window to operate in. |
@gonsalu it's funny you mention that, because Adam Machanic has a really cool method he calls the "parallel apply pattern", which you can use to improve parallelism on queries using windowing functions that have a bad plan. Itzik Ben-Gan mentions it in his windowing functions book and credits Adam, but I couldn't find it online. I asked Adam if it was online anywhere and he sent me this video from a PASS presentation he did: I'd watch it while you have the chance before PASS takes down their YouTube channel. Adam presents the pattern at 54:00, but I'd suggest watching the whole thing, tons of great info there. |
Thanks for sharing, but that's not quite what I was trying to highlight. For example, let's say you have the following query:
The result set will look like:
If you try to use
Then, the result set will look like the table below, which might not be the expected result.
|
https://chadbaldwin.net/2021/01/07/use-cross-apply-to-clean-up-queries.html
The text was updated successfully, but these errors were encountered: