Skip to content

Commit 28f8369

Browse files
committed
WL#7870: Create JOIN object after query preparation
1. Create JOIN object after query preparation. 2. Refactor query execution so that interfaces become simpler. See LLD for detailed description of changes.
1 parent c8cc1b3 commit 28f8369

File tree

103 files changed

+3199
-3402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+3199
-3402
lines changed

mysql-test/include/subquery.inc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,11 +3942,11 @@ INSERT INTO t1 VALUES (1,1,1), (1,1,1);
39423942
# so "c" is not dependent on the group column:
39433943
--error ER_WRONG_FIELD_WITH_GROUP
39443944
EXPLAIN EXTENDED
3945-
SELECT c FROM
3945+
SELECT cc FROM
39463946
( SELECT
39473947
(SELECT COUNT(a) FROM
39483948
(SELECT COUNT(b) FROM t1) AS x GROUP BY c
3949-
) FROM t1 GROUP BY b
3949+
) AS cc FROM t1 GROUP BY b
39503950
) AS y;
39513951
SHOW WARNINGS;
39523952

@@ -6360,3 +6360,21 @@ HAVING field1 != 'r'
63606360
ORDER BY CONCAT(alias2.col_varchar_nokey, alias2.col_varchar_nokey) DESC, field1;
63616361

63626362
DROP TABLE t1, t2;
6363+
6364+
--echo # Bug#19778967: Assert failed in JOIN::optimize
6365+
6366+
CREATE TABLE t1(a INTEGER);
6367+
CREATE VIEW v1 AS SELECT * FROM t1;
6368+
6369+
INSERT INTO t1 VALUES(0), (1);
6370+
6371+
let $query=SELECT * FROM t1 WHERE a <ANY (SELECT a FROM v1);
6372+
eval EXPLAIN $query;
6373+
eval PREPARE s FROM "$query";
6374+
6375+
EXECUTE s;
6376+
EXECUTE s;
6377+
6378+
DEALLOCATE PREPARE s;
6379+
DROP VIEW v1;
6380+
DROP TABLE t1;

mysql-test/r/explain_for_connection_rqg_json.result

Lines changed: 168 additions & 168 deletions
Large diffs are not rendered by default.

mysql-test/r/explain_for_connection_small_json.result

