If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to handle too many rows in mysql server

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-11, 05:30
vibhavram vibhavram is offline
Registered User
 
Join Date: May 2010
Location: Hyderabd
Posts: 12
How to handle too many rows in mysql server

I have a classifieds site uses MySql as database server in which thousands of new ads are posted and each ad will be tagged with few tags. Now when I store each tag in a separate row along with the ad reference id, I could see about 3 to 4 thousands of rows are added to the table which is increasing load heavily day by day.

Here is the example of storing tags in a table.
postid tagname
1 real-estate
1 homes
1 best-homes
2 job
2 internet-jobs
2 workfromhome

Is there any way to decrease the load on the server. Can I split table into parts and store in different servers and use them as a single table when the query is executed?
Reply With Quote
  #2 (permalink)  
Old 09-25-11, 05:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
what efforts have you made to optimize your queries with appropriate indexes?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-25-11, 05:50
vibhavram vibhavram is offline
Registered User
 
Join Date: May 2010
Location: Hyderabd
Posts: 12
Quote:
Originally Posted by r937 View Post
what efforts have you made to optimize your queries with appropriate indexes?
I have only 2 columns(postid tagname) in the table and I created a Boolean index on postid.

Last edited by vibhavram; 09-25-11 at 05:55.
Reply With Quote
  #4 (permalink)  
Old 09-25-11, 05:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by vibhavram View Post
I have only 2 columns(postid tagname) in the table and I created a Boolean index on postid.
please do a SHOW CREATE TABLE on the table, and give an example of a search query that uses this table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-25-11, 06:07
vibhavram vibhavram is offline
Registered User
 
Join Date: May 2010
Location: Hyderabd
Posts: 12
Quote:
Originally Posted by r937 View Post
please do a SHOW CREATE TABLE on the table, and give an example of a search query that uses this table

I used following query to create table

CREATE TABLE `draggin_classifieds`.`cfd_tags` (
`postid` BIGINT NOT NULL ,
`tagname` VARCHAR( 128 ) NOT NULL ,
INDEX ( `postid` )
) ENGINE = InnoDB;

Now when I wnat to retrieve all the posts with a tagname I am using

SELECT * FROM cfd_tags WHERE tagname='sometag' LIMIT 0, 20;

Last edited by vibhavram; 09-25-11 at 06:18.
Reply With Quote
  #6 (permalink)  
Old 09-25-11, 06:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
that cannot possibly be the correct table layout, because if postid is the primary key, then there can be only one row for each postid, however, your example says you have multiple rows per postid like this --

1 real-estate
1 homes
1 best-homes
2 job
2 internet-jobs
2 workfromhome

so something is wrong, you have misrepresented something, and i can't help you until you clear this up
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 09-25-11, 06:20
vibhavram vibhavram is offline
Registered User
 
Join Date: May 2010
Location: Hyderabd
Posts: 12
Quote:
Originally Posted by r937 View Post
that cannot possibly be the correct table layout, because if postid is the primary key, then there can be only one row for each postid, however, your example says you have multiple rows per postid like this --

1 real-estate
1 homes
1 best-homes
2 job
2 internet-jobs
2 workfromhome

so something is wrong, you have misrepresented something, and i can't help you until you clear this up
I am sorry. I corrected the create table query above.

Here is that

CREATE TABLE `draggin_classifieds`.`cfd_tags` (
`postid` BIGINT NOT NULL ,
`tagname` VARCHAR( 128 ) NOT NULL ,
INDEX ( `postid` )
) ENGINE = InnoDB;
Reply With Quote
  #8 (permalink)  
Old 09-25-11, 08:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
remove the index on postid, then run the following two statements--
Code:
ALTER TABLE cfd_tags
ADD PRIMARY KEY ( postid , tagname )
Code:
ALTER TABLE cfd_tags
ADD INDEX ( tagname, postid )
then try your query again and see how fast it is
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On