Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Some sensible optimizations to functions #14

Merged
merged 1 commit into from
Jul 25, 2016

Conversation

maggiepint
Copy link
Collaborator

Creates an inline table valued function to get the zone id from the links table.

Uses that inline function in UtcToLocal and LocalToUTC

Schema binds functions

  • note that this will require scripts to be run in a certain order. Don't know what tool you are using to generate, it doesn't appear to be a standard publish, but be aware that this matters

I was seeing some decent performance improvement from this. Processing 70,000 dates went from about 25 seconds to about 17. I don't like this metric, I would rather pay attention to actual reads/writes/cpu, but that data is hard to get for non-inline functions as the query optimizer black boxes them.

Turns out that writing an inline version of UtcToLocal actually makes things worse. Probably a result of the query optimizer choking on the complexity from the cross applies that end up being used. SQL Server is fun that way.

IMO, it would make sense to just keep duplicate data in the intervals table for all the linked time zones, instead of running a query to get the canonical timezone from the link, and then looking up that time zone. This allows basic inner joins to retrieve data, instead of functions, and that's always going to perform better. Should more than make up for the extra rows in the table (especially since the table is never written). As an added bonus, you can create some indexed views you otherwise wouldn't be able to create.

I also wonder what would happen if the clustered index on the zones table were just the IANA zone name (lose the surrogate key). Yes, it's wide, but that puts the cluster on the primary lookup column, which is good.

Let me know if you want me to try any of this stuff.

@mattjohnsonpint
Copy link
Owner

This all looks great. I'm going to do some additional things before release, but going ahead with merging this.

@mattjohnsonpint mattjohnsonpint merged commit 43ebd39 into mattjohnsonpint:master Jul 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants