mysql update 有无索引对比
<pre name="code" class="html">mysql> desc ProductInfo;
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| sn | int(11) | NO | PRI | NULL | |
| productIntro | text | NO | | NULL | |
| borrowerInfo | text | NO | | NULL | |
| realBorrower | varchar(128) | YES | | NULL | |
| capitalPurpose | text | NO | | NULL | |
| repaySource | text | NO | | NULL | |
| riskInfo | text | NO | | NULL | |
| safeguard | varchar(50) | NO | | | |
| contractSn | int(11) | YES | | NULL | |
| delegator | int(11) | NO | | NULL | |
| custody | varchar(125) | NO | | | |
| riskLevel | char(1) | NO | | NULL | |
+----------------+--------------+------+-----+---------+-------+
12 rows in set (0.00 sec) mysql> show index from ProductIno;
ERROR 1146 (42S02): Table 'zjzc.ProductIno' doesn't exist
mysql> show index from ProductInfo;
+-------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| ProductInfo | 0 | PRIMARY | 1 | sn | A | 283 | NULL | NULL | | BTREE | | |
+-------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.01 sec) mysql> select sn,contractSn from ProductInfo where contractSn=45;
+-----+------------+
| sn | contractSn |
+-----+------------+
| 58 | 45 |
| 301 | 45 |
+-----+------------+
2 rows in set (0.00 sec) mysql> explain update ProductInfo set contractSn=99 where contractSn=45;
+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | ProductInfo | index | NULL | PRIMARY | 4 | NULL | 283 | Using where |
+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.07 sec) mysql> create index ProductInfo_idx1 on ProductInfo(contractSn);
Query OK, 0 rows affected (0.23 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> explain update ProductInfo set contractSn=99 where contractSn=45;
+----+-------------+-------------+-------+------------------+------------------+---------+-------+------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------+-------+------------------+------------------+---------+-------+------+------------------------------+
| 1 | SIMPLE | ProductInfo | range | ProductInfo_idx1 | ProductInfo_idx1 | 5 | const | 2 | Using where; Using temporary |
+----+-------------+-------------+-------+------------------+------------------+---------+-------+------+------------------------------+
1 row in set (0.00 sec) /***************************************************************************************************8 mysql> show create table test100\G;
*************************** 1. row ***************************
Table: test100
Create Table: CREATE TABLE `test100` (
`sn` int(11) NOT NULL COMMENT 'product sn',
`productIntro` text NOT NULL COMMENT '产品介绍',
`borrowerInfo` text NOT NULL COMMENT '借款方信息',
`realBorrower` varchar(128) DEFAULT NULL COMMENT '实际借款人',
`capitalPurpose` text NOT NULL COMMENT '资金用途',
`repaySource` text NOT NULL COMMENT '还款来源',
`riskInfo` text NOT NULL COMMENT '风控信息',
`safeguard` varchar(50) NOT NULL DEFAULT '' COMMENT '保障信息代码列表,格式1,2,3,4',
`contractSn` int(11) DEFAULT NULL COMMENT '合同模版',
`delegator` int(11) NOT NULL COMMENT '产品委托人',
`custody` varchar(125) NOT NULL DEFAULT '' COMMENT '产品管理人',
`riskLevel` char(1) NOT NULL COMMENT '风险级别'
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec) ERROR:
No query specified mysql> show index from test100;
Empty set (0.00 sec) mysql> explain update test100 set contractSn=99 where contractSn=45;
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | test100 | ALL | NULL | NULL | NULL | NULL | 283 | Using where |
+----+-------------+---------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec) mysql> create index test100_idx1 on test100(contractSn);
Query OK, 0 rows affected (0.36 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> explain update test100 set contractSn=99 where contractSn=45;
+----+-------------+---------+-------+---------------+--------------+---------+-------+------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+-------+---------------+--------------+---------+-------+------+------------------------------+
| 1 | SIMPLE | test100 | range | test100_idx1 | test100_idx1 | 5 | const | 2 | Using where; Using temporary |
+----+-------------+---------+-------+---------------+--------------+---------+-------+------+------------------------------+
1 row in set (0.03 sec)
mysql update 有无索引对比的更多相关文章
- MySQL和Lucene索引对比分析
MySQL和Lucene都可以对数据构建索引并通过索引查询数据,一个是关系型数据库,一个是构建搜索引擎(Solr.ElasticSearch)的核心类库.两者的索引(index)有什么区别呢?以前写过 ...
- Mysql update 索引
执行mysql update,或者delete的时候会遇到: You can't specify target table for update in FROM clause 相关的原因自不必说:下面 ...
- Mysql数据库的索引原理
写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...
- Mysql 和 Postgresql(PGSQL) 对比
Mysql 和 Postgresql(PGSQL) 对比 转载自:http://www.oschina.net/question/96003_13994 PostgreSQL与MySQL比较 MySQ ...
- 【Mysql优化】索引优化策略
1:索引类型 1.1 B-tree索引 注: 名叫btree索引,大的方面看,都用的平衡树,但具体的实现上, 各引擎稍有不同, 比如,严格的说,NDB引擎,使用的是T-tree Myisam,in ...
- 千万级MySQL数据库建立索引,提高性能的秘诀
实践中如何优化MySQL 实践中,MySQL的优化主要涉及SQL语句及索引的优化.数据表结构的优化.系统配置的优化和硬件的优化四个方面,如下图所示: SQL语句及索引的优化 SQL语句的优化 SQL语 ...
- 阿里面试:MySQL如何设计索引更高效?
有情怀,有干货,微信搜索[三太子敖丙]关注这个不一样的程序员. 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试完整考点.资料以及我的系列文章. ...
- mysql 高级和 索引优化,目的:查的好,查的快,性能好
1-事物隔离级别: 更新丢失, 并发情况下,对同一字段进行更新,就会出现更新丢失,采用乐观锁,比较版本号或时间戳可解决 读未提交 解决了更新丢失但是会引起脏读, 二个session.sessionA中 ...
- MySQL引擎、索引和优化(li)
一.存储引擎 存储引擎,MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择不同的技术 ...
随机推荐
- UISearchBar控件
摘自:http://blog.sina.com.cn/s/blog_7b9d64af0101dfg8.html UISearchBar控件就是要为你完成搜索功能的一个专用控件.它集成了很多你意想不到的 ...
- java.lang.NoClassDefFoundError: ognl/PropertyAccessor解决的方法
本来不想为这个专门写一篇文章的,可是发现这么简单的一个问题居然没有人好好回答过.从方便搜索的角度考虑,特意取了这么一个题目. 事实上解决方法就是将ognl的jar包增加就可以. 比方我用的是ognl3 ...
- 利用navicat for oracle将数据库全部数据移动
话不多说.直接上图. 1.首先选择自己的数据库. 右键,data transfer 2.选择相应源数据库,目标数据库.点击start就可以.假设中间失败,可多尝试几次. 2.
- javascript每日一练(四)——DOM二
一.DOM的创建,插入,删除 createElement(标签名) appendChild(节点) insertBefore(节点,原有节点) removeChild(节点) <!doctype ...
- vi/vim高级命令集粹
vi/vim高级命令集粹 (ctrl +v过来 留着以后看) 1.交换两个字符位置 xp 2.上下两行调换 ddp 3.把文件内容反转 :g/^/m0/ (未通过) 4.上下两行合并 J 5.删除所有 ...
- linux下crontab的使用方法
<span style="font-size:14px;">在Linux中任务可以被配置在指定的时间段.指定的日期.或系统平均载量低于指定的数量时自动运行. cront ...
- 几种经典的数据排序及其Java实现
选择排序 思想 n个记录的文件的直接选择排序可经过n-1趟直接选择排序得到有序结果: ①初始状态:无序区为R[1..n],有序区为空. ②第1趟排序 在无序区R[1..n]中选出关键字最小的记录R[k ...
- Spring boot jar 后台运行
start(){ now=`date "+%Y%m%d%H%M%S"` exec java -Xms256m -Xmx512m -jar /alidata/server/webap ...
- 问题:Excel在“xxx.xlsx”中发现不可读取的内容。是否恢复此工作薄的内容?【原创】
现象: 点"是(Y)" 提示信息中提到的error242440_02.xml文件: 问题重现: package poi; import java.io.FileNotFoundEx ...
- iOS学习——UI基础UIButton(七)
前面写了UIWindow.UIViewController,那些都是一些框架,框架需要填充上具体的view才能组成我们的应用,移动应用开发中UI占了很大一部分,最基础的UI实现是使用系统提供的各种控件 ...