1

i am working on a project where i need to put large number of sql queries on a single page .. my question is that is there any problem that i will be having in future if my site gets heavy traffic ... i do not want my site to slow down.. please suggest some way so that the number of queries does not affect my site performance..

i am working on php

sql query may look like

$selectcomments=mysql_query("select `comment`,`email`,`Date` from `fk_views` where (`onid`='$idselect_forcomments' and comment !='') order by Date asc");
3
  • what do you mean by "large number"? this is just one query? Do you mean the number of result records? Commented Sep 18, 2013 at 17:09
  • Could you please describe database structure, planned code? We know nothing about your application. What can we suggest? Commented Sep 18, 2013 at 17:10
  • show the code, to give you targeted solution for problem. discuss db structure lil bit Commented Sep 18, 2013 at 17:41

3 Answers 3

1

Of course, if your site gets bigger, you will have problems putting everything on one page. That's logic, and you can't change it.

Different solutions:

It's obvious that if your database gets too big, it'll be impossible to simply dump all the data on one page. Even the quickest browsers would crash.

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

Comments

0

One thing what you can do is Memcached. It will store in cache those results. So for the next visitor, who chick on the same page will read a cached objects from sql not need to run again.

Other trick: order by Date asc if you have huge result, than better, faster to do it in PHP side, those can rally slow down the query if they need to do a full table scan.

Other like Yannik told: pagination ( this is basic, ofc ) and divide pages.

You can speed up the delay from pagination with pre-executing sql with Ajax: get count of total results for pagination.

Comments

0

Yes, obviously if you have a lot of queries on a single page then even in moderate traffic it can flood your database with queries.

Few Tips: 1)You should work on your database structure,how you have created tables,which table stores what,normalization etc.Try to optimise storage and retrieval of information so that in a single query,you fetch max. information.This will reduce the calls to database.

2)Never store and fetch redundant info (like age,that you can calculate from DOB) from database.

3)Pagination (as pointed earlier).

4)Caching

5)If you are updating small portions on your page at a time,then instead of loading entire page,use AJAX to update necessary portions.It will also increase interactivity.

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.