Skip to content

Commit 94af73c

Browse files
author
Sreeharsha Ramanavarapu
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 3567964 + 5debdf6 commit 94af73c

File tree

5 files changed

+53
-1208
lines changed

5 files changed

+53
-1208
lines changed

mysql-test/suite/opt_trace/include/bugs.inc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ CREATE TABLE t1 (
483483
PRIMARY KEY (a(32),b),
484484
KEY b_idx(b)
485485
) ENGINE=INNODB;
486-
INSERT INTO t1 VALUES ('a',1),('a',2),('a',3),('b',1),('b',4),('c',1),('d',1),
487-
('c',4),('d',3),('e',2),('f',2);
486+
INSERT INTO t1 VALUES ('a',1),('a',2),('a',3),('b',1),('c',1),('c',4),('e',2);
487+
ANALYZE TABLE t1;
488488

489489
SET @optimizer_switch_saved=@@session.optimizer_switch;
490490
SET @@session.optimizer_switch=default;
@@ -493,8 +493,8 @@ SELECT COUNT(*) FROM t1;
493493
# Uses "access_type_changed" to use range over ref despite b_idx not being the
494494
# cheapest in range.
495495
EXPLAIN SELECT * FROM t1 WHERE a IN ('a', 'b') AND b = 2;
496-
--replace_regex /"rows": 12/"rows": 11/ /"cost": 5.5/"cost": 5.3/
497-
SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
496+
SELECT TRACE into @trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
497+
SELECT @trace RLIKE "rerunning_range_optimizer_for_single_index";
498498

499499
SET @@session.optimizer_switch=@optimizer_switch_saved;
500500

@@ -515,6 +515,7 @@ while ($1)
515515
}
516516
enable_query_log;
517517

518+
ANALYZE TABLE t1;
518519
EXPLAIN SELECT c1, c2 FROM t1 ORDER BY c1 DESC LIMIT 1;
519520
--replace_regex /"cost": 3/"cost": 1/ /"cost": 4/"cost": 1/ /"cost": 203/"cost": 201/ /"cost": 204/"cost": 201/ /"cost_for_plan": 203/"cost_for_plan": 201/ /"cost_for_plan": 204/"cost_for_plan": 201/
520521
SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;

mysql-test/suite/opt_trace/r/bugs_no_prot_all.result

