Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I have a fairly simple database which is giving horrible performance when loading up my records.

In essence, I have 2 tables which are linked by a primary key and hold different information. One of these tables has 1 record only per, the other can have many.

The problem I have is that the query which is returning the "many" results gives terrible performance and will take 2-3 seconds to execute locally. This was the case when there was only a handful of records in that table.

My SQL query is as follows:-
SQL
SELECT 
PID, Municipality, Address_1, Address_2, Locality, State, Postcode, Sale_date, Sale_price, Capital_value, Land_area, Land_use_code, Room_count, Building_area, Construction_year, Wall_construction_code, Roof_construction_code, Source, SaleID 
FROM SaleInformation 
ORDER BY Sale_date DESC


There is a lot of records in that table now (say 40,000+) and that query returns every field that matches PID (linked key).

For the life of me I cannot work out what it is that is slowing the performance and it is driving me insane!

Any help greatly appreciated.

Cheers,

Joe
Posted
Comments
Thomas Nielsen - getCore 17-Sep-14 3:07am    
please add table definitions, it is likely that something usefull is missing there

Hi,

Check this ...How Do I Speed Up My Select * Query Of "530,000" Rows[^]

Also, one more thing i noticed in your query is that absence of where clause which may be useful to improve your query performance.

Hope provided link will help you.

Cheers
 
Share this answer
 
Comments
Joe Stansfield 17-Sep-14 5:15am    
Thankyou!
Something very simple (no where clause!). So that was resulting in the entire table being returned all the time, but just the relevant rows been displayed through the joined tables.

Now it runs like a dream!!
Magic Wonder 17-Sep-14 5:37am    
Your welcome.
dear Joe,

You may need to add index to your table for fast performance...

Regard
 
Share this answer
 
Comments
Joe Stansfield 16-Sep-14 21:46pm    
Thanks,

I will look in to that.

I have also read that creating a view may improve performance, however people seem conflicted on this. Would creating a view between the 2 tables that contain all the columns I require be likely to improve things?

Joe
Jörgen Andersson 17-Sep-14 2:52am    
A view is essentially just a predefined query, so telling you that it will improve performance is pretty stupid. (Unless of course you create an Indexed View)
Your only chance of improving the performance is to add a composite index on (PID,Sale_date), that way you will at least not need any sorting.
Creating an indexed view would probably increase your performance if your tables are not updated too frequently. It is easy enough for you to try out.
See performance gains by using indexed views in SQL Server[^]

But maybe you should look into database normalization in order to improve the performance.

Database Normalization Basics[^]

Database Normalization Tutorial[^]

Normalization of database[^]
 
Share this answer
 
v2
Comments
Jörgen Andersson 17-Sep-14 2:53am    
Why would a view increase performance?
George Jonsson 17-Sep-14 3:16am    
See my updated answer.
Mainly because the view is created once for every table update and a SELECT is executed every query.
But I see now that he only gets results from one table, not both.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900