Lines changed: 61 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,11 @@ QUERY: UPDATE t1 left join t2 on t1.a=t2.a set t1.b=2, t2.b=2 where t1.b=1 and
287287
STATUS:NOT_EQUAL
288288
SYNC_POINT:before_reset_query_plan
289289
Diff: EXPLAIN NORMAL vs OTHER
290-
@@ -36,3 +36,3 @@
290+
@@ -36,2 +36,3 @@
291291
"filtered": 75,
292-
- "using_join_buffer": "Block Nested Loop",
293292
+ "using_where": true,
294293
"cost_info": {
295-
@@ -46,4 +46,3 @@
294+
@@ -45,4 +46,3 @@
296295
"b"
297296
- ],
298297
- "attached_condition": "(<if>(found_match(t2), (((`test`.`t2`.`b` = 1) and (`test`.`t1`.`b` = 1)) or isnull(`test`.`t2`.`a`)), true) and <if>(is_not_null_compl(t2), (`test`.`t2`.`a` = `test`.`t1`.`a`), true))"
@@ -302,12 +301,11 @@ QUERY: UPDATE t1 LEFT JOIN t2 USING(id) SET s1 = 'b'
302301
STATUS:NOT_EQUAL
303302
SYNC_POINT:before_reset_query_plan
304303
Diff: EXPLAIN NORMAL vs OTHER
305-
@@ -40,3 +40,3 @@
304+
@@ -40,2 +40,3 @@
306305
"filtered": 100,
307-
- "using_join_buffer": "Block Nested Loop",
308306
+ "using_where": true,
309307
"cost_info": {
310-
@@ -50,4 +50,3 @@
308+
@@ -49,4 +50,3 @@
311309
"s1"
312310
- ],
313311
- "attached_condition": "<if>(is_not_null_compl(t2), (`test`.`t1`.`id` = `test`.`t2`.`id`), true)"
@@ -509,7 +507,7 @@ QUERY: DELETE FROM t1 WHERE topic IN (SELECT DISTINCT topic FROM t2 WHERE NOT EX
509507
STATUS:NOT_EQUAL
510508
SYNC_POINT:planned_single_delete
511509
Diff: EXPLAIN NORMAL vs OTHER
512-
@@ -10,75 +10,20 @@
510+
@@ -10,72 +10,20 @@
513511
"filtered": 100,
514512
- "attached_condition": "<in_optimizer>(`test`.`t1`.`topic`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`topic`) in t2 on topic where ((not(exists(/* select#3 */ select 1 from dual where ('1' = `test`.`t2`.`topic`)))) and (<cache>(`test`.`t1`.`topic`) = `test`.`t2`.`topic`)))))",
515513
+ "using_where": true,
@@ -524,67 +522,63 @@ Diff: EXPLAIN NORMAL vs OTHER
524522
- "cost_info": {
525523
- "query_cost": "1.42"
526524
- },
527-
- "duplicates_removal": {
528-
- "using_filesort": false,
529-
- "table": {
530-
- "table_name": "t2",
531-
- "access_type": "index_subquery",
532-
- "possible_keys": [
533-
- "topic"
534-
- ],
535-
- "key": "topic",
536-
- "used_key_parts": [
537-
- "topic"
538-
- ],
539-
- "key_length": "3",
540-
- "ref": [
541-
- "func"
542-
- ],
543-
- "rows_examined_per_scan": 2,
544-
- "rows_produced_per_join": 2,
545-
- "filtered": 100,
546-
- "using_index": true,
547-
- "cost_info": {
548-
- "read_cost": "1.02",
549-
- "eval_cost": "0.40",
550-
- "prefix_cost": "1.42",
551-
- "data_read_per_join": "160"
552-
- },
553-
- "used_columns": [
554-
- "topic"
555-
- ],
556-
- "attached_condition": "((not(exists(/* select#3 */ select 1 from dual where ('1' = `test`.`t2`.`topic`)))) and (<cache>(`test`.`t1`.`topic`) = `test`.`t2`.`topic`))",
557-
- "attached_subqueries": [
558-
- {
559-
- "dependent": true,
560-
- "cacheable": false,
561-
- "query_block": {
562-
- "select_id": 3,
525+
- "table": {
526+
- "table_name": "t2",
527+
- "access_type": "index_subquery",
528+
- "possible_keys": [
529+
- "topic"
530+
- ],
531+
- "key": "topic",
532+
- "used_key_parts": [
533+
- "topic"
534+
- ],
535+
- "key_length": "3",
536+
- "ref": [
537+
- "func"
538+
- ],
539+
- "rows_examined_per_scan": 2,
540+
- "rows_produced_per_join": 2,
541+
- "filtered": 100,
542+
- "using_index": true,
543+
- "cost_info": {
544+
- "read_cost": "1.02",
545+
- "eval_cost": "0.40",
546+
- "prefix_cost": "1.42",
547+
- "data_read_per_join": "160"
548+
- },
549+
- "used_columns": [
550+
- "topic"
551+
- ],
552+
- "attached_condition": "((not(exists(/* select#3 */ select 1 from dual where ('1' = `test`.`t2`.`topic`)))) and (<cache>(`test`.`t1`.`topic`) = `test`.`t2`.`topic`))",
553+
- "attached_subqueries": [
554+
- {
555+
- "dependent": true,
556+
- "cacheable": false,
557+
- "query_block": {
558+
- "select_id": 3,
559+
- "cost_info": {
560+
- "query_cost": "1.00"
561+
- },
562+
- "table": {
563+
- "table_name": "t3",
564+
- "access_type": "system",
565+
- "possible_keys": [
566+
- "PRIMARY"
567+
- ],
568+
- "rows_examined_per_scan": 1,
569+
- "rows_produced_per_join": 1,
570+
- "filtered": 100,
563571
- "cost_info": {
564-
- "query_cost": "1.00"
572+
- "read_cost": "0.00",
573+
- "eval_cost": "0.20",
574+
- "prefix_cost": "0.00",
575+
- "data_read_per_join": "16"
565576
- },
566-
- "table": {
567-
- "table_name": "t3",
568-
- "access_type": "system",
569-
- "possible_keys": [
570-
- "PRIMARY"
571-
- ],
572-
- "rows_examined_per_scan": 1,
573-
- "rows_produced_per_join": 1,
574-
- "filtered": 100,
575-
- "cost_info": {
576-
- "read_cost": "0.00",
577-
- "eval_cost": "0.20",
578-
- "prefix_cost": "0.00",
579-
- "data_read_per_join": "16"
580-
- },
581-
- "used_columns": [
582-
- "numeropost"
583-
- ]
584-
- }
577+
- "used_columns": [
578+
- "numeropost"
579+
- ]
585580
- }
586581
- }
587-
- ]
588582
+ "message": "Plan isn't ready yet",
589583
+ "attached_subqueries": [
590584
+ {
@@ -593,9 +587,10 @@ Diff: EXPLAIN NORMAL vs OTHER
593587
+ "query_block": {
594588
+ "select_id": 3,
595589
+ "message": "Plan isn't ready yet"
596-
+ }
597-
}
590+
}
591+
- ]
598592
- }
593+
+ }
599594
+ ]
600595
}
601596
QUERY: SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns

mysql-test/r/explain_for_connection_small_trad.result

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,9 @@ STATUS: EQUAL
7979
QUERY: DELETE t1,t2 from t2 left outer join t1 using (n)
8080
STATUS: EQUAL
8181
QUERY: UPDATE t1 left join t2 on t1.a=t2.a set t1.b=2, t2.b=2 where t1.b=1 and t2.b=1 or t2.a is NULL
82-
STATUS:NOT_EQUAL
83-
SYNC_POINT:before_reset_query_plan
84-
Diff: EXPLAIN NORMAL vs OTHER
85-
@@ -2,2 +2,2 @@
86-
1 UPDATE t1 NULL ALL NULL NULL NULL NULL 3 100.00 NULL
87-
-1 UPDATE t2 NULL ALL NULL NULL NULL NULL 2 75.00 Using where; Using join buffer (Block Nested Loop)
88-
+1 UPDATE t2 NULL ALL NULL NULL NULL NULL 2 75.00 Using where
82+
STATUS: EQUAL
8983
QUERY: UPDATE t1 LEFT JOIN t2 USING(id) SET s1 = 'b'
90-
STATUS:NOT_EQUAL
91-
SYNC_POINT:before_reset_query_plan
92-
Diff: EXPLAIN NORMAL vs OTHER
93-
@@ -2,2 +2,2 @@
94-
1 SIMPLE t1 NULL index NULL PRIMARY 4 NULL 64 100.00 Using index
95-
-1 UPDATE t2 NULL ALL NULL NULL NULL NULL 64 100.00 Using where; Using join buffer (Block Nested Loop)
96-
+1 UPDATE t2 NULL ALL NULL NULL NULL NULL 64 100.00 Using where
84+
STATUS: EQUAL
9785
QUERY: SELECT * from t1 where a = 1 and b is null order by a desc, b desc
9886
STATUS: EQUAL
9987
QUERY: SELECT * from t1 where b=1 or b is null order by a

mysql-test/r/explain_json_all.result

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -396,26 +396,23 @@ EXPLAIN
396396
"cost_info": {
397397
"query_cost": "2.40"
398398
} /* cost_info */,
399-
"ordering_operation": {
400-
"using_filesort": false,
401-
"table": {
402-
"table_name": "t2",
403-
"access_type": "ALL",
404-
"rows_examined_per_scan": 2,
405-
"rows_produced_per_join": 1,
406-
"filtered": 50,
407-
"cost_info": {
408-
"read_cost": "2.00",
409-
"eval_cost": "0.20",
410-
"prefix_cost": "2.40",
411-
"data_read_per_join": "8"
412-
} /* cost_info */,
413-
"used_columns": [
414-
"i"
415-
] /* used_columns */,
416-
"attached_condition": "((`test`.`t1`.`i` = 10) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))"
417-
} /* table */
418-
} /* ordering_operation */
399+
"table": {
400+
"table_name": "t2",
401+
"access_type": "ALL",
402+
"rows_examined_per_scan": 2,
403+
"rows_produced_per_join": 1,
404+
"filtered": 50,
405+
"cost_info": {
406+
"read_cost": "2.00",
407+
"eval_cost": "0.20",
408+
"prefix_cost": "2.40",
409+
"data_read_per_join": "8"
410+
} /* cost_info */,
411+
"used_columns": [
412+
"i"
413+
] /* used_columns */,
414+
"attached_condition": "((`test`.`t1`.`i` = 10) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))"
415+
} /* table */
419416
} /* query_block */
420417
}
421418
] /* attached_subqueries */

