-- MySQL dump 10.13 Distrib 5.1.52, for redhat-linux-gnu (x86_64) -- -- Host: 127.0.01 Database: ss -- ------------------------------------------------------ -- Server version 5.1.52 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `t1` -- DROP TABLE IF EXISTS `t1`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, `f2` int(11) DEFAULT NULL, KEY `t1f2f1` (`f2`,`f1`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `t1` -- LOCK TABLES `t1` WRITE; /*!40000 ALTER TABLE `t1` DISABLE KEYS */; INSERT INTO `t1` VALUES (1,1),(2,1),(3,1),(4,2),(2,3),(10,10),(0,1),(1,10); /*!40000 ALTER TABLE `t1` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `t2` -- DROP TABLE IF EXISTS `t2`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `t2` ( `f2` int(11) DEFAULT NULL, `f3` varchar(10) DEFAULT NULL, KEY `t2f3` (`f3`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `t2` -- LOCK TABLES `t2` WRITE; /*!40000 ALTER TABLE `t2` DISABLE KEYS */; INSERT INTO `t2` VALUES (1,'a'),(2,'b'),(10,'c'); /*!40000 ALTER TABLE `t2` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2012-01-02 18:03:58 insert into t1 select * from t1; insert into t1 select * from t1; insert into t1 select * from t1; insert into t1 select * from t1; insert into t1 select * from t1; insert into t1 select * from t1; insert into t1 select * from t1; insert into t1 select * from t1; flush status; select sql_no_cache max(f1) as 'Query f2 = 1' from t1 where f2 = 1; show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f2 = 10' from t1 where f2 = 10; show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f2 in (1,10)' from t1 where f2 in (1,10); show status like 'handler_read%'; flush status; select sql_no_cache max(f) as 'Complex union' from (select sql_no_cache max(f1) as f from t1 where f2 = 1 UNION select max(f1) as f from t1 where f2 = 10) as b; show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f3 = a (using subquery)' from t1 where f2 = (select t2.f2 from t2 where f3 = 'a'); show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f3 = a (using join)' from t1 join t2 on t1.f2 = t2.f2 where f3 = 'a'; show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f3 = c (using subquery)' from t1 where f2 = (select t2.f2 from t2 where f3 = 'c'); show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f3 = c (using join)' from t1 join t2 on t1.f2 = t2.f2 where f3 = 'c'; show status like 'handler_read%'; flush status; select sql_no_cache max(f1) as 'Query f2 IN subquery' from t1 where f2 IN (select t2.f2 from t2 where f3 in('a', 'c')); show status like 'handler_read%'; flush status; select sql_no_cache max(f) as 'Query using complex join' from (select sql_no_cache max(f1) as f from t1 where f2 = (select t2.f2 from t2 where f3 = 'a') UNION select max(f1) as f from t1 where f2 = (select t2.f2 from t2 where f3 = 'c')) as b; show status like 'handler_read%';