Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- Using Cron Job to process PHP scripts
- job interview questions (1)
- Install PHPMailer 5.2.4 and use smtp gmail
- PHP connect IBM db2 database in XAMPP
- Set up a child account and set screen time limit in Windows 8
- PHP - Export Content to MS Word document
- Datatable export excel wraptext and newline
- Sweet Alert JS library - beautiful replacement of JavaScript Alert
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
Thursday, December 6, 2012
When to use MySQL index
Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows.
According to MySQL document: " If a table has 1,000 rows, this is at least 100 times faster than reading sequentially"
Indexes are best used on columns that are frequently used in where clauses, jpin, min(), max()and in any kind of sorting, such as "order by". But it will slow down for e it will slow down MySQL "update" and "insert".
Suppose we have table employees:
CREATE TABLE employees (
ID INT,
name VARCHAR(60) );
We can create an index for name in table empoyees:
create index name_index on employees (name);
To see the index created:
SHOW CREATE TABLE employees;
return
+-----------+------------------------------------------------
-------------------------------------------------------+
| Table | Create Table
|
+-----------+------------------------------------------------
-------------------------------------------------------+
| employees | CREATE TABLE `employees` (
`ID` int(11) default NULL,
`name` varchar(60) default NULL,
KEY `name_index` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-----------+------------------------------------------------
-------------------------------------------------------+
1 row in set (0.00 sec)
You will be much faster by using index in name for the following query:
select * from employees where name ='smith';
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment