Skip to content

Cache query plan for DML LINQ queries #2229

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

Merged
merged 3 commits into from
Dec 22, 2019

Conversation

bahusoid
Copy link
Member

@bahusoid bahusoid commented Sep 25, 2019

Fixes #2222

Maybe I'm wrong but it seems cached constants are not possible with DML queries (as no result transformers are supported). So let's just ignore CanCachePlan check for DML queries.

Regarding changes in #1544. I think of another fix for cached constants - we should "parametrize" them. So that such queries should be cachable. I mean for query like:

from c in db.Customers
where c.CustomerId == "ALFKI"
select new { c.CustomerId, c.ContactName, Constant = 1 }

Currently transformer is generated with embedded constants inside. Which for query above should generate something like:

public object ItemTransfomer(object[] row)
{
return new{CustomerId = row[0], ContactName = row[1], Constant = 1};
}

Instead we should generate something like this:

public object ItemTransfomer(object[] row, IDictionoray<string, object> parameters)
{
return new{CustomerId = row[0], ContactName = row[1], Constant = (int)parameters["p1"]};
}

And provide NhLinqExpression.ParameterValuesByName for parameters parameter.

@hazzik
Copy link
Member

hazzik commented Sep 26, 2019

Not sure if it is a good idea to cache a DML query.

@hazzik
Copy link
Member

hazzik commented Sep 26, 2019

Or is it about a query plan cache?

@bahusoid
Copy link
Member Author

Yes. It's exactly about query plan cache.

@bahusoid bahusoid changed the title Cache DML LINQ queries Cache query plan for DML LINQ queries Sep 26, 2019
@gokhanabatay

This comment has been minimized.

hazzik
hazzik previously approved these changes Nov 18, 2019
@fredericDelaporte fredericDelaporte added this to the 5.3 milestone Nov 18, 2019
Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

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

Regarding changes in #1544. I think of another fix for cached constants - we should "parametrize" them.

This is not straightforward to do, as far as I remember when I have looked into this for #1544. Parameterized constant works as parameters in the generated SQL queries, but these projections are run in-memory, and are not translated to SQL.

@fredericDelaporte fredericDelaporte merged commit 8c7444d into nhibernate:master Dec 22, 2019
bahusoid added a commit to bahusoid/nhibernate-core that referenced this pull request Jan 2, 2020
fredericDelaporte pushed a commit that referenced this pull request Jan 12, 2020
* Revert "Cache query plan for DML LINQ queries (#2229)"

This reverts commit 8c7444d

* Failing test

* Proper DML query plan caching

* Fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NHibernate query plan for Linq Dml is not cached
4 participants