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

If there is an unequal operator in the query, HQL Query Plan is regenerated #3069

Open
cokalyoncu opened this issue May 24, 2022 · 5 comments · May be fixed by #3168
Open

If there is an unequal operator in the query, HQL Query Plan is regenerated #3069

cokalyoncu opened this issue May 24, 2022 · 5 comments · May be fixed by #3168

Comments

@cokalyoncu
Copy link

cokalyoncu commented May 24, 2022

CrdCardResponse crdCardResponse = Query<CrdCard>()
    .Where(x => x.CardNo == cardNo)
    .Select(x => new CrdCardResponse()
    {
        IsLimitExceed = x.Dci != CardDci.Credit.GetKey()
    }).SingleOrDefault();

Hql query plan is regenerated each time this query is run. If the query is changed in this way, hql query plan is cached.

CrdCardResponse crdCardResponse = Query<CrdCard>()
    .Where(x => x.CardNo == cardNo)
    .Select(x => new CrdCardResponse()
    {
        IsLimitExceed = x.Dci == CardDci.Credit.GetKey()
    }).SingleOrDefault();

This line in SelectClauseHqlNominator is causing this trouble:

var projectConstantsInHql = _stateStack.Peek() || expression.NodeType == ExpressionType.Equal || IsRegisteredFunction(expression);

This code should be changed like this:

var projectConstantsInHql = _stateStack.Peek() || expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual || IsRegisteredFunction(expression);
@gokhanabatay
Copy link
Contributor

@fredericDelaporte is it ok to change as @cokalyoncu suggested it effects performance of our application and we don't know until we investigate deeply ?

var projectConstantsInHql = _stateStack.Peek() || expression.NodeType == ExpressionType.Equal || expression.NodeType == ExpressionType.NotEqual || IsRegisteredFunction(expression);

@bahusoid
Copy link
Member

I don't understand importance of Equal/NotEqual operators. Shouldn't this check at least include all others comparison operators too (<, >, ...)

@gokhanabatay
Copy link
Contributor

I don't understand importance of Equal/NotEqual operators. Shouldn't this check at least include all others comparison operators too (<, >, ...)

You are right with other operators (<, >, ...) in our case we just faced this issue with not equal operator. QueryPlanCache is effects application performance under high load.

@gokhanabatay
Copy link
Contributor

Hi @bahusoid could you lead us for providing fix for this issue.

@bahusoid
Copy link
Member

bahusoid commented Sep 14, 2022

What assistance do you need? Just prepare pull request with the fix and a test case. Fix should be applied at least for all comparison operations Maybe others binary operations too - I don't understand this code.

@bahusoid bahusoid linked a pull request Sep 27, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants