我在MariaDB 10.x中执行了一个复杂的查询,在MySQL 5.6中执行了相同的查询(参见下面的SQL)。在MariaDB中,MySQL的执行时间为25秒。
my.ini中的所有参数也相同。
你有什么线索可以解释为什么会有这样的差异?
select distinct
resourcety0_.VERSION_ as VERSION1_78_0_,
resourceus1_.ID as ID88_1_,
[... 20 more fields],
case
when resourceco2_12_.VERSION_ is not null then 12
when resourceco2_2_.VERSION_ is not null then 2
[... 20 more cases]
end as clazz_2_
from
BINARY_GUVNOR_RESOURCE_CONTE_0 resourceco2_2_ ON resourceco2_.VERSION_ = resourceco2_2_.VERSION_
left outer join
DATA_OBJECT_RESOURCE_CONTENT_0 resourceco2_3_ ON resourceco2_.VERSION_ = resourceco2_3_.VERSION_
left outer join
[... 20 more outer and inner joins]
where
(resourcety0_.RESOURCE_TYPE in ('ARGUMENT1' , 'ARGUMENT2',
'ARGUMENT3',
'ARGUMENT4',
'ARGUMENT5',
'ARGUMENT6'))
and resourcety0_.ID = resourceus1_.ID
and not (exists( select
resourcety10_.VERSION_
from
RESOURCE_TYPE resourcety10_
inner join
VERSION_INFO_TYPE resourcety10_1_ ON resourcety10_.VERSION_ = resourcety10_1_.VERSION_
where
resourcety0_.ID = resourcety10_.ID
and resourcety0_.VERSION_ = resourcety10_1_.PREVIOUS_VERSION))
and (resourceus1_.OWNER_ID = 'string1'
or (permission5_.HJVALUE in ('string2' , 'string1'))
and resourceus1_.OWNER_ID <> 'string1'
or (permission8_.HJVALUE in ('string2' , 'string1'))
and resourceus1_.OWNER_ID <> 'string1')
and resourcety0_1_.DELETED = 0
and (configurat9_.DTYPE in ('string3'))
order by resourcety0_1_.CREATED ASC
这是MariaDB EXPLAIN结果:
id;select_type;table;type;possible_keys;key;key_len;ref;rows;Extra
1;PRIMARY;configurat9_;ALL;PRIMARY; ; ; ;5;Using where; Using temporary; Using filesort
1;PRIMARY;resourceco2_4_;ref;PRIMARY,FK9F028B5C42E2A693,FK9F028B5CA7E5C40E;FK9F028B5CA7E5C40E;9;db_data.configurat9_.HJID;1;Using index
1;PRIMARY;resourceco2_;eq_ref;PRIMARY;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_5_;eq_ref;PRIMARY,FKAAE0AD5242E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_6_;eq_ref;PRIMARY,FK842528CF42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_7_;eq_ref;PRIMARY,FKF5BDD9B6DDDE48DC;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_8_;eq_ref;PRIMARY,FK415ED7006A929478;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_9_;eq_ref;PRIMARY,FK561F66796A929478;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_10_;eq_ref;PRIMARY,FKE6A69C9D42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_11_;eq_ref;PRIMARY,FK98392DBD65A46193;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_12_;eq_ref;PRIMARY,FK385C086331440E6;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_13_;eq_ref;PRIMARY,FKA7D0407442E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourcety0_;ref;PRIMARY,FKF5E4E4CB5B468256,FKF5E4E4CB894B8877,RESOURCE_ID,RESOURCE_TYPE;FKF5E4E4CB5B468256;39;db_data.resourceco2_4_.VERSION_;1;Using where
1;PRIMARY;resourceco2_14_;eq_ref;PRIMARY,FKF4B8FF842E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using where
1;PRIMARY;resourceco2_15_;eq_ref;PRIMARY,FKF5C0D3FA42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using where
1;PRIMARY;resourceco2_16_;eq_ref;PRIMARY,FKD4B1081342E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using where; Using index
1;PRIMARY;resourceco2_17_;eq_ref;PRIMARY,FKF7E6486F42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_18_;eq_ref;PRIMARY,FK627B607D42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_1_;eq_ref;PRIMARY,FKA8E578BBDDDE48DC;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_2_;eq_ref;PRIMARY,FKBFEDBDCB65A46193;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_19_;eq_ref;PRIMARY,FKE15CF71A42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using where
1;PRIMARY;resourceco2_20_;eq_ref;PRIMARY,FKBA3EF7D442E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using where
1;PRIMARY;resourceco2_21_;eq_ref;PRIMARY,FKEF28EDEE42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_3_;eq_ref;PRIMARY,FK545CBF84DDDE48DC;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using index
1;PRIMARY;resourcety0_1_;eq_ref;PRIMARY,VERSION_INFO_DELETED;PRIMARY;38;db_data.resourcety0_.VERSION_;1;Using where
1;PRIMARY;resourceus1_;eq_ref;PRIMARY,RESOURCE_USAGE_PERMISSION_OWNER_ID;PRIMARY;38;db_data.resourcety0_.ID;1;Using where
1;PRIMARY;permission3_;ref;FK4D42693835DD5F6E;FK4D42693835DD5F6E;38;db_data.resourcety0_.ID;1;Using where; Distinct
1;PRIMARY;resourceus4_;eq_ref;PRIMARY;PRIMARY;38;db_data.permission3_.CHILD_RESOURCE_USAGE_PERMISS_0;1;Using where; Using index; Distinct
1;PRIMARY;permission5_;ref;PRIMARY,FKFE973D132992B6A5;PRIMARY;38;db_data.resourceus4_.ID;1;Using where; Distinct
1;PRIMARY;inheritedp6_;ref;FK4D42693935DD5F6E;FK4D42693935DD5F6E;38;db_data.resourcety0_.ID;1;Using where; Distinct
1;PRIMARY;resourceus7_;eq_ref;PRIMARY;PRIMARY;38;db_data.inheritedp6_.CHILD_RESOURCE_USAGE_PERMISS_0;1;Using where; Using index; Distinct
1;PRIMARY;permission8_;ref;PRIMARY,FKFE973D132992B6A5;PRIMARY;38;db_data.resourceus7_.ID;1;Using where; Distinct
2;MATERIALIZED;resourcety10_1_;range;PRIMARY,VERSION_INFO_PREVIOUS_VERSION,VERSION_INFO_LAST_CHANGED,VERSION_INFO_DELETED,VERSION_INFO_CREATED;VERSION_INFO_PREVIOUS_VERSION;39; ;1;Using where; Using index
2;MATERIALIZED;resourcety10_;eq_ref;PRIMARY,FKF5E4E4CB3F390ABD,FKF5E4E4CB5B468256,FKF5E4E4CB894B8877,RESOURCE_LOCKED,RESOURCE_NAME,RESOURCE_ID,RESOURCE_TYPE;PRIMARY;38;db_data.resourcety10_1_.VERSION_;1;Using where
这里有MySQL EXPLAIN结果:
id;select_type;table;type;possible_keys;key;key_len;ref;rows;Extra
1;PRIMARY;resourceco2_4_;index;PRIMARY,FK9F028B5C42E2A693,FK9F028B5CA7E5C40E;FK9F028B5CA7E5C40E;9; ;6;Using where; Using index; Using temporary; Using filesort
1;PRIMARY;resourcety0_;ref;PRIMARY,FKF5E4E4CB5B468256,FKF5E4E4CB894B8877,RESOURCE_ID,RESOURCE_TYPE;FKF5E4E4CB5B468256;39;db_data.resourceco2_4_.VERSION_;1;Using where
1;PRIMARY;configurat9_;eq_ref;PRIMARY;PRIMARY;8;db_data.resourceco2_4_.CONFIGURATION_CONFIGURATION__0;1;Using where
1;PRIMARY;resourceco2_;eq_ref;PRIMARY;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_1_;eq_ref;PRIMARY,FKA8E578BBDDDE48DC;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_2_;eq_ref;PRIMARY,FKBFEDBDCB65A46193;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceus1_;eq_ref;PRIMARY,RESOURCE_USAGE_PERMISSION_OWNER_ID;PRIMARY;38;db_data.resourcety0_.ID;1;Using where
1;PRIMARY;resourceco2_3_;eq_ref;PRIMARY,FK545CBF84DDDE48DC;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using index
1;PRIMARY;permission3_;ref;FK4D42693835DD5F6E;FK4D42693835DD5F6E;38;db_data.resourcety0_.ID;1;
1;PRIMARY;resourcety0_1_;eq_ref;PRIMARY,VERSION_INFO_DELETED;PRIMARY;38;db_data.resourcety0_.VERSION_;1;Using where
1;PRIMARY;resourceus4_;eq_ref;PRIMARY;PRIMARY;38;db_data.permission3_.CHILD_RESOURCE_USAGE_PERMISS_0;1;Using index
1;PRIMARY;permission5_;ref;PRIMARY,FKFE973D132992B6A5;PRIMARY;38;db_data.resourceus4_.ID;1;Using where
1;PRIMARY;inheritedp6_;ref;FK4D42693935DD5F6E;FK4D42693935DD5F6E;38;db_data.resourcety0_.ID;1;
1;PRIMARY;resourceus7_;eq_ref;PRIMARY;PRIMARY;38;db_data.inheritedp6_.CHILD_RESOURCE_USAGE_PERMISS_0;1;Using index
1;PRIMARY;permission8_;ref;PRIMARY,FKFE973D132992B6A5;PRIMARY;38;db_data.resourceus7_.ID;1;Using where
1;PRIMARY;resourceco2_5_;ALL;PRIMARY,FKAAE0AD5242E2A693; ; ; ;1;Using where; Using join buffer (Block Nested Loop)
1;PRIMARY;resourceco2_6_;eq_ref;PRIMARY,FK842528CF42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_7_;eq_ref;PRIMARY,FKF5BDD9B6DDDE48DC;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_8_;eq_ref;PRIMARY,FK415ED7006A929478;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_9_;ALL;PRIMARY,FK561F66796A929478; ; ; ;1;Using where; Using join buffer (Block Nested Loop)
1;PRIMARY;resourceco2_10_;eq_ref;PRIMARY,FKE6A69C9D42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_11_;eq_ref;PRIMARY,FK98392DBD65A46193;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_12_;ALL;PRIMARY,FK385C086331440E6; ; ; ;1;Using where; Using join buffer (Block Nested Loop)
1;PRIMARY;resourceco2_13_;eq_ref;PRIMARY,FKA7D0407442E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_14_;eq_ref;PRIMARY,FKF4B8FF842E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_15_;eq_ref;PRIMARY,FKF5C0D3FA42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_16_;eq_ref;PRIMARY,FKD4B1081342E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;Using index
1;PRIMARY;resourceco2_17_;eq_ref;PRIMARY,FKF7E6486F42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_18_;ALL;PRIMARY,FK627B607D42E2A693; ; ; ;1;Using where; Using join buffer (Block Nested Loop)
1;PRIMARY;resourceco2_19_;eq_ref;PRIMARY,FKE15CF71A42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_20_;eq_ref;PRIMARY,FKBA3EF7D442E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
1;PRIMARY;resourceco2_21_;eq_ref;PRIMARY,FKEF28EDEE42E2A693;PRIMARY;38;db_data.resourceco2_4_.VERSION_;1;
2;DEPENDENT SUBQUERY;resourcety10_1_;ref;PRIMARY,VERSION_INFO_PREVIOUS_VERSION;VERSION_INFO_PREVIOUS_VERSION;39;db_data.resourcety0_.VERSION_;1;Using index
2;DEPENDENT SUBQUERY;resourcety10_;eq_ref;PRIMARY,FKF5E4E4CB894B8877,RESOURCE_ID;PRIMARY;38;db_data.resourcety10_1_.VERSION_;1;Using where