Home > USING FILESORTを消すにはインデックス作成だけでは足りない場合があるのでFORCE INDEXで強制する

USING FILESORTを消すにはインデックス作成だけでは足りない場合があるのでFORCE INDEXで強制する

  • June 29, 2007 11:35 AM
[world]>explain select * from city where countrycode='JPN' o
rder by name\G
*************************** 1. row *************************
**
           id: 1
  select_type: SIMPLE
        table: city
         type: ref
possible_keys: CountryCode
          key: CountryCode
      key_len: 3
          ref: const
         rows: 248
        Extra: Using where; Using filesort
1 row in set (0.00 sec)

[world]>create index idx1 on city(name);
Query OK, 4079 rows affected (0.26 sec)
Records: 4079  Duplicates: 0  Warnings: 0

[world]>explain select * from city where countrycode='JPN' o
rder by name\G
*************************** 1. row *************************
**
           id: 1
  select_type: SIMPLE
        table: city
         type: ref
possible_keys: CountryCode
          key: CountryCode
      key_len: 3
          ref: const
         rows: 248
        Extra: Using where; Using filesort
1 row in set (0.00 sec)

[world]>show create table city;
+-------+---------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
-----+
| Table | Create Table





     |
+-------+---------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
-----+
| city  | CREATE TABLE `city` (
  `ID` int(11) NOT NULL auto_increment,
  `Name` char(35) NOT NULL default '',
  `CountryCode` char(3) NOT NULL default '',
  `District` char(20) NOT NULL default '',
  `Population` int(11) NOT NULL default '0',
  PRIMARY KEY  (`ID`),
  KEY `CountryCode` (`CountryCode`),
  KEY `idx1` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
-----+
1 row in set (0.00 sec)

と思ったら、FORCE INDEXでUSING FILESORTが消えた

[world]>explain select * from city force index(idx1) where c
ountrycode='JPN' order by name\G
*************************** 1. row *************************
**
           id: 1
  select_type: SIMPLE
        table: city
         type: index
possible_keys: NULL
          key: idx1
      key_len: 35
          ref: NULL
         rows: 4070
        Extra: Using where
1 row in set (0.00 sec)


Home > USING FILESORTを消すにはインデックス作成だけでは足りない場合があるのでFORCE INDEXで強制する

Search
Feeds

Return to page top