两条SQL语句比较,哪个好点
explain 出来的结果。。
第一个SQL,TYPE为range,扫描的行数只有168,运行的速度为:0.02sec
第二个SQL, TYPE为ref,扫描的行数为436,运行的速度为:0.02sec - 0.03sec
从上面EXPLAIN出来的数据,哪个SQL会更好些。。
+----+-------------+-------+--------+---------------+------------+---------+--------------------------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+------------+---------+--------------------------------------+------+--------------------------+
| 1 | SIMPLE | pd | range | PRIMARY | PRIMARY | 8 | NULL | 168 | Using where; Using index |
| 1 | SIMPLE | p | eq_ref | PRIMARY | PRIMARY | 4 | kleehaus_wedding.pd.product_id | 1 | Using where |
| 1 | SIMPLE | p2s | eq_ref | PRIMARY | PRIMARY | 8 | kleehaus_wedding.pd.product_id,const | 1 | Using where; Using index |
| 1 | SIMPLE | ps | ref | product_id | product_id | 4 | kleehaus_wedding.p.product_id | 1 | Using index |
+----+-------------+-------+--------+---------------+------------+---------+--------------------------------------+------+--------------------------+
+----+-------------+-------+--------+---------------------+-------------+---------+---------------------------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------------+-------------+---------+---------------------------------------+------+--------------------------+
| 1 | SIMPLE | p2c | ref | PRIMARY,category_id | category_id | 4 | const | 436 | Using where |
| 1 | SIMPLE | pd | eq_ref | PRIMARY | PRIMARY | 8 | kleehaus_wedding.p2c.product_id,const | 1 | Using where; Using index |
| 1 | SIMPLE | p | eq_ref | PRIMARY | PRIMARY | 4 | kleehaus_wedding.p2c.product_id | 1 | Using where |
| 1 | SIMPLE | ps | ref | product_id | product_id | 4 | kleehaus_wedding.p.product_id | 1 | Using index |
| 1 | SIMPLE | p2s | eq_ref | PRIMARY | PRIMARY | 8 | kleehaus_wedding.pd.product_id,const | 1 | Using where; Using index |
+----+-------------+-------+--------+---------------------+-------------+---------+---------------------------------------+------+--------------------------+
第一个SQL,TYPE为range,扫描的行数只有168,运行的速度为:0.02sec
第二个SQL, TYPE为ref,扫描的行数为436,运行的速度为:0.02sec - 0.03sec
从上面EXPLAIN出来的数据,哪个SQL会更好些。。
...全文
相关推荐
SQL注入语句
经典的SQL注入语句,里面有的有注释啊,可以参考使用
sql语句妙用,各种sql语句的详细用法与讲解
sql语句妙用,各种sql语句的详细用法与讲解 ,使得程序运行的更加流畅。主要针对一些高效sql语句的解释。
SQL三种删除语句的用法比较
SQL三种删除语句的用法比较:drop、truncate、delete。
MySql获取某个字段存在于哪个表的sql语句
本文为大家详细介绍下通过MySql查询某个字段所在表是哪一个,具体的sql语句如下,感兴趣的朋友可以参考下,希望对大家有所帮助
sql语句、动态SQL语句基本语法
sql语句、动态SQL语句基本语法,里面有很多很有用的sql语句。



