views:

35

answers:

3

Hello

I'm using jQuery .ajax function to load php page with a mysql query in it that selects data from the database, but my question is: Does refreshing mysql query by jQuery ajax crashs or tiring the database?

Info: Refreshing by 1 second using setInterval().

Edited: This the queries that I use to refresh them.

SELECT * FROM table1 ORDER BY id DESC
SELECT * FROM table1 ORDER BY id ASC LIMIT 10
DELETE FROM table1 WHERE id = 'something'

I would you answer me. Thanks in advance

+1  A: 

No it does not crash the database (how could it?). Of course, if you're requesting the script running the mysql_query a lot it might result in a DoS (but normally it requires a very high amount of requests to bring down a server).

EDIT: Your update states you're using setInterval() with 1 second. It this case it depends on how many users will have that page open at the same time. E.g. say 1000 Users are on that site - this would result in 60.000 Requests + Queries being fired every minute. If your query is only a simple select it might not be a problem. If your doing a slow-query you might want to check the slow query log to improve your query - or alternatively change the behaviour of your script.

halfdan
+1  A: 

MySQL is capable of serving hundreds of queries per second, even when running on low-end hardware.

However, you could still be "tiring" the database server, especially if you're running a very complex query, or if you do not have the necessary indexes on your tables. You may want to use the EXPLAIN syntax to see how MySQL is executing your query.

Daniel Vassallo
A: 

What is the mysql query? Is it user specific? If not, it would be much better to cache the value server side once per second and use ajax to fetch this cached file rather than have all of your users simultaneously requesting the same data.

Mahdi.Montgomery