sql: report RevalidateCachedQuery as the cached-plan error's routine - #173374
Open
demostheneslld wants to merge 1 commit into
Open
sql: report RevalidateCachedQuery as the cached-plan error's routine#173374demostheneslld wants to merge 1 commit into
demostheneslld wants to merge 1 commit into
Conversation
Clients detect "cached plan must not change result type" via the error's Routine field (PG_DIAG_SOURCE_FUNCTION). CockroachDB reported whichever internal function raised the error, so cockroachdb#164406 silently changed the value from "runExecBuilder" to "execBind" and broke ActiveRecord's stale-plan recovery. Construct the error in a dedicated function named RevalidateCachedQuery so the field is stable and matches what PostgreSQL reports, and assert it in pgtest. Epic: none Release note (bug fix): The "cached plan must not change result type" error now reports "RevalidateCachedQuery" as its source function, matching PostgreSQL, so client libraries that detect stale prepared statements via that field recover correctly.
demostheneslld
requested review from
bghal and
yuzefovich
and removed request for
a team
August 14, 2026 19:33
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link) |
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.
During the Bind phase of the extended pgwire protocol (and Execute for the simple protocol), the "cached plan must not change result type" error is detected by clients via its Routine field (
PG_DIAG_SOURCE_FUNCTION). PostgreSQL reportsRevalidateCachedQuery, its plancache.c function. CockroachDB reported whichever internal function constructed the error -runExecBuilderuntil #164406 moved the extended-protocol check to Bind, which changed the value toexecBindand silently broke clients matching the old name (e.g. activerecord-cockroachdb-adapter'sis_cached_plan_failure?, which stopped translating the error into ActiveRecord's evict-and-retry recovery; we hit this in production).This PR constructs the error in a dedicated function named
RevalidateCachedQuery, so the reported routine is stable across refactors and identical to PostgreSQL's - detection heuristics written against PostgreSQL (ActiveRecord upstream matches exactly this name) work unchanged. The pgtest datadriven test now asserts Code, Message, and Routine (newkeepErrRoutineoption), making the fields clients key on a tested contract rather than an accident of the call stack. The assertion also holds when the suite runs against real PostgreSQL.Compatibility note: this is itself a wire-behavior change, and it breaks two client classes once. (1) Clients that adapted to 26.2 by matching
execBindstop matching when the pin ships. (2) Simple-protocol clients (SQL-level PREPARE/EXECUTE, no wire Bind) matchingrunExecBuilderwork on every released version and break only here. Every alternative to freezing the accidental value breaks one of these groups eventually; the pin breaks them onto the value PostgreSQL has reported since 8.3, making it the last such break. Flagged in the release note; deferring to you on which release it rides.Companion adapter fix: cockroachdb/activerecord-cockroachdb-adapter#403 switches detection to the error message, which works on pre- and post-#164406 servers. The two are complementary: the adapter fix covers existing versions, this makes the field reliable going forward.
Resolves the detection half of the issue behind #164406's driver-compat work.