473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Table optimizing for big table. Need advice.

Hi.

I need a little help to optimize requests on a table, and I have no
idea how to do it (I optimized already a lot other table, but this one
is a pain). My table looks like :

CREATE TABLE comments (
id int(11) NOT NULL auto_increment,
subject varchar(80) NOT NULL default '',
timestamp timestamp(14) NOT NULL,
user_id int(6) NOT NULL default '1',
com_parent int(11) NOT NULL default '0',
res_type int(5) NOT NULL default '1',
PRIMARY KEY (id),
KEY id (id),
KEY news_id (news_id),
KEY user_id (user_id),
KEY com_parent (com_parent),
KEY res_type (res_type),
KEY timestamp (timestamp),
KEY thread_id (thread_id)
) TYPE=MyISAM PACK_KEYS=1;

It has about 500.000 entries. A simple select like :

SELECT id,subject FROM commentsnew WHERE user_id=9790 AND res_type != 3
ORDER BY id DESC LIMIT 20;

takes about 4 seconds !! :( If I run it fews times, after 3 times it
goes ok (0.03). Any idea to improve it ? I tried to go in InnoDB but it
goes as slow as on MyISAM. a 'DESC' on the request shows :

+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
| comments | ref | user_id,user_id_restypeid | user_id | 4 |
const | 1602 | where used; Using filesort |
+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
For information we did setup mysql with :

set-variable = key_buffer=32M
set-variable = max_allowed_packet=2M
set-variable = thread_stack=2M
set-variable = table_cache=1024
set-variable = sort_buffer=4M
set-variable = record_buffer=2M
set-variable = join_buffer=2M
set-variable = tmp_table_size=2M
set-variable = flush_time=0

Jul 20 '05 #1
2 2794
Fabien Penso wrote:
CREATE TABLE comments (
id int(11) NOT NULL auto_increment,
subject varchar(80) NOT NULL default '',
timestamp timestamp(14) NOT NULL,
user_id int(6) NOT NULL default '1',
com_parent int(11) NOT NULL default '0',
res_type int(5) NOT NULL default '1',
PRIMARY KEY (id),
KEY id (id),
KEY news_id (news_id),
KEY user_id (user_id),
KEY com_parent (com_parent),
KEY res_type (res_type),
KEY timestamp (timestamp),
KEY thread_id (thread_id)
) TYPE=MyISAM PACK_KEYS=1;
Here's an excerpt from http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html:

"KEY is normally a synonym for INDEX. From MySQL 4.1, the key attribute
PRIMARY KEY can also be specified as just KEY when given in a column
definition. This was implemented for compatibility with other database
systems."

Is it possible that you are using 4.1, and specifying KEY is being
ignored because it's not valid to have more than one primary key per
table? I'm just speculating here, but try changing KEY to INDEX and see
if it changes anything.
SELECT id,subject FROM commentsnew WHERE user_id=9790 AND res_type != 3
ORDER BY id DESC LIMIT 20;


What happens if you ORDER BY id ASC or eliminate the LIMIT? MySQL is
supposed to have bidirectional indexes, I think, but it's worth an
experiment.

Regards,
Bill K.
Jul 20 '05 #2
For a full indexed lookup, you might wanna try adding an index to the
table, suited for that particular query.

CREATE INDEX idxUserRes ON comments (user_id, res_type);

only run once of course :)
\sBeam
Fabien Penso wrote:
Hi.

I need a little help to optimize requests on a table, and I have no
idea how to do it (I optimized already a lot other table, but this one
is a pain). My table looks like :

CREATE TABLE comments (
id int(11) NOT NULL auto_increment,
subject varchar(80) NOT NULL default '',
timestamp timestamp(14) NOT NULL,
user_id int(6) NOT NULL default '1',
com_parent int(11) NOT NULL default '0',
res_type int(5) NOT NULL default '1',
PRIMARY KEY (id),
KEY id (id),
KEY news_id (news_id),
KEY user_id (user_id),
KEY com_parent (com_parent),
KEY res_type (res_type),
KEY timestamp (timestamp),
KEY thread_id (thread_id)
) TYPE=MyISAM PACK_KEYS=1;

It has about 500.000 entries. A simple select like :

SELECT id,subject FROM commentsnew WHERE user_id=9790 AND res_type != 3
ORDER BY id DESC LIMIT 20;

takes about 4 seconds !! :( If I run it fews times, after 3 times it
goes ok (0.03). Any idea to improve it ? I tried to go in InnoDB but it
goes as slow as on MyISAM. a 'DESC' on the request shows :

+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
| comments | ref | user_id,user_id_restypeid | user_id | 4 |
const | 1602 | where used; Using filesort |
+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
For information we did setup mysql with :

set-variable = key_buffer=32M
set-variable = max_allowed_packet=2M
set-variable = thread_stack=2M
set-variable = table_cache=1024
set-variable = sort_buffer=4M
set-variable = record_buffer=2M
set-variable = join_buffer=2M
set-variable = tmp_table_size=2M
set-variable = flush_time=0

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CoOL! . | last post by:
Hello, I found the key to solve this problem in: http://darkstar.ist.utl.pt/mysql/doc/en/InnoDB_foreign_key_constraints.html You'll probably need an INDEX for that new foreign key you are...
4
by: Matt | last post by:
Hi all, We recently upsized two Microsoft Access Databases to SQL. We're using an ADP (2002) as the front end. All the conversion issues have been resolved, except for one: Whenever we...
1
by: Tamir Khason | last post by:
Hi, all This time I need advice - no help ;) I have following architecture: 30 server with 100 devices connected each one Each "device" implement some (between 1 and 10) different interfaces All...
1
by: Chris Lane | last post by:
Need Advice on prebuilt Exception Assemblies Please take a look at my post on the Titled: Need Advice on prebuilt Exception Assemblies posted on 04/21/04 Thank
3
by: hazly | last post by:
I'm very new in the web technology and need advice on search engine. I want to develop a portal using PHP and MySQL on Linux. Need to know on the following features : 1. search engine that could...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
5
by: Eric Layman | last post by:
Hi, Many years ago when I first learnt abt web dev in school, I was taught this methodology: <html> blah blabh
1
by: shapper | last post by:
Hello, I need to create a data object to hold a number of records with 3 columns. A datatable would do. My problem is this: 1. I will use this as a GridView datasource. 2. I will need to...
7
by: SM | last post by:
Hello, I have a index.php template (2 columns). The right columns contains a bunch of links (interviews, poems, etc...) The left columns contains the actual article. So if I click on a link on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.