Jump to content

Cluster a table


jaymc

Recommended Posts

I have a huge table with 3,000,000 records in which is heavily accessed

 

I need to do something about it because its causing problems with load

 

I was thinking of taking the username field and moving usernames starting from A-D into an A-D table, usernames starting with E-H to an E-H table, etc etc

 

So I would have maybe 8 tables with 250,000,000 rows in..

 

That would also give me the opportunity to spread the tables onto different servers

 

Thats what ive come up with, is that the best way to go about it when you have a huge heavily accessed table?

 

Feedback would be great

 

Thanks

Link to comment
Share on other sites


I was thinking of taking the username field and moving usernames starting from A-D into an A-D table, usernames starting with E-H to an E-H table, etc etc

 

this is good it even better if you do that per letter but take note about the realtionship of the table consider how are you going to join them say if you searc a record on the other table then you will have to match them in your a-z tables 

Link to comment
Share on other sites

I've never dealt with an issue like this before and have no idea what kind of search capabilities you hope to provide, but if you break them up A-D, E-F, etc. you will have to continuously adjust who goes where to keep the load fairly distributed.

 

A good hashing function can do this for you.  Let's say you want to distribute across N tables:

users0, users1, ..., usersN

 

You create a hash function:

  // returns an int between 0 and N inclusive based on user name
  function username_to_table_hash($user){
    // perform magic
    return $hash;
  }

 

Usage:

  $uname = clean_post_value($_POST["uname"]);
  $tbl = "users" . username_to_table_hash($uname);
  $q = mysql_query( "SELECT * FROM {$tbl} WHERE uname={$uname} LIMIT 1" );

 

Don't know how practical that'd be though; I got the idea from when I wrote a hash table back in college.  :D

Link to comment
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.