Jump to content

Recommended Posts

Hi

 

I am redoing a friends website and he has a log of files accessed held in a SQL database.

 

At the moment he has 550,000 records, but it's becoming a bit slow when queries are run.

 

Would it therefore be better to have multiple tables of data, most likely stamped by month

 

log_june2010

log_july2010

log_august2010

 

and so on, and just tie them over with JOINS, or is it better to tweak the current table and optimise it a little and let it continue to fill up?

 

thanks very much

Link to comment
https://forums.phpfreaks.com/topic/215858-whats-best/
Share on other sites

The first thing that pops into my mind is what columns are queried and are they indexed?

 

If not, I would index the columns that the database is queried on (excluding the Primary Key as that is indexed by default). You should not need to separate them out into different tables.

Link to comment
https://forums.phpfreaks.com/topic/215858-whats-best/#findComment-1122137
Share on other sites

oh ok, so what is the max number of rows a database table can handle?

 

It might not be indexed as there is likely to be 10 times more data being processed, so it could be a non indexed table with 2+ million records.

 

Indexing the database every second might be too much eh?

Link to comment
https://forums.phpfreaks.com/topic/215858-whats-best/#findComment-1122171
Share on other sites

Databases were made for large amounts of data. To optimize it, you should index only rows you will query. If you plan on having a search you should look into Full Text searching or another searching type option such as Sphynx. But splitting the data into two separate tables should not be done as you would have to query the second table as well and there in you now have two queries you have to run and it will tax the database just the same, if not harder.

Link to comment
https://forums.phpfreaks.com/topic/215858-whats-best/#findComment-1122200
Share on other sites

ok, but surely as the number of rows in the database increase, the slower the database would become because it's having to do a query on a table holding tons of data?

 

So if having multiple tables that spread the data is not a good idea, then how do I handle the tables becoming very slow as they get bigger?

 

Data might be added in very often, so surely if I index it every time some new data is added, the whole system will slow down even more?

Link to comment
https://forums.phpfreaks.com/topic/215858-whats-best/#findComment-1122861
Share on other sites

ok, but surely as the number of rows in the database increase, the slower the database would become because it's having to do a query on a table holding tons of data?

That's why databases were invented: to handle large amounts of data. They are designed to do queries on tables holding "tons" of data.

 

So if having multiple tables that spread the data is not a good idea, then how do I handle the tables becoming very slow as they get bigger?

as premiso said: "index the columns that the database is queried on". An index provides a pointer to the rows that contain the indexed data, this way the database server can go directly to the indexed data instead of having to read thousands of rows.

 

Data might be added in very often, so surely if I index it every time some new data is added, the whole system will slow down even more?

as juddster said: "You don't need to keep re-indexing tables"  You create the index ONCE then whenever data is added to (or removed from) the table, the database server updates the indexes.

 

The database servers have tools to evaluate a query so you can see where indexes need to be created.  See EXPLAIN PLAN

Link to comment
https://forums.phpfreaks.com/topic/215858-whats-best/#findComment-1122877
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.