remi bourgarel
remi bourgarel

Reputation: 9389

Is SqlDataReader.GetValue query dependant?

In my code I have a Query like this

SELECT id,name
FROM people

I retrieve datas using a sqldatareader.

If I change my query for

SELECT id,name
FROM people
WHERE NOT EXISTS(
SELECT *
FROM people_died
WHERE people_died.id = people.id
)

I can see with dotTrace that the calls to getvalue takes longer with the second query, so I'd like to know why ...

If you're absolutely sure that's not the good reason, can you tell me what can possibly affect the performance of SqlDataReader.getValue ?

Thanks

EDIT : Is it possible that it depends on column from table "people" that are not in the query ? (there is a lot of ntext column in this table for instance)

Upvotes: 0

Views: 258

Answers (3)

remi bourgarel
remi bourgarel

Reputation: 9389

I have an answer to my question : YES

In my original query I had a very very big IN clause (around 1400 id), I removed this clause and the call to getValue now have a normal execution time, so I have to find a work-around

Thanks anyway

Upvotes: 0

Beth
Beth

Reputation: 9617

Can you try

SELECT p.id,name
FROM people p left join people_died d
on p.id = d.id
WHERE d.id is null

might improve your performance

Upvotes: 0

LukeH
LukeH

Reputation: 269588

Does your query return many rows?

A SqlDataReader streams the data. It's possible that the GetValue call is waiting for more rows to be streamed in, and that's taking longer to happen in the second case due to the more complex query.

Upvotes: 1

Related Questions