Skip to content

fix: fix unstable tag generation for composite indexes with different column orders #1346

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ucpr
Copy link

@ucpr ucpr commented Jul 16, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Fix unstable tag generation for composite indexes with different column orders.

User Case Description

When multiple composite indexes exist on the same columns but in different orders, the generated code may have unstable tag output.

Example:

CREATE TABLE users (
    id INT PRIMARY KEY,
    email VARCHAR(255),
    name VARCHAR(255),

    -- composite indexes with different column orders
    INDEX idx_email_name (email, name),
    INDEX idx_name_email (name, email)
);

With a schema like the above, the generated tags can vary between runs:

// First run
Email string `gorm:"index:idx_email_name,priority:1;index:idx_name_email,priority:2"`

// Second run (order may differ)
Email string `gorm:"index:idx_name_email,priority:2;index:idx_email_name,priority:1"`

@ucpr ucpr marked this pull request as draft July 16, 2025 13:35
@ucpr ucpr marked this pull request as ready for review July 16, 2025 13:36
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.

1 participant