Skip to content

Ability to do use table hints per query with MSSQL - #8843

Merged
sushantdhiman merged 10 commits into
sequelize:masterfrom
mccabemj:master
Jan 5, 2018
Merged

sushantdhiman merged 10 commits into
sequelize:masterfrom
mccabemj:master

Conversation

@mccabemj

@mccabemj mccabemj commented Jan 5, 2018 •

Copy link
Copy Markdown
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • 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?

Description of change

As per issue #8830 I have implemented the ability to do table hints with MSSQL queries. Simply adding the tableHint option with a string containing the type of table hint will add it to the SQL of the query. I have also added tests for a couple of potential table hints.

The array of potential table hints comes from the table_hint_limited section here
https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table

Note I have not added the ability for multiple table hints, or the ability to use hints with index's. This could be added in the future.

@codecov

codecov Bot commented Jan 5, 2018 •

Copy link
Copy Markdown

Codecov Report

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

Comment thread lib/dialects/mssql/query-generator.js Outdated
mainFragment += ' AS ' + mainTableAs;
}

const tableHints = ['NOLOCK', 'READUNCOMMITTED', 'UPDLOCK', 'REPEATABLEREAD', 'SERIALIZABLE', 'READCOMMITTED', 'TABLOCK', 'TABLOCKX', 'PAGLOCK', 'ROWLOCK', 'NOWAIT', 'READPAST', 'XLOCK', 'SNAPSHOT', 'NOEXPAND'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @janmeier good suggestion. I have implemented that, let me know what you think

@janmeier
janmeier requested a review from a team January 5, 2018 11:27

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implementation looks good, I found a feature request #7031

It seems there can be multiple hints on single table, so tableHints should be an array possibly.

I haven't used MSSQL table hints so not sure but if its possible we should support multiple hints too.

@sushantdhiman

Copy link
Copy Markdown
Contributor

Note I have not added the ability for multiple table hints

Got it, lets start with small if there is demand for multiple hints we can always add that later

@mccabemj

mccabemj commented Jan 5, 2018

Copy link
Copy Markdown
Contributor Author

@sushantdhiman yes, I was aiming to start small. In the future, a new option could be added for multiples, but this would be a lot more complex as it would have to allow for indexs on certain values. Plus, you are not allowed more than one hint from each group (Granularity hints and Isolation level hints) so that would have to be coded.

Seeing as there is only my issue and #7031 I'd say this is good enough for now. Your call

@sushantdhiman
sushantdhiman merged commit 11ff776 into sequelize:master Jan 5, 2018
@sushantdhiman sushantdhiman mentioned this pull request May 23, 2018
2 of 4 tasks
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.

3 participants