1

I am wondering which is a more efficent method to retrieve data from the database.

ex. One particular part of my application can have well over 100 objects. Right now I have it setup to query the database twice for each object. This part of the application periodically refreshes itself, say every 2 minutes, and this application will probably end of being installed on 25-30 pc's. I am thinking that this is a large number of select statements to make from the database, and I am thinking about trying to optimize the procedure. I have to pull the information out of several tables, and both queries are using join statements.

Would it be better to rewrite the queries so that I am only executing the queries twice per update instead of 200 times? For example using a large where statement to include each object, and then do the processing of the data outside of the object, rather than inside each object?

Using SQL Server, .net No indexes on the tables, size of database is less than 10-5th

1
  • the overhead of running the query N times for 1 row is worse than running it 1 time and returning N rows Commented May 15, 2009 at 21:13

2 Answers 2

3

all things being equal, many statements with few rows is usually worse than few statements with many rows.

show the actual code and get better answers.

Sign up to request clarification or add additional context in comments.

3 Comments

Thats what just what I was looking for. Thanks
the overhead of running the query N times for 1 row is worse than running it 1 time and returning N rows
I'm uncomfortable with this already being an accepted answer. Who knows what his use case is. I don't trust the OP with taking this nougat (as accurate as it may be) and running with it.
2

The default answer for optimization must always be: don't optimize until you have a demonstrated need for it. The followup is: once you have a demonstrated need for it, and an alternative approach: try both ways to determine which is faster. You can't predict which will be faster, and we certainly can't. KM's answer is good - fewer queries tends to be better - but the way to know is to test.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.