[YSQL] Fixes unique index consistency bug when yb_enable_inplace_index_update is on#32126
Conversation
…te` is set to on. `yb_enable_inplace_index_update` incorrectly treats primary-key updates on unique secondary indexes as safe for in-place index-row updates. This is false when the unique index uses NULLs-distinct semantics and any unique-index key column is NULL, because the hidden `ybuniqueidxkeysuffix` is part of the index row key and is derived from the base row ybctid. A base table PK update changes the base row ybctid, so the hidden unique suffix changes too.
There was a problem hiding this comment.
Code Review
This pull request ensures that primary key updates on unique indexes with NULL key columns are modeled as DELETE and INSERT operations rather than in-place updates, because the index row key suffix depends on the base table's ybctid. Feedback on the changes suggests switching to a short-lived per-tuple memory context in the newly introduced YbUniqueIndexKeyHasNull function to prevent potential memory leaks during large bulk updates when calling FormIndexDatum.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
✅ Deploy Preview for infallible-bardeen-164bc9 ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
trigger jenkins |
yb_enable_inplace_index_updateincorrectly treats primary-key updates on unique secondary indexes as safe for in-place index-row updates. This is false when the unique index uses NULLs-distinct semantics and any unique-index key column is NULL, because the hiddenybuniqueidxkeysuffixis part of the index row key and is derived from the base rowybctid. A base table PK update changes the base row ybctid, so the hidden unique suffix changes too.Reproducible example:
Consistency check immediately fails
The fix is to essentially force the
DELETE+INSERTfor this scenario.With
yb_enable_inplace_index_update = offthe issue is not reproducible with the above example.