Repository navigation
fix(meerkat-core): dedupe array join keys before UNNEST in v2 joins - #309
Merged
Merged
Conversation
v2 array joins created one row per list entry, so a repeated ID in the join array produced repeated joined rows. Example: an SLA that reuses the same metric definitions across its policies made one ticket show 66 rows instead of 4. The v1 CONTAINS join matched each ID once. Remove duplicate IDs before UNNEST, keeping a single NULL when the list has one, so only duplicate rows change. Applied only when a table has a single array join column, so multiple arrays keep their positional pairing. Uses only functions allowed by the query server. Refs: TKT-115361
PutluruAravindaReddy
requested review from
itsTalwar,
ujaval403,
vpbs2 and
zaidjan-devrev
as code owners
October 1, 2026 09:53
jayachandranramadoss-devrev
left a comment
Contributor
There was a problem hiding this comment.
@shriram-devrev Could you PTAL
shriram-devrev
approved these changes
Oct 7, 2026
PutluruAravindaReddy
enabled auto-merge (squash)
October 12, 2026 05:24
PutluruAravindaReddy
disabled auto-merge
October 12, 2026 05:24
ujaval403
approved these changes
Oct 13, 2026
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.
Summary
UNNESTto turn an ID list into rows before joining. Every list entry becomes a row, so when the same ID appears more than once, the joined row repeats. Example: an SLA reuses the same metric definitions across many policies, so a ticket joined to its SLA metrics showed 66 rows instead of 4. The v1CONTAINSjoin matched each ID once, and v2 was meant to differ from v1 only in speed.list_distinct) beforeUNNEST.list_distinctalso drops NULLs, so when the list has a NULL, one NULL is added back. NULL entries behave exactly as they do today.list_appendandlist_countare rejected there).What changes
[a, b][a, a, b][a, NULL, a][NULL][]orNULLOnly duplicate values change. Everything else produces the same rows as before.
When this happens, and why it wasn't caught earlier
The repetition comes from the array side of a join: a column holding a list of IDs, matched against the other table's
id.ticket → slais a normal one-to-one join, so it isn't affected.sla → metric_definitionjoins through an array. One SLA lists 66 metric IDs across its policies but only 4 are unique, because each policy repeats the same metrics.UNNESTturns all 66 into rows, so each ticket repeats 66 times.issue.owned_by_ids → dev_user.idif an owner appeared twice.sla_id,part_id), and arrays that are only shown as columns, not used in a join.Why now: the
UNNESTjoin was added in #259 (May 2026); the v1CONTAINSjoin before it didn't have this problem. Most ID arrays (owners, tags, parts) don't repeat IDs, and the existing test fixtures had none, so results looked correct. SLA policies are the first common case where repeats are normal. The editor preview also caps at 20 rows, which hid how large the repetition really was.DevRev
work-item: CEAAA-103
Test plan
joins each distinct id once when the array has duplicates or NULLs) fails without the fix (7 rows) and passes with it (5 rows).UNNEST.meerkat-core: 565 passed (11 pre-existing skips).meerkat-node: 789 passed (117 pre-existing expected failures, 1 skip).Not in this PR