Tricks to speed up your querys.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
visonardo
Forum Contributor
Posts: 136
Joined: Mon Oct 02, 2006 7:49 pm
Location: Argentina, South America´s Sun.

Tricks to speed up your querys.

Post by visonardo »

Im not an expert about it but i can say somethings and you too that will be so useful to others ;)
Well, i searched but didnt find anything about that


Start!
  • Select fields: there i read that take more time to find how many field your table has than take field that you write, and its obvius.
    • (slow): mysql_query("SELECT * FROM table",$link);
    • (quick): mysql_query("SELECT field1, field2, field3 FROM table",$link);
  • Count how many rows has your table (suposed that you need just rows´s ammount):
    • (so slow) take more memory than really need:
      $sql=mysql_query("SELECT * FROM table",$link);
      $sql_link=mysql_fetch_assoc($sql);
      $cant=mysql_num_rows($sql_link);
    • (quick): $sql=mysql_query("SELECT count(*) as ammount_field FROM table",$link);
      $sql_link=mysql_fetch_assoc($sql);
      $cant=$sql_link['ammount_field'];

Well, hope it be useful to many people and please, sorry if my english is poor. Dont forget tell us your recomendations to speed up our script. The idea would be to do a list here with all tricks :lol:


Thank all.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

For performance issues, this URL will helpful :
http://sheeri.net/index.php?tag=performance
Post Reply