You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
233 lines
12 KiB
233 lines
12 KiB
DROP TABLE IF EXISTS person;
|
|
CREATE TABLE person (
|
|
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
address_info JSON,
|
|
city VARCHAR(64) AS (JSON_UNQUOTE(JSON_EXTRACT(address_info, '$.city'))) STORED,
|
|
KEY (city)
|
|
);
|
|
EXPLAIN SELECT name, id FROM person WHERE city = 'Beijing';
|
|
id estRows task access object operator info
|
|
Projection_4 10.00 root test.person.name, test.person.id
|
|
└─IndexLookUp_10 10.00 root
|
|
├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:person, index:city(city) range:["Beijing","Beijing"], keep order:false, stats:pseudo
|
|
└─TableRowIDScan_9(Probe) 10.00 cop[tikv] table:person keep order:false, stats:pseudo
|
|
DROP TABLE IF EXISTS `sgc`;
|
|
CREATE TABLE `sgc` (
|
|
`j1` JSON DEFAULT NULL,
|
|
`j2` JSON DEFAULT NULL,
|
|
`a` int(11) GENERATED ALWAYS AS (JSON_EXTRACT(`j1`, "$.a")) STORED,
|
|
`b` int(2) GENERATED ALWAYS AS (JSON_CONTAINS(j2, '1')) STORED,
|
|
KEY `idx_a` (`a`),
|
|
KEY `idx_b` (`b`),
|
|
KEY `idx_a_b` (`a`,`b`)
|
|
);
|
|
EXPLAIN SELECT a FROM sgc where a < 3;
|
|
id estRows task access object operator info
|
|
IndexReader_6 3323.33 root index:IndexRangeScan_5
|
|
└─IndexRangeScan_5 3323.33 cop[tikv] table:sgc, index:idx_a(a) range:[-inf,3), keep order:false, stats:pseudo
|
|
EXPLAIN SELECT a, b FROM sgc where a < 3;
|
|
id estRows task access object operator info
|
|
IndexReader_6 3323.33 root index:IndexRangeScan_5
|
|
└─IndexRangeScan_5 3323.33 cop[tikv] table:sgc, index:idx_a_b(a, b) range:[-inf,3), keep order:false, stats:pseudo
|
|
EXPLAIN SELECT a, b from sgc where b < 3;
|
|
id estRows task access object operator info
|
|
IndexReader_13 3323.33 root index:Selection_12
|
|
└─Selection_12 3323.33 cop[tikv] lt(test.sgc.b, 3)
|
|
└─IndexFullScan_11 10000.00 cop[tikv] table:sgc, index:idx_a_b(a, b) keep order:false, stats:pseudo
|
|
EXPLAIN SELECT a, b from sgc where a < 3 and b < 3;
|
|
id estRows task access object operator info
|
|
IndexReader_11 1104.45 root index:Selection_10
|
|
└─Selection_10 1104.45 cop[tikv] lt(test.sgc.b, 3)
|
|
└─IndexRangeScan_9 3323.33 cop[tikv] table:sgc, index:idx_a_b(a, b) range:[-inf,3), keep order:false, stats:pseudo
|
|
DROP TABLE IF EXISTS sgc1,
|
|
sgc2;
|
|
CREATE TABLE `sgc1` (
|
|
`j1` JSON,
|
|
`j2` JSON,
|
|
`a` INT AS (JSON_EXTRACT(j1, "$.a")) STORED,
|
|
`b` VARCHAR(20) AS (JSON_KEYS(j2)) STORED,
|
|
KEY `idx_a` (`a`),
|
|
KEY `idx_b` (`b`),
|
|
KEY `idx_a_b` (`a`, `b`)
|
|
);
|
|
CREATE TABLE `sgc2` (
|
|
`j1` JSON,
|
|
`j2` JSON,
|
|
`a` INT AS (JSON_EXTRACT(j1, "$.a")) STORED,
|
|
`b` VARCHAR(20) AS (JSON_KEYS(j2)) STORED,
|
|
KEY `idx_a` (`a`),
|
|
KEY `idx_b` (`b`),
|
|
KEY `idx_a_b` (`a`, `b`)
|
|
);
|
|
INSERT INTO sgc1(j1, j2)
|
|
VALUES ('{"a": 1}', '{"1": "1"}'),
|
|
('{"a": 1}', '{"1": "1"}'),
|
|
('{"a": 1}', '{"1": "1"}'),
|
|
('{"a": 1}', '{"1": "1"}'),
|
|
('{"a": 1}', '{"1": "1"}');
|
|
INSERT INTO sgc2(j1, j2)
|
|
VALUES ('{"a": 1}', '{"1": "1"}');
|
|
ANALYZE TABLE sgc1, sgc2;
|
|
EXPLAIN SELECT /*+ TIDB_INLJ(sgc1, sgc2) */ * from sgc1 join sgc2 on sgc1.a=sgc2.a;
|
|
id estRows task access object operator info
|
|
IndexJoin_19 5.00 root inner join, inner:IndexLookUp_18, outer key:test.sgc2.a, inner key:test.sgc1.a, equal cond:eq(test.sgc2.a, test.sgc1.a)
|
|
├─TableReader_33(Build) 1.00 root data:Selection_32
|
|
│ └─Selection_32 1.00 cop[tikv] not(isnull(test.sgc2.a))
|
|
│ └─TableFullScan_31 1.00 cop[tikv] table:sgc2 keep order:false
|
|
└─IndexLookUp_18(Probe) 5.00 root
|
|
├─Selection_17(Build) 5.00 cop[tikv] not(isnull(test.sgc1.a))
|
|
│ └─IndexRangeScan_15 5.00 cop[tikv] table:sgc1, index:idx_a(a) range: decided by [eq(test.sgc1.a, test.sgc2.a)], keep order:false
|
|
└─TableRowIDScan_16(Probe) 5.00 cop[tikv] table:sgc1 keep order:false
|
|
EXPLAIN SELECT * from sgc1 join sgc2 on sgc1.a=sgc2.a;
|
|
id estRows task access object operator info
|
|
Projection_6 5.00 root test.sgc1.j1, test.sgc1.j2, test.sgc1.a, test.sgc1.b, test.sgc2.j1, test.sgc2.j2, test.sgc2.a, test.sgc2.b
|
|
└─HashJoin_24 5.00 root inner join, equal:[eq(test.sgc2.a, test.sgc1.a)]
|
|
├─TableReader_43(Build) 1.00 root data:Selection_42
|
|
│ └─Selection_42 1.00 cop[tikv] not(isnull(test.sgc2.a))
|
|
│ └─TableFullScan_41 1.00 cop[tikv] table:sgc2 keep order:false
|
|
└─TableReader_52(Probe) 5.00 root data:Selection_51
|
|
└─Selection_51 5.00 cop[tikv] not(isnull(test.sgc1.a))
|
|
└─TableFullScan_50 5.00 cop[tikv] table:sgc1 keep order:false
|
|
DROP TABLE IF EXISTS sgc3;
|
|
CREATE TABLE sgc3 (
|
|
j JSON,
|
|
a INT AS (JSON_EXTRACT(j, "$.a")) STORED
|
|
)
|
|
PARTITION BY RANGE (a) (
|
|
PARTITION p0 VALUES LESS THAN (1),
|
|
PARTITION p1 VALUES LESS THAN (2),
|
|
PARTITION p2 VALUES LESS THAN (3),
|
|
PARTITION p3 VALUES LESS THAN (4),
|
|
PARTITION p4 VALUES LESS THAN (5),
|
|
PARTITION p5 VALUES LESS THAN (6),
|
|
PARTITION max VALUES LESS THAN MAXVALUE);
|
|
EXPLAIN SELECT * FROM sgc3 WHERE a <= 1;
|
|
id estRows task access object operator info
|
|
PartitionUnion_8 6646.67 root
|
|
├─TableReader_11 3323.33 root data:Selection_10
|
|
│ └─Selection_10 3323.33 cop[tikv] le(test.sgc3.a, 1)
|
|
│ └─TableFullScan_9 10000.00 cop[tikv] table:sgc3, partition:p0 keep order:false, stats:pseudo
|
|
└─TableReader_14 3323.33 root data:Selection_13
|
|
└─Selection_13 3323.33 cop[tikv] le(test.sgc3.a, 1)
|
|
└─TableFullScan_12 10000.00 cop[tikv] table:sgc3, partition:p1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT * FROM sgc3 WHERE a < 7;
|
|
id estRows task access object operator info
|
|
PartitionUnion_13 23263.33 root
|
|
├─TableReader_16 3323.33 root data:Selection_15
|
|
│ └─Selection_15 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
│ └─TableFullScan_14 10000.00 cop[tikv] table:sgc3, partition:p0 keep order:false, stats:pseudo
|
|
├─TableReader_19 3323.33 root data:Selection_18
|
|
│ └─Selection_18 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
│ └─TableFullScan_17 10000.00 cop[tikv] table:sgc3, partition:p1 keep order:false, stats:pseudo
|
|
├─TableReader_22 3323.33 root data:Selection_21
|
|
│ └─Selection_21 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
│ └─TableFullScan_20 10000.00 cop[tikv] table:sgc3, partition:p2 keep order:false, stats:pseudo
|
|
├─TableReader_25 3323.33 root data:Selection_24
|
|
│ └─Selection_24 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
│ └─TableFullScan_23 10000.00 cop[tikv] table:sgc3, partition:p3 keep order:false, stats:pseudo
|
|
├─TableReader_28 3323.33 root data:Selection_27
|
|
│ └─Selection_27 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
│ └─TableFullScan_26 10000.00 cop[tikv] table:sgc3, partition:p4 keep order:false, stats:pseudo
|
|
├─TableReader_31 3323.33 root data:Selection_30
|
|
│ └─Selection_30 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
│ └─TableFullScan_29 10000.00 cop[tikv] table:sgc3, partition:p5 keep order:false, stats:pseudo
|
|
└─TableReader_34 3323.33 root data:Selection_33
|
|
└─Selection_33 3323.33 cop[tikv] lt(test.sgc3.a, 7)
|
|
└─TableFullScan_32 10000.00 cop[tikv] table:sgc3, partition:max keep order:false, stats:pseudo
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1(a INT, b INT AS (a+1) VIRTUAL, c INT AS (b+1) VIRTUAL, d INT AS (c+1) VIRTUAL, KEY(b), INDEX IDX(c, d));
|
|
INSERT INTO t1 (a) VALUES (0);
|
|
EXPLAIN SELECT b FROM t1 WHERE b=1;
|
|
id estRows task access object operator info
|
|
IndexReader_6 10.00 root index:IndexRangeScan_5
|
|
└─IndexRangeScan_5 10.00 cop[tikv] table:t1, index:b(b) range:[1,1], keep order:false, stats:pseudo
|
|
EXPLAIN SELECT b, c, d FROM t1 WHERE b=1;
|
|
id estRows task access object operator info
|
|
Projection_4 10.00 root test.t1.b, test.t1.c, test.t1.d
|
|
└─IndexLookUp_10 10.00 root
|
|
├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:t1, index:b(b) range:[1,1], keep order:false, stats:pseudo
|
|
└─TableRowIDScan_9(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT * FROM t1 WHERE b=1;
|
|
id estRows task access object operator info
|
|
IndexLookUp_10 10.00 root
|
|
├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:t1, index:b(b) range:[1,1], keep order:false, stats:pseudo
|
|
└─TableRowIDScan_9(Probe) 10.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT c FROM t1 WHERE c=2 AND d=3;
|
|
id estRows task access object operator info
|
|
Projection_4 0.10 root test.t1.c
|
|
└─IndexReader_6 0.10 root index:IndexRangeScan_5
|
|
└─IndexRangeScan_5 0.10 cop[tikv] table:t1, index:IDX(c, d) range:[2 3,2 3], keep order:false, stats:pseudo
|
|
DROP TABLE IF EXISTS person;
|
|
CREATE TABLE person (
|
|
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
address_info JSON,
|
|
city_no INT AS (JSON_EXTRACT(address_info, '$.city_no')) VIRTUAL,
|
|
KEY(city_no));
|
|
INSERT INTO person (name, address_info) VALUES ("John", CAST('{"city_no": 1}' AS JSON));
|
|
EXPLAIN SELECT name FROM person where city_no=1;
|
|
id estRows task access object operator info
|
|
Projection_4 10.00 root test.person.name
|
|
└─IndexLookUp_10 10.00 root
|
|
├─IndexRangeScan_8(Build) 10.00 cop[tikv] table:person, index:city_no(city_no) range:[1,1], keep order:false, stats:pseudo
|
|
└─TableRowIDScan_9(Probe) 10.00 cop[tikv] table:person keep order:false, stats:pseudo
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (a INT,
|
|
b INT GENERATED ALWAYS AS (-a) VIRTUAL,
|
|
c INT GENERATED ALWAYS AS (-a) STORED,
|
|
index (c));
|
|
INSERT INTO t1 (a) VALUES (2), (1), (1), (3), (NULL);
|
|
EXPLAIN SELECT sum(a) FROM t1 GROUP BY b;
|
|
id estRows task access object operator info
|
|
HashAgg_5 8000.00 root group by:Column#7, funcs:sum(Column#6)->Column#5
|
|
└─Projection_12 10000.00 root cast(test.t1.a, decimal(65,0) BINARY)->Column#6, test.t1.b
|
|
└─TableReader_9 10000.00 root data:TableFullScan_8
|
|
└─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT sum(a) FROM t1 GROUP BY c;
|
|
id estRows task access object operator info
|
|
HashAgg_11 8000.00 root group by:test.t1.c, funcs:sum(Column#6)->Column#5
|
|
└─TableReader_12 8000.00 root data:HashAgg_5
|
|
└─HashAgg_5 8000.00 cop[tikv] group by:test.t1.c, funcs:sum(test.t1.a)->Column#6
|
|
└─TableFullScan_10 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT sum(b) FROM t1 GROUP BY a;
|
|
id estRows task access object operator info
|
|
HashAgg_5 8000.00 root group by:Column#7, funcs:sum(Column#6)->Column#5
|
|
└─Projection_12 10000.00 root cast(test.t1.b, decimal(65,0) BINARY)->Column#6, test.t1.a
|
|
└─TableReader_9 10000.00 root data:TableFullScan_8
|
|
└─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT sum(b) FROM t1 GROUP BY c;
|
|
id estRows task access object operator info
|
|
HashAgg_5 8000.00 root group by:Column#9, funcs:sum(Column#8)->Column#5
|
|
└─Projection_18 10000.00 root cast(test.t1.b, decimal(65,0) BINARY)->Column#8, test.t1.c
|
|
└─TableReader_11 10000.00 root data:TableFullScan_10
|
|
└─TableFullScan_10 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT sum(c) FROM t1 GROUP BY a;
|
|
id estRows task access object operator info
|
|
HashAgg_9 8000.00 root group by:test.t1.a, funcs:sum(Column#6)->Column#5
|
|
└─TableReader_10 8000.00 root data:HashAgg_5
|
|
└─HashAgg_5 8000.00 cop[tikv] group by:test.t1.a, funcs:sum(test.t1.c)->Column#6
|
|
└─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
EXPLAIN SELECT sum(c) FROM t1 GROUP BY b;
|
|
id estRows task access object operator info
|
|
HashAgg_5 8000.00 root group by:Column#7, funcs:sum(Column#6)->Column#5
|
|
└─Projection_12 10000.00 root cast(test.t1.c, decimal(65,0) BINARY)->Column#6, test.t1.b
|
|
└─TableReader_9 10000.00 root data:TableFullScan_8
|
|
└─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
DROP TABLE IF EXISTS tu;
|
|
CREATE TABLE tu (a INT, b INT, c INT GENERATED ALWAYS AS (a + b) VIRTUAL, primary key (a), unique key uk(c));
|
|
INSERT INTO tu(a, b) VALUES(1, 2);
|
|
EXPLAIN SELECT * FROM tu WHERE c = 1;
|
|
id estRows task access object operator info
|
|
Point_Get_5 1.00 root table:tu, index:uk(c)
|
|
EXPLAIN SELECT a, c FROM tu WHERE c = 1;
|
|
id estRows task access object operator info
|
|
Projection_4 1.00 root test.tu.a, test.tu.c
|
|
└─Point_Get_5 1.00 root table:tu, index:uk(c)
|
|
EXPLAIN SELECT * FROM tu WHERE c in(1, 2, 3);
|
|
id estRows task access object operator info
|
|
Batch_Point_Get_5 3.00 root table:tu, index:uk(c) keep order:false, desc:false
|
|
EXPLAIN SELECT c, a FROM tu WHERE c in(1, 2, 3);
|
|
id estRows task access object operator info
|
|
Projection_4 3.00 root test.tu.c, test.tu.a
|
|
└─Batch_Point_Get_5 3.00 root table:tu, index:uk(c) keep order:false, desc:false
|
|
|