Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bug optimizing string contains and string startswith for version 8.0.0 #2994

Copy link
Copy link

Description

@stevenpua
Issue body actions

Greetings! Great job transitioning to .net 8. I got into an issue. Not sure if this is already written.

with Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0

TO REPLICATE: When doing a query

var normalizedSearchString = "my title".ToUpperInvariant();

var q=  from x in db.Blogs
where x.NormalizedName.StartsWith(normalizedSearchString) ||
x.NormalizedBody.Contains(normalizedSearchString)
select x;
q.ToList();

i get an optimized query:

select * from blogs where normalized_name like @normalized_searchstring_0_rewritten escape '\' or 
 normalized_body like @normalized_searchstring_0_rewritten escape '\' 

the desired behaviour should probably be using a different rewritten @normalized_searchstring_1_rewritten. For contains.

TEMPORARY FIX: is to use a different variable

var normalizedSearchString = "my title".ToUpperInvariant();
var normalizedSearchString1 = normalizedSearchString;

var q=  from x in db.Blogs
where x.NormalizedName.StartsWith(normalizedSearchString) ||
x.NormalizedBody.Contains(normalizedSearchString1)
select x;
q.ToList();

proposed code to fix:
in

replace

var escapedPatternParameter =
    _queryCompilationContext.RegisterRuntimeParameter(patternParameter.Name + "_rewritten", lambda);

with

// use different parameter name for StartsWith, EndsWith, Contains (sec)
var escapedPatternParameter =
    _queryCompilationContext.RegisterRuntimeParameter(patternParameter.Name + _rewritten_sec"+
(int)methodType, lambda);
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.