Repository navigation
Share the parameter names of a schema-qualified procedure by server and database - #314
Merged
Merged
Conversation
…nd database A stored procedure's parameter names were kept with the object the command's connections came from, so a connection, a factory or a lambda made for each call (or each request) asked the database for the same names on every call. A schema-qualified name (dbo.get_author) is the same procedure for every login of a database, so its answer does not depend on who asked. Those answers are now kept once per server and database and found by every command and query of the library's own types. What is shared: the names of a procedure whose name has a schema, when the answer holds names, the connection is a DbConnection that reports both a DataSource and a Database, and the command is one of the library's own exact types (a query only needs the server and the database). Lookup goes to the shared entries first, then to the source's entries as before, then to the database. Everything else stays with its source exactly as before: names without a schema (each login resolves them in its own default schema), answers of no names, connections that report no server or database or are not a DbConnection, text commands, and command classes of the user's own. The shared entries hold at most 1024 procedures and are never cleared, evicted or expired; past the limit new sets go to their source. A failure that forgets a set removes the shared one for every connection, and the next call reads it again. No public API changes. Cost on the hit path: a command of the library's own type does one more virtual type check and two string length checks on the key, then one lookup in the shared entries (a hit for a qualified name, replacing the per-source lookup; a miss for an unqualified name, which then does the per-source lookup as before). No allocation is added; the schema-qualified test parses the name only after a database round trip. A connection created for each call now skips the schema round trip and the per-connection entry. No timed measurement was made for this change. Tests: four existing tests of distinct sources now use a procedure name without a schema, because a name with one is shared whatever its source is; fail-first tests for two fresh connections, unqualified names, empty answers, missing server or database, a user's own command type in both orders, other servers and databases, the 1024 limit, forgetting for everyone, and queries with a connection or a transaction per call; allocation tests for the shared lookup; and SQL Server tests for two logins with different default schemas and for a login that may only execute the procedure. The docs section "Parameter names are read once" and the release notes say who shares what and the caveats of sharing across logins, servers that report one name, and fake connections in tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…cache, and tidy the shared-tier tests A command class of the user's own that overrides how parameter names are read could remember its names in the same per-source table as the library's own commands, so a library command on the same connection or factory could be given the user's names, and the other way round. Such commands now keep their names in a table of their own for each source, found and kept by separate methods; the library's commands and queries keep the shared tier and their own table as before. No public API changes. Cost: none on the library's hit path; a user command does the same single lookup it did before, in its own table. Tests: new cases where the user's command runs first and the library's second on the same connection, and the reverse, for a name without a schema, a name with one, and a name with one while the shared tier is full. The shared-tier tests, the SQL Server tests and the cost tests now all sit in the one collection that runs alone, and the fakes of other tests that return names use a server name of their own. The synchronous and asynchronous paths are separate tests instead of one taking a flag, a non-DbConnection command also checks what it sends, a key without a server or database is checked directly, the SQL Server scene drops each object even when one drop fails and disposes its connection when impersonating fails, and the user and schema names there are neutral. Comments and code of the previous commit are wrapped, and a comment says the shared bound may be overshot by a few sets when calls race. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ocument the fall-through after the tier is full Two connection classes can report the same server and database (a test container, a provider behind a proxy), so a set of names shared by those two alone could be handed to the wrong provider. The key of a remembered set now also holds the runtime type of the connection, compared by reference: connections of different kinds of provider never share a set. One key shape serves both the shared entries and a source's own entries. Cost per call: one reference comparison in key equality and one runtime-type hash in the key hash, and a call to GetType on the connection when the key is made; nothing is allocated, and the key keeps only the type itself alive. Also documented, with a code comment and a test that pins it: once the shared tier has been full, a set of the same procedure can sit in a source's own entries beside one shared later. If the shared one is forgotten, the next call of that source can find the older set once, use it and fail, which forgets it too, and the call after that reads the names again. It is rare, loud and heals itself, so it is not guarded. Tests: a fail-first test with two connection classes that report the same server and database (one class shares, the other has its own entry) and a test for the fall-through. The fake server now applies its failure to each command, so a connection made earlier can fail later. Docs: the names section says names are kept per server, database, kind of provider and procedure, and describes the fall-through. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…r each fact The tests of the shared name tier repeated text that already has one home. The fake servers and the source tests built the ProcedureParameters schema table with their own copies of its name and column words; they now take the table from the existing test helper, which takes them from the library's constants. The LocalDB test reads the schema collection and its columns by those constants too. The name of the test collection is one constant used by its definition and every test class in it, and the shared tier tests reuse the existing server-error test type instead of declaring a second one with the same message. Where a chain of calls sat on one line it now has the first call on the receiver's line and one call per line after it. Tests only: no run-time change, no public API change, no message text changed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… findings A procedure name with no '.' cannot be schema-qualified, so it is never in the shared entries. FindShared now skips the shared probe for it. Cost per call: one scan of the procedure text for a dot (a short span search, no allocation) in place of a four-part hash and a table lookup for an unqualified name; a name with a dot probes as before, so bracketed names such as [dbo].[p] are still shared. Which names are shared does not change. Also: - Docs: the shared set also holds the parameter modes and scales the output-parameter check reads, read by whichever login needs them first and kept for every sharer until the set is forgotten. The release note says so in one sentence. - XML docs and comments on where names are kept now give every condition (schema, a DbConnection that reports server and database, the library's own command types). - The MSSqlClient README no longer says names are read once per connection factory: a schema-qualified name is kept per server and database, an unqualified one per factory. The article's overview sentence says the same. - The comments on the procedure key and the shared table say the static table keeps the provider type for the life of the process. - The shared-tier cost test creates a connection for each call, so it fails without the shared tier. The LocalDB test scene drops what it created if its constructor throws. A test comment about server names on fakes is now accurate. The tests read the bound from the library's own constant, which is now public. - Key construction and a few long comment lines are regrouped and wrapped. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
electricessence
marked this pull request as ready for review
December 4, 2026 14:39
electricessence
added a commit
that referenced
this pull request
Dec 4, 2026
…en one is fixed (#316) The remembered parameter names of a schema-qualified procedure are kept for the whole process, by server, database, kind of connection and procedure text (#314). Most test fakes reported the same fixed server name (`fake`, `gate`, `output` and so on), so a test could find names another test had left for the same procedure text, and pass or fail by the order the tests ran in. The theory in `ProcedureSchemaNamesTests` that failed in CI on #315 was one such case (#315 renamed its procedure names; this change removes the class of problem). - **Every fake connection reports its own server name.** Each now takes it from `NameServer.Unique`, which already existed. A fake that stands for one server across several connections of one test (the tracked connections of a tally, the connections of a token rig, the connections of a database rig) takes the name once for the tally or rig instead of once per connection, so what a test counts across those connections keeps its meaning. A fake that reports no server at all (the gated connection of the ConfigureAwait test) stays as it is: a connection that names no server is never shared. - **A guard fails when it comes back.** `SharedTierIsolationTests` reads the test project's own source files and fails when a type reports a string literal as its server name (except that one allowed fake, with its reason), or when a test file uses a procedure name of the form `ParameterNameHarness.NewProcedure` hands out (`dbo.names` followed by a number). The failure message says what is wrong and the fix. Seen failing: a fixed `fake` put back in one file and a `dbo.names3` in another made the two checks fail; both were restored before the commit. - **No other channel into the shared table.** `Shared.ByProcedure.Count` is asserted only in the shared-tier collection, which runs alone, and the table is cleared only there. Tests only: no run-time change, no public API change. **Verification:** solution Release build 0 warnings, 0 errors; Core.Tests all passed in three runs with the test classes and collections shuffled (seeds 101, 202 and 303), and in the normal gate; 267 sample checks; style and analyzer checks 0 findings; docfx 0 warnings; style scan clean; each literal of 12 or more characters this change adds appears once. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A stored procedure's parameter names were kept with the object the command's connections came from, so a connection, a factory or a lambda made for each call (or each request) asked the database for the same names on every call. A schema-qualified name (
dbo.get_author) is the same procedure for every login of a database, so its answer does not depend on who asked. Those answers are now kept once per server, database and kind of provider, and found by every command and query of the library's own types.What is shared: the names of a procedure whose name has a schema, when the answer holds names, the connection is a
DbConnectionthat reports both aDataSourceand aDatabase, and the command is one of the library's own exact types (a query only needs the server and the database). Lookup goes to the shared entries first, then to the source's own entries, then to the database. Everything else stays with its source exactly as before: names without a schema (each login resolves them in its own default schema), answers of no names, connections that report no server or database or are not aDbConnection, text commands, and command classes of the user's own. The shared entries hold at most 1024 procedures and are never cleared, evicted or expired; past the limit new sets go to their source. A failure that forgets a set removes the shared one for every connection, and the next call reads it again.Kind of provider: two connection classes can report the same server and database (a test container, a provider behind a proxy), so the key also holds the runtime type of the connection, compared by reference. Connections of different kinds of provider never share a set.
User's own command types: a command class of the user's own that overrides how names are read keeps its names in a table of its own for each source, apart from the library's commands on the same connection or factory. Before, both could use one table and be handed each other's names.
Documented limits: the shared set also holds the parameter modes and scales that the output-parameter check reads, read by whichever login needs them first; the key has no login, so two logins to one server and database share a set. Once the shared tier has been full, a set of the same procedure can sit in a source's own entries beside one shared later; if the shared one is forgotten, the next call of that source can find the older set once, use it and fail, which forgets it too, and the call after that reads the names again. It is rare, loud and heals itself, so it is not guarded; a test pins it. The shared bound may be overshot by a few sets when calls race.
Cost on the hit path: a command of the library's own type does one more virtual type check and two string length checks on the key, then one lookup in the shared entries (a hit for a qualified name, replacing the per-source lookup; an unqualified name skips the shared entries after one scan of its text for a dot, then does the per-source lookup as before). Key equality adds one reference comparison and the key hash one runtime-type hash; a call to
GetTypeis made on the connection when the key is made. No allocation is added. A connection created for each call now skips the schema round trip and the per-connection entry. No timed measurement is part of this change; the benchmark gate runs separately before it is merged.No public API change (the PublicAPI files are untouched).
Tests: four existing tests of distinct sources now use a procedure name without a schema, because a name with one is shared whatever its source is. New tests, fail-first: two fresh connections, unqualified names, empty answers, missing server or database, a user's own command type in both orders, other servers and databases, two connection classes that report one server and database, the 1024 limit, forgetting for everyone, the fall-through, and queries with a connection or a transaction per call. Allocation tests for the shared lookup. SQL Server tests (LocalDB) for two logins with different default schemas and for a login that may only execute the procedure. The shared-tier tests take the schema table, its names and the messages from the library's own constants and the existing test helper.
Docs: the section "Parameter names are read once" in
expressive-commands.mdand the release notes say who shares what and the caveats.Verification: solution Release and Debug (VS MSBuild) 0 warnings, 0 errors; Core.Tests 16216 passed with the generator on, 16195 passed and 16 skipped with it off; 267 sample checks; style and analyzer checks 0 findings on all projects; docfx 0 warnings.
🤖 Generated with Claude Code