mysql-test/r/explain_json_none.result

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -309,26 +309,23 @@ EXPLAIN
309309
"cost_info": {
310310
"query_cost": "2.40"
311311
} /* cost_info */,
312-
"ordering_operation": {
313-
"using_filesort": false,
314-
"table": {
315-
"table_name": "t2",
316-
"access_type": "ALL",
317-
"rows_examined_per_scan": 2,
318-
"rows_produced_per_join": 1,
319-
"filtered": 50,
320-
"cost_info": {
321-
"read_cost": "2.00",
322-
"eval_cost": "0.20",
323-
"prefix_cost": "2.40",
324-
"data_read_per_join": "8"
325-
} /* cost_info */,
326-
"used_columns": [
327-
"i"
328-
] /* used_columns */,
329-
"attached_condition": "((`test`.`t1`.`i` = 10) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))"
330-
} /* table */
331-
} /* ordering_operation */
312+
"table": {
313+
"table_name": "t2",
314+
"access_type": "ALL",
315+
"rows_examined_per_scan": 2,
316+
"rows_produced_per_join": 1,
317+
"filtered": 50,
318+
"cost_info": {
319+
"read_cost": "2.00",
320+
"eval_cost": "0.20",
321+
"prefix_cost": "2.40",
322+
"data_read_per_join": "8"
323+
} /* cost_info */,
324+
"used_columns": [
325+
"i"
326+
] /* used_columns */,
327+
"attached_condition": "((`test`.`t1`.`i` = 10) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))"
328+
} /* table */
332329
} /* query_block */
333330
}
334331
] /* attached_subqueries */
@@ -392,26 +389,23 @@ EXPLAIN
392389
"cost_info": {
393390
"query_cost": "2.40"
394391
} /* cost_info */,
395-
"ordering_operation": {
396-
"using_filesort": false,
397-
"table": {
398-
"table_name": "t2",
399-
"access_type": "ALL",
400-
"rows_examined_per_scan": 2,
401-
"rows_produced_per_join": 1,
402-
"filtered": 50,
403-
"cost_info": {
404-
"read_cost": "2.00",
405-
"eval_cost": "0.20",
406-
"prefix_cost": "2.40",
407-
"data_read_per_join": "8"
408-
} /* cost_info */,
409-
"used_columns": [
410-
"i"
411-
] /* used_columns */,
412-
"attached_condition": "((`test`.`t1`.`i` = 10) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))"
413-
} /* table */
414-
} /* ordering_operation */
392+
"table": {
393+
"table_name": "t2",
394+
"access_type": "ALL",
395+
"rows_examined_per_scan": 2,
396+
"rows_produced_per_join": 1,
397+
"filtered": 50,
398+
"cost_info": {
399+
"read_cost": "2.00",
400+
"eval_cost": "0.20",
401+
"prefix_cost": "2.40",
402+
"data_read_per_join": "8"
403+
} /* cost_info */,
404+
"used_columns": [
405+
"i"
406+
] /* used_columns */,
407+
"attached_condition": "((`test`.`t1`.`i` = 10) and (<cache>(`test`.`t1`.`i`) = `test`.`t2`.`i`))"
408+
} /* table */
415409
} /* query_block */
416410
}
417411
] /* attached_subqueries */

0 commit comments

Comments
 (0)