-
Notifications
You must be signed in to change notification settings - Fork 11
Optimise IN queries for json fields in flat collections #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimise IN queries for json fields in flat collections #252
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is tweaking the parser to not do this a bigger lift?
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