fix: incorrect parentheses in partial index WHERE clause with IN and AND#265
fix: incorrect parentheses in partial index WHERE clause with IN and AND#265
Conversation
…AND (#264) The convertAnyArrayToIn() function assumed ARRAY[...] was at the end of the expression. When additional conditions followed (like AND ...), the simple TrimSuffix approach failed, leaving stray brackets and parens. Fixed by properly parsing to find the matching ]) closure, handling nested parentheses and quoted strings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes schema dump generation for partial indexes whose predicates contain an IN clause (via = ANY (ARRAY[...])) followed by additional conditions (e.g., AND ...), preventing stray ]/) from appearing in generated DDL.
Changes:
- Reworked
convertAnyArrayToIn()to locate the correctARRAY[...]terminator via scanning instead of usingTrimSuffix. - Added
findArrayClose()helper to safely find the matching])while skipping over quoted strings and nested brackets. - Updated online diff test fixtures to cover a partial index predicate with both
INandANDconditions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| testdata/diff/online/add_partial_index/plan.txt | Updates expected human plan output for the new partial index predicate formatting. |
| testdata/diff/online/add_partial_index/plan.sql | Updates expected SQL plan output to include the combined predicate. |
| testdata/diff/online/add_partial_index/plan.json | Updates expected JSON plan output (SQL and fingerprint) for the new predicate. |
| testdata/diff/online/add_partial_index/old.sql | Adds is_active column to support the new partial index predicate in fixtures. |
| testdata/diff/online/add_partial_index/new.sql | Adds the partial index with IN + AND predicate for reproduction/verification. |
| testdata/diff/online/add_partial_index/diff.sql | Updates expected migration SQL to include the combined predicate. |
| ir/normalize.go | Implements robust parsing for = ANY (ARRAY[...]) → IN (...) conversion when trailing expressions exist. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| bracketDepth := 1 // We're already inside ARRAY[ | ||
| parenDepth := 0 | ||
| inQuote := false | ||
|
|
There was a problem hiding this comment.
findArrayClose tracks parenDepth but never uses it to influence matching. This adds complexity and the doc comment implies parentheses are part of the matching logic. Consider either removing parenDepth entirely, or using it to gate the match (and/or validating it never goes negative) so the implementation matches the comment and intent.
Address Copilot review feedback - the parenDepth variable was tracked but never used in the matching logic. Removed it and updated the doc comment to accurately describe what the function does. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Thanks! |
Fix #264
The convertAnyArrayToIn() function assumed ARRAY[...] was at the end of the expression. When additional conditions followed (like AND ...), the simple TrimSuffix approach failed, leaving stray brackets and parens.
Fixed by properly parsing to find the matching ]) closure, handling nested parentheses and quoted strings.