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 > redundant indexes?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-14-04, 01:05
robw robw is offline
Registered User
 
Join Date: Mar 2004
Posts: 1
redundant indexes?

Hello. I have a MySQL database in which some of the tables have 2 indexes on the same column. Here's an example of what I mean:

CREATE TABLE `posts` (
`pid` int(10) unsigned NOT NULL auto_increment,
`message` text NOT NULL,
PRIMARY KEY (`pid`),
KEY `pid` (`pid`)
) TYPE=MyISAM;

In an attempt to make the database more efficient, someone added more indexes, even on columns that were already primary keys.

What effect does this have on the database? If the extra keys aren't helping, can I safely delete them without affecting my data? For example:

ALTER TABLE posts DROP INDEX pid;

Thanks in advance. BTW, nice forums you've got here!
Reply With Quote
  #2 (permalink)  
Old 03-17-04, 02:43
trieder trieder is offline
Registered User
 
Join Date: Sep 2003
Posts: 69
That is odd. If anything, it would seem like it would slow it down (mysql optimizer has to think about what to do with extra indices?). My suggestion is create the table like so:

CREATE TABLE `posts` (
`pid` int unsigned NOT NULL auto_increment,
`message` text,
PRIMARY KEY (`pid`),
INDEX(pid)
) TYPE=MyISAM;

I removed the not null "constraint" from the text portion because you will most likely be using asp/php/perl to check to see if it's empty before you allow the post anyway... (and you're checking the return value from the insert anyway).
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