Created
December 25, 2019 07:57
-
-
Save lilinghai/02e2a3f867180a7484108512cab136cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table if exists city; | |
CREATE TABLE `city` ( | |
`id` varchar(70) NOT NULL, | |
`province_id` int(15) DEFAULT NULL, | |
`city_name` varchar(90) DEFAULT NULL, | |
`description` varchar(90) DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; | |
load stats "s/explain_union_scan.json"; | |
insert into city values("06766b3ef41d484d8878606393f1ed0b", 88, "chongqing", "chongqing city"); | |
begin; | |
update city set province_id = 77 where id="06766b3ef41d484d8878606393f1ed0b"; | |
explain select t1.*, t2.province_id as provinceID, t2.city_name as cityName, t3.description as description from city t1 inner join city t2 on t1.id = t2.id left join city t3 on t1.province_id = t3.province_id where t1.province_id > 1 and t1.province_id < 100 limit 10; | |
id count task operator info | |
Projection_17 10.00 root test.city.id, test.city.province_id, test.city.city_name, test.city.description, test.city.province_id, test.city.city_name, test.city.description | |
└─Limit_20 10.00 root offset:0, count:10 | |
└─HashLeftJoin_22 10.00 root left outer join, inner:Limit_25 (REVERSED), equal:[eq(test.city.province_id, test.city.province_id)] | |
├─Limit_25 10.00 root offset:0, count:10 | |
│ └─IndexJoin_38 10.00 root inner join, inner:UnionScan_37, outer key:test.city.id, inner key:test.city.id | |
│ ├─UnionScan_37 0.97 root gt(test.city.province_id, 1), lt(test.city.province_id, 100) | |
│ │ └─IndexLookUp_36 0.97 root | |
│ │ ├─IndexScan_33 1.00 cop[tikv] table:t1, index:id, range: decided by [eq(test.city.id, test.city.id)], keep order:false | |
│ │ └─Selection_35 0.97 cop[tikv] gt(test.city.province_id, 1), lt(test.city.province_id, 100) | |
│ │ └─TableScan_34 1.00 cop[tikv] table:t1, keep order:false | |
│ └─UnionScan_47 10.33 root | |
│ └─TableReader_49 10.33 root data:TableScan_48 | |
│ └─TableScan_48 10.33 cop[tikv] table:t2, range:[-inf,+inf], keep order:false | |
└─UnionScan_57 519304.44 root gt(test.city.province_id, 1), lt(test.city.province_id, 100), not(isnull(test.city.province_id)) | |
└─TableReader_60 519304.44 root data:Selection_59 | |
└─Selection_59 519304.44 cop[tikv] gt(test.city.province_id, 1), lt(test.city.province_id, 100), not(isnull(test.city.province_id)) | |
└─TableScan_58 536284.00 cop[tikv] table:t3, range:[-inf,+inf], keep order:false | |
commit; | |
有问题的版本 unionscan 扫描的行数远大于10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment