Skip to content

Conversation

@jharting
Copy link
Contributor

Pull Request check-list

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Context

When querying with findOne() Sequelize adds LIMIT 1 to the query to limit the result size. In combination with duplicating joins this may result in a complicated query (subqueryFilter). An optimization exists in Sequelize where if the query's where clause contains the primary key then LIMIT 1 is skipped.

Description of change

This change extends the optimization to also cover unique columns.

@codecov
Copy link

codecov bot commented Mar 28, 2018

Codecov Report

Merging #9248 into master will increase coverage by <.01%.
The diff coverage is 100%.

@jharting jharting force-pushed the find-one-unique-column branch from 6951dce to b6d212b Compare April 6, 2018 07:44
lib/model.js Outdated

if (options.limit === undefined) {
const pkVal = options.where && options.where[this.primaryKeyAttribute];
const uniqueSingleColumns = _(this.uniqueKeys).values().filter(c => c.fields.length === 1).map('column').value();
Copy link
Member

Choose a reason for hiding this comment

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

use .chain here to make it explicit what's happening

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.

2 participants