sequelize / sequelize/sequelize

Option to auto create foreign key indexes

Open
#5,042 12 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

existing workaround good first issue status: understood
Dominant language
TypeScript
Stars
30.4k
Forks
4.3k
Avg merge
1d 6h
Merged PRs (30d)
68

Description

If you create a foreign key constraint no further index will be auto created by postgres (I'm not sure what other DBs will do, I did not check), since there are a couple of different ways to create a index in that case.

But I'd say the average use case would be improved if sequelize would just add a normal btree index on the foreign key if you pass a option to the global sequelize instance. That way new tables would always benefit from that and you do not always have to think about it.

The performance difference is significant in that case.

So I'd say it would be a nice feature to add.

Contributor guide

Open the contributing guide

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.

Research direction

Start by reading the issue discussion and locating Sequelize’s foreign-key constraint and index creation paths. Check how PostgreSQL and other supported databases handle these indexes, then define done as an optional global setting that creates normal btree indexes for foreign keys on new tables, with coverage for the supported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, typescript
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.