搜索
首页数据库mysql教程update优化一条。

原语句 update HAHA a set (td03_flag) = (select td03_flag from z_temp1 b where a.user_id = b.user_id and lx = pz) Plan hash value: 1855602026 SQL_ID 62h7a9s7yyr18, child number 0------------------------------------- update HAHA a set (td03_

原语句

update HAHA a set (td03_flag) = (select td03_flag

from z_temp1 b where a.user_id = b.user_id and lx = 'pz')

Plan hash value: 1855602026
SQL_ID  62h7a9s7yyr18, child number 0
-------------------------------------
 update HAHA a set (td03_flag) = (select td03_flag
from z_temp1 b where a.user_id = b.user_id and lx = 'pz')

Plan hash value: 1855602026

-------------------------------------------------------------------------------------------------------------
| Id  | Operation                         | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------------------------
|   0 | UPDATE STATEMENT                  |                         |       |       |  8720M(100)|          |
|   1 |  UPDATE                           | HAHA 	            |       |       |            |          |
|   2 |   TABLE ACCESS FULL               | HAHA         	    |  2094K|    51M|  5404   (3)| 00:01:05 |
|   3 |   TABLE ACCESS BY INDEX ROWID     | Z_TEMP1                 | 24383 |   714K|  4163   (2)| 00:00:50 |
|   4 |    BITMAP CONVERSION TO ROWIDS    |                         |       |       |            |          |
|   5 |     BITMAP AND                    |                         |       |       |            |          |
|   6 |      BITMAP CONVERSION FROM ROWIDS|                         |       |       |            |          |
|*  7 |       INDEX RANGE SCAN            | Z_TEMP1_U               |  2438K|       |     3   (0)| 00:00:01 |
|   8 |      BITMAP CONVERSION FROM ROWIDS|                         |       |       |            |          |
|*  9 |       INDEX RANGE SCAN            | Z_TEMP1_L               |  2438K|       |  4108   (2)| 00:00:50 |
-------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------

   7 - access("B"."USER_ID"=:B1)
   9 - access("LX"='pz')

我们可以看第7步的谓词7 - access("B"."USER_ID"=:B1) 这种:B1 是一个变量,变量就有输入源,这里的变量的输入源就是第2步中的每一行 

我们就可以简单理解为,就是第2步有多少条语句,第三步就要执行多少次(7是第三步的子步骤,从这一步开始,一直执行完整个 第3步) 这种行为即是Nested loop。

虽然这里有索引,但这里的整个过程,是 两个位图索引 bitmap and,并且会回表,都是单块读,其中回表的单块读在这里占大头(每次都有24383个单块读)的。 我们从统计信息看到 步骤2 有2094K 行 我们可以简单认为, 第三步 这个整个步骤(bitmap and +回表) 被整个执行了 2094K即200多万次。 不慢才怪 

优化后语句

explain plan for merge into HAHA a
using (select td03_flag, user_id
from z_temp1 b
where user_id in (select user_id
from HAHA where lx='pz')
) h
on (a.user_id = h.user_id)
when matched then
update set a.td03_flag = h.td03_flag;

这里需要创建两个索引

create index HAHA_IDX on HAHA(lx,user_id) ;
create index z_temp1_ind_uidtd03 on z_temp1(userid,td03_flag) ;

优化前SQL2个小时还没跑完

之后虽然执行时间对方没有反馈,但对方也没有再喊叫 看来满足需求了:)

优化虽易,乙方不易,且行且珍惜

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
mysql:blob和其他无-SQL存储,有什么区别?mysql:blob和其他无-SQL存储,有什么区别?May 13, 2025 am 12:14 AM

mysql'sblobissuitableForStoringBinaryDataWithInareLationalDatabase,而alenosqloptionslikemongodb,redis和calablesolutionsoluntionsoluntionsoluntionsolundortionsolunsolunsstructureddata.blobobobsimplobissimplobisslowderperformandperformanceperformancewithlararengelitiate;

mySQL添加用户:语法,选项和安全性最佳实践mySQL添加用户:语法,选项和安全性最佳实践May 13, 2025 am 12:12 AM

toaddauserinmysql,使用:createUser'username'@'host'Indessify'password'; there'showtodoitsecurely:1)choosethehostcarecarefullytocon trolaccess.2)setResourcelimitswithoptionslikemax_queries_per_hour.3)usestrong,iniquepasswords.4)Enforcessl/tlsconnectionswith

MySQL:如何避免字符串数据类型常见错误?MySQL:如何避免字符串数据类型常见错误?May 13, 2025 am 12:09 AM

toAvoidCommonMistakeswithStringDatatatPesInMysQl,CloseStringTypenuances,chosethirtightType,andManageEngencodingAndCollat​​ionsEttingsefectery.1)usecharforfixed lengengters lengengtings,varchar forbariaible lengength,varchariable length,andtext/blobforlabforlargerdata.2 seterters seterters seterters seterters

mySQL:字符串数据类型和枚举?mySQL:字符串数据类型和枚举?May 13, 2025 am 12:05 AM

mysqloffersechar,varchar,text,and denumforstringdata.usecharforfixed Lengttrings,varcharerforvariable长度,文本forlarger文本,andenumforenforcingDataAntegrityWithaEtofValues。

mysql blob:如何优化斑点请求mysql blob:如何优化斑点请求May 13, 2025 am 12:03 AM

优化MySQLBLOB请求可以通过以下策略:1.减少BLOB查询频率,使用独立请求或延迟加载;2.选择合适的BLOB类型(如TINYBLOB);3.将BLOB数据分离到单独表中;4.在应用层压缩BLOB数据;5.对BLOB元数据建立索引。这些方法结合实际应用中的监控、缓存和数据分片,可以有效提升性能。

将用户添加到MySQL:完整的教程将用户添加到MySQL:完整的教程May 12, 2025 am 12:14 AM

掌握添加MySQL用户的方法对于数据库管理员和开发者至关重要,因为它确保数据库的安全性和访问控制。1)使用CREATEUSER命令创建新用户,2)通过GRANT命令分配权限,3)使用FLUSHPRIVILEGES确保权限生效,4)定期审计和清理用户账户以维护性能和安全。

掌握mySQL字符串数据类型:varchar vs.文本与char掌握mySQL字符串数据类型:varchar vs.文本与charMay 12, 2025 am 12:12 AM

chosecharforfixed-lengthdata,varcharforvariable-lengthdata,andtextforlargetextfield.1)chariseffity forconsistent-lengthdatalikecodes.2)varcharsuitsvariable-lengthdatalikenames,ballancingflexibilitibility andperformance.3)

MySQL:字符串数据类型和索引:最佳实践MySQL:字符串数据类型和索引:最佳实践May 12, 2025 am 12:11 AM

在MySQL中处理字符串数据类型和索引的最佳实践包括:1)选择合适的字符串类型,如CHAR用于固定长度,VARCHAR用于可变长度,TEXT用于大文本;2)谨慎索引,避免过度索引,针对常用查询创建索引;3)使用前缀索引和全文索引优化长字符串搜索;4)定期监控和优化索引,保持索引小巧高效。通过这些方法,可以在读取和写入性能之间取得平衡,提升数据库效率。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。