Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2006, 12:59 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default indexing MySQL table

I am looking into indexing my MySQL table.

Should I index each column that i pick out in my script using the WHERE statement?

I ran this command to index 'picconame':

alter table picco add index(picconame)

Should this be done against all columns in the table access regularly?

Picco

www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old January 19th, 2006, 01:02 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

+---------+------+---------------+-------------+---------+--------+------+------------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+---------+------+---------------+-------------+---------+--------+------+------------------------------+
| picco | ref | picconame | picconame | 101 | const | 2119 | Using where; Using temporary |
+---------+------+---------------+-------------+---------+--------+------+------------------------------+

That is the result I get when I ran the above query with:
EXPLAIN SELECT DISTINCT piccoa FROM `picco` WHERE picconame = 'RFC'

www.crmpicco.co.uk
 
Old January 19th, 2006, 08:29 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Picco,

To determine what fields should be indexed, can you please supply:

1) A "describe [tablename]" output for the table
2) Three to five commonly run queries that include the table (especially include queries that join this table to other tables)

Thanks!

Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/
 
Old January 20th, 2006, 05:12 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

+---------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+---------+-------+
| piccocode | char(3) | YES | | | |
| stadiumname | varchar(100) | YES | | | |
| citycode | char(3) | YES | | | |
| cityname | varchar(100) | YES | | | |
| countrycode | char(2) | YES | | [NULL] | |
| provincecode | char(2) | YES | | [NULL] | |
| provincename | varchar(100) | YES | | | |
| provincecountrycode | char(2) | YES | | [NULL] | |
| picconame | varchar(100) | YES | MUL | | |
| Geog_loc | varchar(100) | YES | | [NULL] | |
| area | varchar(5) | YES | | [NULL] | |
| nationality | varchar(100) | YES | | [NULL] | |
| la | char(1) | YES | | [NULL] | |
| la1 | tinyint(10) | YES | | [NULL] | |
| la2 | tinyint(10) | YES | | [NULL] | |
| la3 | tinyint(10) | YES | | [NULL] | |
| lo | char(1) | YES | | [NULL] | |
| lo1 | tinyint(10) | YES | | [NULL] | |
| lo2 | tinyint(10) | YES | | [NULL] | |
| lo3 | tinyint(10) | YES | | [NULL] | |
+---------------------+--------------+------+-----+---------+-------+


www.crmpicco.co.uk
 
Old January 20th, 2006, 06:00 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

that is the result of:
Code:
DESCRIBE `picco`
some typical queries are
Code:
select piccocode from picco where countrycode = 'GB'
select provincename from picco where cityname = 'Glasgow'
select citycode from picco where countryname = 'United Kingdom'
I have already indexed countryname, and this is shown with the MUL (Multiple?) Key above?
Also, in MySQL CC there is a green diamond beside the column.


www.crmpicco.co.uk
 
Old January 20th, 2006, 06:00 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Also, there are no joins (inner or outer) run on this table

www.crmpicco.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL table names question cutesneakers PHP How-To 2 January 11th, 2005 12:35 AM
MySQL table types madhukp PHP Databases 1 December 16th, 2004 03:44 PM
mysql table hosefo81 PHP Databases 1 February 20th, 2004 04:09 PM
mysql discount table hosefo81 PHP Databases 0 December 12th, 2003 10:58 PM
CREATE TABLE error in MySQL k4rm4killer PHP Databases 2 December 9th, 2003 01:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.