Lines changed: 12 additions & 301 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,323 +3493,34 @@ b TINYINT(3) UNSIGNED NOT NULL,
34933493
PRIMARY KEY (a(32),b),
34943494
KEY b_idx(b)
34953495
) ENGINE=INNODB;
3496-
INSERT INTO t1 VALUES ('a',1),('a',2),('a',3),('b',1),('b',4),('c',1),('d',1),
3497-
('c',4),('d',3),('e',2),('f',2);
3496+
INSERT INTO t1 VALUES ('a',1),('a',2),('a',3),('b',1),('c',1),('c',4),('e',2);
3497+
ANALYZE TABLE t1;
3498+
Table Op Msg_type Msg_text
3499+
test.t1 analyze status OK
34983500
SET @optimizer_switch_saved=@@session.optimizer_switch;
34993501
SET @@session.optimizer_switch=default;
35003502
SELECT COUNT(*) FROM t1;
35013503
COUNT(*)
3502-
11
3504+
7
35033505
EXPLAIN SELECT * FROM t1 WHERE a IN ('a', 'b') AND b = 2;
35043506
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
35053507
1 SIMPLE t1 NULL range PRIMARY,b_idx b_idx 35 NULL 2 100.00 Using index condition; Using where
35063508
Warnings:
35073509
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where ((`test`.`t1`.`b` = 2) and (`test`.`t1`.`a` in ('a','b')))
3508-
SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
3509-
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
3510-
EXPLAIN SELECT * FROM t1 WHERE a IN ('a', 'b') AND b = 2 {
3511-
"steps": [
3512-
{
3513-
"join_preparation": {
3514-
"select#": 1,
3515-
"steps": [
3516-
{
3517-
"IN_uses_bisection": true
3518-
},
3519-
{
3520-
"expanded_query": "/* select#1 */ select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` where ((`t1`.`a` in ('a','b')) and (`t1`.`b` = 2))"
3521-
}
3522-
] /* steps */
3523-
} /* join_preparation */
3524-
},
3525-
{
3526-
"join_optimization": {
3527-
"select#": 1,
3528-
"steps": [
3529-
{
3530-
"condition_processing": {
3531-
"condition": "WHERE",
3532-
"original_condition": "((`t1`.`a` in ('a','b')) and (`t1`.`b` = 2))",
3533-
"steps": [
3534-
{
3535-
"transformation": "equality_propagation",
3536-
"resulting_condition": "((`t1`.`a` in ('a','b')) and multiple equal(2, `t1`.`b`))"
3537-
},
3538-
{
3539-
"transformation": "constant_propagation",
3540-
"resulting_condition": "((`t1`.`a` in ('a','b')) and multiple equal(2, `t1`.`b`))"
3541-
},
3542-
{
3543-
"transformation": "trivial_condition_removal",
3544-
"resulting_condition": "((`t1`.`a` in ('a','b')) and multiple equal(2, `t1`.`b`))"
3545-
}
3546-
] /* steps */
3547-
} /* condition_processing */
3548-
},
3549-
{
3550-
"substitute_generated_columns": {
3551-
} /* substitute_generated_columns */
3552-
},
3553-
{
3554-
"table_dependencies": [
3555-
{
3556-
"table": "`t1`",
3557-
"row_may_be_null": false,
3558-
"map_bit": 0,
3559-
"depends_on_map_bits": [
3560-
] /* depends_on_map_bits */
3561-
}
3562-
] /* table_dependencies */
3563-
},
3564-
{
3565-
"ref_optimizer_key_uses": [
3566-
{
3567-
"table": "`t1`",
3568-
"field": "b",
3569-
"equals": "2",
3570-
"null_rejecting": false
3571-
}
3572-
] /* ref_optimizer_key_uses */
3573-
},
3574-
{
3575-
"rows_estimation": [
3576-
{
3577-
"table": "`t1`",
3578-
"range_analysis": {
3579-
"table_scan": {
3580-
"rows": 11,
3581-
"cost": 5.3
3582-
} /* table_scan */,
3583-
"potential_range_indexes": [
3584-
{
3585-
"index": "PRIMARY",
3586-
"usable": true,
3587-
"key_parts": [
3588-
"a",
3589-
"b"
3590-
] /* key_parts */
3591-
},
3592-
{
3593-
"index": "b_idx",
3594-
"usable": true,
3595-
"key_parts": [
3596-
"b",
3597-
"a"
3598-
] /* key_parts */
3599-
}
3600-
] /* potential_range_indexes */,
3601-
"setup_range_conditions": [
3602-
] /* setup_range_conditions */,
3603-
"group_index_range": {
3604-
"chosen": false,
3605-
"cause": "not_group_by_or_distinct"
3606-
} /* group_index_range */,
3607-
"analyzing_range_alternatives": {
3608-
"range_scan_alternatives": [
3609-
{
3610-
"index": "PRIMARY",
3611-
"ranges": [
3612-
"unprintable_blob_value <= a <= unprintable_blob_value AND 2 <= b <= 2",
3613-
"unprintable_blob_value <= a <= unprintable_blob_value AND 2 <= b <= 2"
3614-
] /* ranges */,
3615-
"index_dives_for_eq_ranges": true,
3616-
"rowid_ordered": true,
3617-
"using_mrr": false,
3618-
"index_only": false,
3619-
"rows": 2,
3620-
"cost": 2.41,
3621-
"chosen": true
3622-
},
3623-
{
3624-
"index": "b_idx",
3625-
"ranges": [
3626-
"2 <= b <= 2 AND unprintable_blob_value <= a <= unprintable_blob_value",
3627-
"2 <= b <= 2 AND unprintable_blob_value <= a <= unprintable_blob_value"
3628-
] /* ranges */,
3629-
"index_dives_for_eq_ranges": true,
3630-
"rowid_ordered": false,
3631-
"using_mrr": false,
3632-
"index_only": false,
3633-
"rows": 2,
3634-
"cost": 4.41,
3635-
"chosen": false,
3636-
"cause": "cost"
3637-
}
3638-
] /* range_scan_alternatives */,
3639-
"analyzing_roworder_intersect": {
3640-
"usable": false,
3641-
"cause": "too_few_roworder_scans"
3642-
} /* analyzing_roworder_intersect */
3643-
} /* analyzing_range_alternatives */,
3644-
"chosen_range_access_summary": {
3645-
"range_access_plan": {
3646-
"type": "range_scan",
3647-
"index": "PRIMARY",
3648-
"rows": 2,
3649-
"ranges": [
3650-
"unprintable_blob_value <= a <= unprintable_blob_value AND 2 <= b <= 2",
3651-
"unprintable_blob_value <= a <= unprintable_blob_value AND 2 <= b <= 2"
3652-
] /* ranges */
3653-
} /* range_access_plan */,
3654-
"rows_for_plan": 2,
3655-
"cost_for_plan": 2.41,
3656-
"chosen": true
3657-
} /* chosen_range_access_summary */
3658-
} /* range_analysis */
3659-
}
3660-
] /* rows_estimation */
3661-
},
3662-
{
3663-
"considered_execution_plans": [
3664-
{
3665-
"plan_prefix": [
3666-
] /* plan_prefix */,
3667-
"table": "`t1`",
3668-
"best_access_path": {
3669-
"considered_access_paths": [
3670-
{
3671-
"access_type": "ref",
3672-
"index": "b_idx",
3673-
"rows": 2,
3674-
"cost": 2.4,
3675-
"chosen": true
3676-
},
3677-
{
3678-
"rows_to_scan": 2,
3679-
"access_type": "range",
3680-
"range_details": {
3681-
"used_index": "PRIMARY"
3682-
} /* range_details */,
3683-
"resulting_rows": 2,
3684-
"cost": 2.81,
3685-
"chosen": false
3686-
}
3687-
] /* considered_access_paths */
3688-
} /* best_access_path */,
3689-
"condition_filtering_pct": 20,
3690-
"rows_for_plan": 0.4,
3691-
"cost_for_plan": 2.4,
3692-
"chosen": true
3693-
}
3694-
] /* considered_execution_plans */
3695-
},
3696-
{
3697-
"rerunning_range_optimizer_for_single_index": [
3698-
{
3699-
"table_scan": {
3700-
"rows": 11,
3701-
"cost": 5.3
3702-
} /* table_scan */,
3703-
"potential_range_indexes": [
3704-
{
3705-
"index": "PRIMARY",
3706-
"usable": false,
3707-
"cause": "not_applicable"
3708-
},
3709-
{
3710-
"index": "b_idx",
3711-
"usable": true,
3712-
"key_parts": [
3713-
"b",
3714-
"a"
3715-
] /* key_parts */
3716-
}
3717-
] /* potential_range_indexes */,
3718-
"setup_range_conditions": [
3719-
] /* setup_range_conditions */,
3720-
"group_index_range": {
3721-
"chosen": false,
3722-
"cause": "not_group_by_or_distinct"
3723-
} /* group_index_range */,
3724-
"analyzing_range_alternatives": {
3725-
"range_scan_alternatives": [
3726-
{
3727-
"index": "b_idx",
3728-
"ranges": [
3729-
"2 <= b <= 2 AND unprintable_blob_value <= a <= unprintable_blob_value",
3730-
"2 <= b <= 2 AND unprintable_blob_value <= a <= unprintable_blob_value"
3731-
] /* ranges */,
3732-
"index_dives_for_eq_ranges": true,
3733-
"rowid_ordered": false,
3734-
"using_mrr": false,
3735-
"index_only": false,
3736-
"rows": 2,
3737-
"cost": 4.41,
3738-
"chosen": true
3739-
}
3740-
] /* range_scan_alternatives */,
3741-
"analyzing_roworder_intersect": {
3742-
"usable": false,
3743-
"cause": "too_few_roworder_scans"
3744-
} /* analyzing_roworder_intersect */
3745-
} /* analyzing_range_alternatives */,
3746-
"chosen_range_access_summary": {
3747-
"range_access_plan": {
3748-
"type": "range_scan",
3749-
"index": "b_idx",
3750-
"rows": 2,
3751-
"ranges": [
3752-
"2 <= b <= 2 AND unprintable_blob_value <= a <= unprintable_blob_value",
3753-
"2 <= b <= 2 AND unprintable_blob_value <= a <= unprintable_blob_value"
3754-
] /* ranges */
3755-
} /* range_access_plan */,
3756-
"rows_for_plan": 2,
3757-
"cost_for_plan": 4.41,
3758-
"chosen": true
3759-
} /* chosen_range_access_summary */
3760-
} /* range_analysis */
3761-
] /* rerunning_range_optimizer_for_single_index */
3762-
},
3763-
{
3764-
"access_type_changed": {
3765-
"table": "`t1`",
3766-
"index": "b_idx",
3767-
"old_type": "ref",
3768-
"new_type": "range",
3769-
"cause": "uses_more_keyparts"
3770-
} /* access_type_changed */
3771-
},
3772-
{
3773-
"attaching_conditions_to_tables": {
3774-
"original_condition": "((`t1`.`b` = 2) and (`t1`.`a` in ('a','b')))",
3775-
"attached_conditions_computation": [
3776-
] /* attached_conditions_computation */,
3777-
"attached_conditions_summary": [
3778-
{
3779-
"table": "`t1`",
3780-
"attached": "((`t1`.`b` = 2) and (`t1`.`a` in ('a','b')))"
3781-
}
3782-
] /* attached_conditions_summary */
3783-
} /* attaching_conditions_to_tables */
3784-
},
3785-
{
3786-
"refine_plan": [
3787-
{
3788-
"table": "`t1`",
3789-
"pushed_index_condition": "(`t1`.`b` = 2)",
3790-
"table_condition_attached": "(`t1`.`a` in ('a','b'))"
3791-
}
3792-
] /* refine_plan */
3793-
}
3794-
] /* steps */
3795-
} /* join_optimization */
3796-
},
3797-
{
3798-
"join_explain": {
3799-
"select#": 1,
3800-
"steps": [
3801-
] /* steps */
3802-
} /* join_explain */
3803-
}
3804-
] /* steps */
3805-
} 0 0
3510+
SELECT TRACE into @trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
3511+
SELECT @trace RLIKE "rerunning_range_optimizer_for_single_index";
3512+
@trace RLIKE "rerunning_range_optimizer_for_single_index"
3513+
1
38063514
SET @@session.optimizer_switch=@optimizer_switch_saved;
38073515
DROP TABLE t1;
38083516
#
38093517
# Bug #23227428: SQL PLAN IS NOT ACCORDING WITH OPTIMIZER_TRACE
38103518
#
38113519
CREATE TABLE t1(c1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
38123520
c2 CHAR(12)) ENGINE=INNODB;
3521+
ANALYZE TABLE t1;
3522+
Table Op Msg_type Msg_text
3523+
test.t1 analyze status OK
38133524
EXPLAIN SELECT c1, c2 FROM t1 ORDER BY c1 DESC LIMIT 1;
38143525
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
38153526
1 SIMPLE t1 NULL index NULL PRIMARY 4 NULL 1 100.00 NULL

0 commit comments

Comments
 (0)