SqlMapper Query param empty list cause table scan in mysql
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Previously reported in #1379, but the issue was closed by the original reporter for some reason, despite the actual problem still being present in Dapper.
connection.Query(
"Select xxx from test WHERE messageid IN @messageids",
new { messageids = new List() }
);
Generates the SQL Select xxx from test WHERE messageid IN (SELECT NULL WHERE 1 = 0), which causes a table scan in mysql due to poor query optimization.
@jayrowe's excellent investigation in the original issue shows that the table scan can be avoided by adding any FROM clause to the inner select, e.g. Select xxx from test WHERE messageid IN (SELECT NULL FROM (SELECT NULL) n WHERE 1 = 0)
Would you be open to a PR implementing this change?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start by tracing Dapper's handling of an empty list parameter for an IN clause, using the example and investigation in #1379; done means the generated MySQL SQL includes a FROM clause in the inner SELECT and avoids the reported table scan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, mysql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100