Optimise IN queries for json fields in flat collections#252
Merged
suresh-prakash merged 7 commits intohypertrace:mainfrom Nov 21, 2025
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #252 +/- ##
============================================
- Coverage 80.50% 79.70% -0.80%
+ Complexity 1210 1209 -1
============================================
Files 224 226 +2
Lines 5626 5701 +75
Branches 487 492 +5
============================================
+ Hits 4529 4544 +15
- Misses 753 809 +56
- Partials 344 348 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // The LHS parser generates: "props"->'brand' (returns JSONB) | ||
| // We need: "props"->>'brand' (returns TEXT) | ||
| // Replace the last -> with ->> for primitive type extraction | ||
| int lastArrowIndex = parsedLhs.lastIndexOf("->"); |
There was a problem hiding this comment.
is tweaking the parser to not do this a bigger lift?
suresh-prakash
approved these changes
Nov 21, 2025
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.
Description
This is a successor to this PR: #251 for json fields.
JSONB Query Optimization: Before vs After
"props"->>'brand' = 'Dettol'"props"->>'brand' = 'Dettol'"props"->>'brand' != 'Dettol'"props"->>'brand' != 'Dettol'(((jsonb_typeof(to_jsonb("props"->'brand')) = 'array' AND to_jsonb("props"->'brand') @> jsonb_build_array('Dettol')) OR (jsonb_build_array("props"->'brand') @> jsonb_build_array('Dettol'))) OR ((jsonb_typeof(to_jsonb("props"->'brand')) = 'array' AND to_jsonb("props"->'brand') @> jsonb_build_array('Lifebuoy')) OR (jsonb_build_array("props"->'brand') @> jsonb_build_array('Lifebuoy'))))"props"->>'brand' IN ('Dettol', 'Lifebuoy')"props"->'brand' IS NULL OR NOT ((((jsonb_typeof(to_jsonb("props"->'brand')) = 'array' AND to_jsonb("props"->'brand') @> jsonb_build_array('Dettol')) OR (jsonb_build_array("props"->'brand') @> jsonb_build_array('Dettol')))))"props"->'brand' IS NULL OR NOT ("props"->>'brand' IN ('Dettol'))CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) > 500000CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) > 500000CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) < 500000CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) < 500000CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) >= 700000CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) >= 700000CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) <= 400004CAST("props"->'seller'->'address'->>'pincode' AS NUMERIC) <= 400004"props"->'colors' @> '["Green"]'::jsonb"props"->'colors' @> '["Green"]'::jsonb"props"->'colors' IS NULL OR NOT "props"->'colors' @> '["Green"]'::jsonb"props"->'colors' IS NULL OR NOT "props"->'colors' @> '["Green"]'::jsonbTesting