slowness in select
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hello
I face huge slowness when using DynamicParameters with a list.
/**** The setup ****/
I am using Dapper 2.0.30 framework .Net 4.6.2.
My Db is Azure SQL Server As a service from Azure.
The table I request has this structure:
TABLE [MY_TABLE](
[first_id] [numeric](12, 0) NOT NULL,
[second_id] [int] NOT NULL,
[entry_start] [datetime] NOT NULL,
[entry_end] [datetime] NOT NULL,
[value] [numeric](20, 10) NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED
(
[first_id] ASC,
[second_id] ASC,
[entry_start] ASC,
[entry_end] ASC
)
/**** The prove that this is not an index problem ****/
When I do the following, there is no problem, it is almost instantaneous:
var request = "select first_id, second_id, entry_start, entry_end, value MY_TABLE where first_id in (2, 3) and entry_start >= @start_date and entry_end <= @end_date";
var param = new DynamicParameters();
param.Add("start_date", startDate);
param.Add("end_date", endDate);
var result = connection.Query<MyTableDto>(request, param);
/**** The problem ****/
But when I want to use a param for first_id, the request remains stucked!!
var request = "select first_id, second_id, entry_start, entry_end, value MY_TABLE where first_id in @ids and entry_start >= @start_date and entry_end <= @end_date;";
var ids = new List<int> { 2, 3 };
var param = new DynamicParameters();
param.Add("ids", ids);
param.Add("start_date", startDate);
param.Add("end_date", endDate);
var result = connection.Query<MyTableDto>(request, param);
/**** Help please :) ****/
Do you have any idea of what causes this slowness?
Regards!
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
Start with the two connection.Query calls and compare the SQL and parameters produced for the literal IN clause versus the DynamicParameters list. Run both queries against the stated Azure SQL database and inspect their execution plans and timings. Done means the cause of the parameterized-list slowness is identified and a reproducible fix or documented limitation is established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100