mysql not exits的sql查询慢优化
阅读数:60 评论数:0
跳转到新版页面分类
数据库
正文
SELECT DISTINCT PI.VALUE ID
FROM PERSON_VIEW PERV
inner join PERSON_IDENT PI on PI.VALUE = PERV.IDENTITY
inner join PERSON PER on PER.ID = PI.EXTERNAL_ID
WHERE NOT EXISTS (SELECT RECORD_ID FROM PERSON_MIGR_DATA PMD
WHERE RECORD_ID = PERV.RECORD_ID)
AND NOT EXISTS (SELECT RECORD_ID FROM PERSON_MIGR_ERRORS
WHERE RECORD_ID = PERV.RECORD_ID)
这种查询非常慢,这是因为mysql对待exits子句时,仍然采用嵌套子查询的执行方式,可以尝试使用左连接进行优化
SELECT DISTINCT PI.VALUE ID
FROM PERSON_VIEW PERV
inner join PERSON_IDENT PI on PI.VALUE = PERV.IDENTITY
inner join PERSON PER on PER.ID = PI.EXTERNAL_ID
LEFT JOIN PERSON_MIGR_DATA PMD ON PMD.RECORD_ID = PERV.RECORD_ID
LEFT JOIN PERSON_MIGR_ERRORS PME ON PME.RECORD_ID = PERV.RECORD_ID
where PMD.RECORD_ID is null and PME.RECORD_ID is null
相关推荐
Centos7的yum源中没有mysql,为了解决这个问题,我们需要先下载mysql的repo源。
一、下载mysql的repo源并安装
wget http://repo.mysql.com/mysq
如果主库已经投入使用了,此时如果需要主从同步,需要导出所表结构和数据,然后导入到从库中。这时需要注意修改/var/lib/mysql/auto.cnf中uuid。
master配
一、事务的ACID
1、Atomicity原子性
Transactions are often composed of multiple statements. Atomicity guarantee
一、登录mysql
mysql --version
-查看Mysql版本
mysql -h hostname -u username -p
-h:运行mysql服务器的机器,如果正在该机器上运行此命令
一、语法
select [optioins] items
[into file_details]
from tables
[where conditions]
[group by gr
一、语法
update [low_priority] [ignore] tablename
set column1=expression1,...
[where condition]
[order b
一、语法
1、基本语法
alter table [ignore] tablename alteration [,alteration...]
(1)ignore,如果会导致唯一键重复,则这些操作将自动