Skip to content
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

MERGE target hints support #1273

Merged
merged 2 commits into from Aug 19, 2018
Merged

MERGE target hints support #1273

merged 2 commits into from Aug 19, 2018

Conversation

MaceWindu
Copy link
Contributor

@MaceWindu MaceWindu commented Aug 10, 2018

Fix #1272

SQL Server supports hints on target table, this PR adds support for hints generation.

Because merge uses different ordering of hint and table alias, you cannot use With method, which will put hint after alias and need to use WithTableExpression method to specify proper ordering:

// {0} is a table
// {1} is an alias
// for merge target alias must go after hint
table.WithTableExpression("{0} WITH (HOLDLOCK) {1}")

TODO:

  • [ ] UsingTarget method produce bad sql. We should remove hint from target table, when it used as source

Edit:
code above shouldn't be used for merge-specific hints, see below

@MaceWindu MaceWindu added this to the 2.3.0 milestone Aug 10, 2018
@MaceWindu
Copy link
Contributor Author

Taking into account

I will add merge hint parameter of merge operation that user could pass to Merge/MergeInto methods.
This will allow us to generate hints in proper places easily for all databases that support merge-specific hints.

@MaceWindu MaceWindu changed the title [WIP] MERGE target hints support MERGE target hints support Aug 11, 2018
@MaceWindu
Copy link
Contributor Author

Ok, what we have. I've added overloads to Merge/MergeInto methods to accept string hint. Those overloads will accept only non-null values and execution of merge will throw exception if provider doesn't support hints.

What providers supported (only those have hints according to documentation)

Sql Server

Hint applied to merge target (OPTIONS clause still not supported). Example:

db.TargetTable
    .Merge("HOLDLOCK")
    .UsingTarget()
    .OnTargetKey()
    .UpdateWhenMatched()
    .Merge();
MERGE INTO [TargetTable] WITH(HOLDLOCK) [Target] ....

Oracle

db.TargetTable
    .Merge("append")
    .UsingTarget()
    .OnTargetKey()
    .UpdateWhenMatched()
    .Merge();
MERGE /*+ append */ INTO TestMerge1 Target ...

Informix

db.TargetTable
    .Merge("AVOID_STMT_CACHE")
    .UsingTarget()
    .OnTargetKey()
    .UpdateWhenMatched()
    .Merge();
MERGE {+ AVOID_STMT_CACHE } INTO TestMerge1 Target ...

@MaceWindu MaceWindu merged commit c934072 into master Aug 19, 2018
@MaceWindu MaceWindu deleted the merge_hints branch August 19, 2018 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants