ExistsSql on SQL Server and subclassing IDatabase #815
Unanswered
baki-reveal
asked this question in
Q&A
Replies: 1 comment
|
Hi, We're always open to PR's that make things better for people. A lot of that underlying code was migrated directly from Roundhouse, so there's definitely room for better, more modern approaches. A couple of things to watch out for with this change are:
In theory, subclassing Thanks for the detailed chat and thought you've put in so far 👍 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
i, thanks for grate. We've been using it for quite a while with both SQL Server and PostgreSQL.
While looking into a SQL Server performance issue, I found something that seems worth raising. I also ran into a related problem when trying to override it locally.
ExistsSql on SQL Server
AnsiSqlDatabase.ExistsSql uses INFORMATION_SCHEMA.TABLES with LOWER() on both columns. SqlServerDatabase does not override it, so SQL Server uses that implementation.
On SQL Server this is more expensive than a direct object lookup, and in our case these queries show up in blocking chains while application DDL is running. We counted 22 calls during a migration of a 364-table database.
I tried replacing it with a SQL Server-specific lookup using OBJECT_ID and sys.objects, which avoids querying INFORMATION_SCHEMA.TABLES.
Would you be open to a PR that adds a SQL Server override for ExistsSql? I'm happy to include tests. If there is a reason the current implementation is preferred, I'd be interested to know.
Subclassing IDatabase
Before changing grate itself, I tried subclassing SqlServerDatabase and overriding ExistsSql in our application.
That override is called, but the migration then creates no grate tables and eventually fails with:
Invalid object name 'grate.ScriptsRun'The reason seems to be that the bootstrap scripts are located using:
this.Database.GetType()The code then searches that type's assembly for the embedded bootstrap SQL. Since my subclass is in a different assembly, no resources are found. No error is raised at that point, so the migration continues until it later tries to use grate.ScriptsRun.
This made me wonder what the intended extension point is.
Is subclassing SqlServerDatabase or replacing IDatabase supported?
If not, would it make sense to throw an error when no bootstrap resources are found? That would make this failure much easier to diagnose.
If subclassing is intended to work, would you consider resolving the bootstrap resources from the provider's assembly rather than the concrete derived type?
I'm happy to put together a PR for either the SQL Server ExistsSql override or the bootstrap issue, depending on which approach you think is appropriate.
Thanks.
All reactions