Skip to content

Conversation

@tianzhou
Copy link
Contributor

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.

…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>
Copilot AI review requested due to automatic review settings January 28, 2026 18:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 correct ARRAY[...] terminator via scanning instead of using TrimSuffix.
  • 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 IN and AND conditions.

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.

Comment on lines 1111 to 1114
bracketDepth := 1 // We're already inside ARRAY[
parenDepth := 0
inQuote := false

Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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>
@tianzhou tianzhou merged commit e2063b8 into main Jan 28, 2026
2 checks passed
@McVeyMason
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect closing parentheses for CREATE INDEX ... WHERE with an IN clause

2 participants