Redundant composite index in many-to-many docs

Open Beginner friendly
#721 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
90/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
postgresql

Research direction

Start at the linked many-to-many relationships section and review the composite primary key and index example. Update the example so it no longer includes the redundant composite index, while retaining the single-column indexes; done when the documentation matches the proposed snippet.

Written by the indexing model from the issue text.

Description

The many-to-many relations documentation recommends creating a separate composite index on (userId, groupId) in addition to a composite primary key on (userId, groupId).

In PostgreSQL (and most other DBMSs), the PK already creates a unique index covering (userId, groupId), making the additional composite index redundant.

So this:

    p.primaryKey({ columns: [t.userId, t.groupId] }),
    p.index('users_to_groups_user_id_idx').on(t.userId),
    p.index('users_to_groups_group_id_idx').on(t.groupId),
    p.index('users_to_groups_composite_idx').on(t.userId, t.groupId),      // <----- unnecessary

Should be:

    p.primaryKey({ columns: [t.userId, t.groupId] }),
    p.index('users_to_groups_user_id_idx').on(t.userId),
    p.index('users_to_groups_group_id_idx').on(t.groupId),
Dominant language
MDX
Stars
241
Forks
402
Avg merge
4d 6h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from drizzle-team/drizzle-orm-docs

All issues in drizzle-team/drizzle-orm-docs

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.