mysql和oracle 关于多表join的区别
http://stackoverflow.com/questions/10953143/join-performance-oracle-vs-mysql
翻译自上面的链接。
Given a query reduced to the form:
select b.field1
from table_a a
innerjoin table_b b on b.field1 = a.field1
leftjoin table_c c on c.field1 = a.field1
leftjoin table_d d on d.field1 = b.field1
leftjoin table_e e on e.field1 = b.field6
groupby b.field1,
b.field2,
b.field3,
b.field4,
b.field5,
e.field2,
e.field3
;
With a certain amount of data it is running in 20 seconds in Oracle. Nothing is indexed in Oracle. Migrated into MySQL the query does not want to finish (executes in minutes). Every field in question is indexed in MySQL. Explain tells that everything is fine.
After still not working, the grouping fields got multiple-column indexes. Still nothing.
What can be the problem that there is still a huge leak in the MySQL performance? Is there a method to speed it up?
他是说这这样的多表join ,oracle 什么索引都没建,20s出结果了,但是mysql ,索引都建了,几分钟还没出结果来。
我们这直接看5楼的回复。
Oracle is able to do hash joins and merge joins, MySQL is not.
oracle 做了hash join ,而mysql 没有。
Since your tables are not filtered in any way, hash joins would be the most efficient way to do the joins, especially if you don't have any indexes.
如果表没用过滤数据,就是说没用where 子句的,用hash join 是非常高效的连接方式。
With nested loops, even if all join fields are indexed, MySQL needs to do an index seek on each value from the leading table in a loop (each time starting from the root index page), then do the table lookup to retrieve the record, then repeat it for each joined table. This involves lots of random seeks.
nested loops ,其实就是嵌套循环算法的话,这里不大好翻译。我的理解是每个row都要和外层的做连接,相当于要一个笛卡尔积的连接量,多层的话,数据量会指数次增加。而且涉及了很多随机读。
A hash join, on the other side, requires scanning the smaller table once (building a hash table) then scanning the bigger table once (searching the hash table built). This involves sequential scans which are much faster.
而hash join 呢,需要扫描一张小的表,做一个hash table ,用他来和大表进行扫描,里面做的是顺序扫描,因此速度会快的多。
Also, with nested loops, a left-joined table can only be driven (scanned in the inner loop), while with a hash join tables on either side can be leading (scanned) or driven (hashed then searched). This affects performance too.
嵌套扫描的话,只有左连接可以被驱动。hash join的话,两边都能被驱动。
MySQL's optimizer, though does support a couple of handy tricks which other engines lack, has very limited capabilities compared to other engines and currently supports neither hash joins nor merge joins. Thus said, a query like this would most probably be slow on MySQL, even if it's fast on other engines on the same data.
mysql 优化器不支持此类优化,hash join 和merge joins ,所以和用什么引擎无关,都会很慢。
此文之前写过。但是没保存,以至于后面丢失了。我以为会进草稿箱,但是遗憾的是没有。吃一陷长一智,下次要养成保存的好习惯。
mysql和oracle 关于多表join的区别的更多相关文章
- MySQL与SQLServer的update left join语法区别
需求: 表A 字段 A_ID, A_NAME, B_ID 表B 字段 B_ID, B_NAME 需求把A的所有A_NAME更新为相应的B的 B_NAME. mysql做法: UPDATE A LEFT ...
- mysql 与 oracle 的连表update
mysql: update 表A a,表B b set a.xx=b.xx where a.id=b.id; oracle update 表A set a.xx=(select b.xx from 表 ...
- mysql、oracle分库分表方案之sharding-jdbc使用(非demo示例)
选择开源核心组件的一个非常重要的考虑通常是社区活跃性,一旦项目团队无法进行自己后续维护和扩展的情况下更是如此. 至于为什么选择sharding-jdbc而不是Mycat,可以参考知乎讨论帖子https ...
- mysql、oracle和SQL server数据库的区别
1.总体对比. SQL,在这里我理解成SQL Server.三者是目前市场占有率最高(依安装量而非收入)的关系数据库,而且很有代表性.排行第四的DB2(属IBM公司),与Oracle的定位和架构非常相 ...
- 【Mysql】MySQL与Oracle的大小写问题
转载来源:http://aofengblog.blog.163.com/blog/static/63170212010101065030136/ MySQL与Oracle在大小写处理上的区别: 1MY ...
- 开发中mysql和oracle的区别
首先就不描述mysql与oracle在整个数据库系统上的区别了,仅从程序员开发的角度来说: 1.主键: mysql一般会用到一个自增的属性,例如设置一个id字段,类型设置为auto increment ...
- MySql类似Oracle的dual虚拟表
在mysql里也存在和oracle里类似的dual虚拟表:官方声明纯粹是为了满足select ... from...这一习惯问题,mysql会忽略对该表的引用. 你可千万注意了: select * f ...
- SWAP_JOIN_INPUTS Oracle Hint(处理hash join强制大表(segment_size大)作为被驱动表)
SWAP_JOIN_INPUTS Oracle Hint(处理hash join强制大表(segment_size大)作为被驱动表) swap_join_inputs是针对哈希连接的hint,它的含义 ...
- Sqlserver 连接oracle和mysql数据库 已经oracle导入sqlserver表数据
SQL Server2012创建连接服务器到ORACLE11G 8,百思考不知道原因啊??突然我发现如下:链接服务器—〉访问接口—〉OraOLEDB.Oracle—〉允许进程内没有勾上,但是我想上面的 ...
随机推荐
- JasperReports入门教程(三):Paramters,Fields和Detail基本组件介绍
JasperReports入门教程(三):Paramter,Field和Detail基本组件介绍 前言 前两篇博客带领大家进行了入门,做出了第一个例子.也解决了中文打印的问题.大家跟着例子也做出了de ...
- Ubuntu创建WiFi:16.0.4
点击编辑链接,点击桌面状态栏的网络图标 点击增加 类型选择WiFi 名称.SSID,均要填写,模式选择:热点 wifi安全性:选择一个安全模式,这里选的是, wpa 及 wpa2个人 必须说的是:选择 ...
- 使用Reactor响应式编程
介绍 响应式编程 响应式编程不同于我们熟悉的命令式编程,我们熟悉的命令式编程即代码就是一行接一行的指令,按照它们的顺序一次一条地出现.一个任务被执行,程序就需要等到它执行完了,才能执行下一个任务.每一 ...
- 前端js传值JSON.stringify(obj)
用bootstrap-talbe前端传值 首先直接传肯定是不行的; 其次做一个全局变量也不行,因为这里的问题的是用bootstrap-table进行生成的操作HTML,从这里datass = row ...
- 2019-2020-1 20199303《Linux内核原理与分析》第六周作业
系统调用的三层机制 首先是为系统增加新的命令 运行脚本自动生成文件系统 其中有一个显示时间的功能 编辑test.c文件,增加一个hello函数用来显示学号,再次使用make roofts自动编译,调用 ...
- 演示:配置日志发送到syslog日志服务器
演示目标:配置网络环境中的交换机和路由器将日志发送到syslog日志服务器. 演示环境:如下图10.54所示的演示环境. 演示背景:要求部署网络中的syslog服务器,集中的收集交换机S1和路由器R1 ...
- 数学--数论--POJ1365——Prime Land
Description Everybody in the Prime Land is using a prime base number system. In this system, each po ...
- P6474 [NOI Online #2 入门组] 荆轲刺秦王
P6474 [NOI Online #2 入门组] 荆轲刺秦王 bfs+差分+卡常 本来我其实是场内选手,但是因为记错提交时间,晚了半小时才交,交不上了,就自动降级为了场外选手 题面复杂,不简述了 首 ...
- pytho xlrd简介
xlrd:是什么? xlrd是python的一个模块,主要用来对Excel进行读的操作,相对应的,xlwd就是对Excel进行写的模块了. xlrd中有哪些方法可以用呢? 1.打开Excel文件读取数 ...
- C# 基础知识系列- 17 实战篇 编写一个小工具(1)
0. 前言 这是对C# 基础系列的一个总结,现在我们利用之前学到的知识做一个小小的工具来给我们使用. 如果有看过IO篇的小伙伴,应该有印象.当时我提过一个场景描述,我们在平时使用系统的时候,经常会为了 ...