You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(client-engine-runtime): parameterize primitive values of Json fields - #30861
A string, number or boolean written to a Json field is never replaced by a placeholder, so the literal stays in the query plan cache key. Every distinct value compiles a new plan and adds its own cache entry. With large string payloads the cache fills up to queryPlanCacheMaxSize entries that each hold the value, which is the memory growth reported in the issue. #handlePrimitive returns early when matchesPrimitiveMask fails, and that check has no case for the Json bit, so the JSON.stringify branch below it never runs for a Json-only field.
Change
Primitives on an edge whose mask includes Json are now stringified and given a Json placeholder before the primitive type check, the same way #handleObject and #handleArray already treat objects and arrays. The gt/gte/lt/lte Json filters are left as literals, because the query compiler reads their value to pick the JSON type to compare against and panics on a placeholder there.
Tests
Unit tests in scalar-values.test.ts (with a Json field added to the fixture schema) check that a string and a number in the same Json field share one parameterized query, and that Json comparison filters keep their literal. Functional tests: a primitive values case in json-fields, and a where path gt case in 0-legacy-ports/json for postgres and mysql. The Json functional suites pass on better-sqlite3, pg and mariadb.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
The parameterizer now serializes primitive values in JSON fields and registers them as JSON placeholders. It leaves values for gt, gte, lt, and lte filters unchanged. Tests cover query parameterization, JSON values, and JSON-path comparisons.
The parameterizer serializes primitive values in JSON fields and registers them as Json placeholders. Tests check string and number parameterization and round-trip storage of string, integer, decimal, and boolean values.
The parameterizer leaves values under gt, gte, lt, and lte unchanged. Tests check that a gt filter is not parameterized and that JSON-path greater-than queries return a result for MySQL and PostgreSQL.
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: primitive values (strings, numbers, booleans) of Json fields are now parameterized in client-engine-runtime. The raw summary and objectives match this. The title is sp…
Linked Issues check
Issue #30859 requires primitive string and number values written to Json fields to use placeholders and share a cached query shape. The production change now JSON-stringifies Json-masked primitives be…
Out of Scope Changes check
The changes stay within issue #30859. The production change fixes primitive Json parameterization. The fixture change supports the unit test. The unit and functional tests verify cache-shape parameter…
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 5 files.
Full details: Title check
Explanation
The title names the main change: primitive values (strings, numbers, booleans) of Json fields are now parameterized in client-engine-runtime. The raw summary and objectives match this. The title is specific and does not include file lists. The commit note about keeping comparison-filter primitives literal is a supporting detail and does not conflict with the title.
Full details: Linked Issues check
Explanation
Issue #30859 requires primitive string and number values written to Json fields to use placeholders and share a cached query shape. The production change now JSON-stringifies Json-masked primitives before primitive matching and creates a Json placeholder. The unit test verifies that string and number values produce equal parameterized queries. The functional test covers string, integer, decimal, and boolean Json values. The comparison-filter exception preserves literals for gt, gte, lt, and lte, as required for query compilation, and tests cover the gt case.
Full details: Out of Scope Changes check
Explanation
The changes stay within issue #30859. The production change fixes primitive Json parameterization. The fixture change supports the unit test. The unit and functional tests verify cache-shape parameterization, Json round trips, and the comparison-filter compatibility case. No unrelated implementation or test scope is shown.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
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
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.
Problem
A string, number or boolean written to a
Jsonfield is never replaced by a placeholder, so the literal stays in the query plan cache key. Every distinct value compiles a new plan and adds its own cache entry. With large string payloads the cache fills up toqueryPlanCacheMaxSizeentries that each hold the value, which is the memory growth reported in the issue.#handlePrimitivereturns early whenmatchesPrimitiveMaskfails, and that check has no case for theJsonbit, so theJSON.stringifybranch below it never runs for aJson-only field.Change
Primitives on an edge whose mask includes
Jsonare now stringified and given aJsonplaceholder before the primitive type check, the same way#handleObjectand#handleArrayalready treat objects and arrays. Thegt/gte/lt/lteJson filters are left as literals, because the query compiler reads their value to pick the JSON type to compare against and panics on a placeholder there.Tests
Unit tests in
scalar-values.test.ts(with aJsonfield added to the fixture schema) check that a string and a number in the sameJsonfield share one parameterized query, and that Json comparison filters keep their literal. Functional tests: aprimitive valuescase injson-fields, and awhere path gtcase in0-legacy-ports/jsonfor postgres and mysql. The Json functional suites pass on better-sqlite3, pg and mariadb.Fixes #30859
Summary by CodeRabbit