473,387 Members | 1,606 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,387 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 2795
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.