From d6db6df9956da295787b863dbe4d849c50956d02 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 18 Feb 2019 17:35:17 +0530 Subject: [PATCH 1/6] MDEV-17903: New optimizer defaults: change optimize_join_buffer_size to be ON optimize_join_buffer_size is switched ON. --- mysql-test/main/analyze_format_json.result | 10 +- mysql-test/main/analyze_stmt_orderby.result | 6 +- mysql-test/main/cte_recursive.result | 14 +- mysql-test/main/derived_cond_pushdown.result | 140 +++++++++--------- mysql-test/main/except.result | 12 +- mysql-test/main/explain_json.result | 16 +- mysql-test/main/in_subq_cond_pushdown.result | 4 +- mysql-test/main/intersect.result | 6 +- mysql-test/main/myisam_mrr,64bit.rdiff | 13 ++ mysql-test/main/myisam_mrr.test | 1 + mysql-test/main/mysqld--help.result | 2 +- .../sys_vars/r/optimizer_switch_basic.result | 16 +- .../sys_vars/r/sysvars_server_embedded.result | 6 +- .../r/sysvars_server_notembedded.result | 6 +- sql/sql_priv.h | 3 +- .../tokudb/r/ext_key_1_innodb.result | 2 +- .../tokudb/r/ext_key_1_tokudb.result | 2 +- .../tokudb/r/ext_key_2_innodb.result | 2 +- .../tokudb/r/ext_key_2_tokudb.result | 2 +- 19 files changed, 139 insertions(+), 124 deletions(-) create mode 100644 mysql-test/main/myisam_mrr,64bit.rdiff diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index b98500d4c34..c306c2fc1b3 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -143,7 +143,7 @@ ANALYZE "attached_condition": "tbl2.b < 60" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "1Kb", "join_type": "BNL", "r_filtered": 100 } @@ -181,7 +181,7 @@ ANALYZE "attached_condition": "tbl2.b < 60" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "1Kb", "join_type": "BNL", "attached_condition": "tbl1.c > tbl2.c", "r_filtered": 15.833 @@ -625,7 +625,7 @@ ANALYZE "attached_condition": "(t2.b,t2.b in (subquery#2))" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "(t2.b,t2.b in (subquery#2))", "r_filtered": null @@ -711,7 +711,7 @@ ANALYZE "attached_condition": "t3.f3 in (1,2)" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "1", "join_type": "BNL", "r_filtered": null }, @@ -742,7 +742,7 @@ ANALYZE "r_filtered": null }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "t2.f2 = t3.f3", "r_filtered": null diff --git a/mysql-test/main/analyze_stmt_orderby.result b/mysql-test/main/analyze_stmt_orderby.result index 3f6a4973d0a..23f4c39dd5b 100644 --- a/mysql-test/main/analyze_stmt_orderby.result +++ b/mysql-test/main/analyze_stmt_orderby.result @@ -426,7 +426,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "t3.a = t0.a", "r_filtered": 10 @@ -497,7 +497,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "attached_condition": "t5.a = t6.a", "r_filtered": 21.429 @@ -537,7 +537,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "attached_condition": "t5.a = t6.a" } diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result index f2ae9929145..0b22da8f72a 100644 --- a/mysql-test/main/cte_recursive.result +++ b/mysql-test/main/cte_recursive.result @@ -1409,7 +1409,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "686", "join_type": "BNL", "attached_condition": "prev_gen.father = folks.`id` or prev_gen.mother = folks.`id`" } @@ -1636,15 +1636,15 @@ i div 4 - (i % 4) = ps.i div 4 - (ps.i % 4) ) SELECT regexp_replace(board,concat('(',REPEAT('.', 4),')'),'\\1\n') n_queens FROM solutions WHERE n_queens = 4; n_queens --*-- ----* -*--- --*- +*--- +---* +-*-- ---*- -*--- ----* -*-- +---* +*--- +--*- # # MDEV-10883: execution of prepared statement from SELECT diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 52143f8e6c1..ea2ff69f792 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -136,7 +136,7 @@ EXPLAIN "attached_condition": "v1.max_c > 214" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "t2.a > v1.a", "materialized": { @@ -291,7 +291,7 @@ EXPLAIN "attached_condition": "v1.max_c > 400 or v1.max_c < 135" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.max_c > 400 and t2.a > v1.a or v1.max_c < 135 and t2.a < v1.a", "materialized": { @@ -359,7 +359,7 @@ EXPLAIN "attached_condition": "v1.max_c > 300 or v1.max_c < 135" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.b = t2.b and v1.max_c > 300 and v1.avg_c > t2.d or v1.a = t2.a and v1.max_c < 135 and v1.max_c < t2.c", "materialized": { @@ -416,7 +416,7 @@ EXPLAIN "attached_condition": "v1.a > 6" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "t2.b > v1.b", "materialized": { @@ -483,7 +483,7 @@ EXPLAIN "attached_condition": "v2.b > 25" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "t2.a < v2.a", "materialized": { @@ -571,7 +571,7 @@ EXPLAIN "attached_condition": "v1.a > 7 or v1.a < 2" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a > 7 and t2.c < v1.max_c or v1.a < 2 and t2.b < v1.b", "materialized": { @@ -652,7 +652,7 @@ EXPLAIN "attached_condition": "v2.a > 7 or v2.a > 5" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v2.a > 7 and t2.c < v2.max_c or v2.a > 5 and t2.b < v2.b", "materialized": { @@ -719,7 +719,7 @@ EXPLAIN "attached_condition": "v1.a > 4 or v1.a < 2" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a > 4 and v1.b > t2.b and v1.max_c = t2.d or v1.a < 2 and v1.max_c < t2.c and v1.max_c = t2.d", "materialized": { @@ -779,7 +779,7 @@ EXPLAIN "attached_condition": "v1.a < 2 and v1.max_c > 400" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "t2.b > v1.b", "materialized": { @@ -991,7 +991,7 @@ EXPLAIN "attached_condition": "v1.a > 7 and v1.max_c > 300 or v1.a < 4 and v1.max_c < 500" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a > 7 and v1.max_c > 300 and t2.c < v1.max_c or v1.a < 4 and v1.max_c < 500 and t2.b < v1.b", "materialized": { @@ -1080,7 +1080,7 @@ EXPLAIN "attached_condition": "v1.a < 2 and v1.max_c > 120 or v1.a > 7" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a < 2 and v1.max_c > 120 or v1.a > 7", "materialized": { @@ -1158,7 +1158,7 @@ EXPLAIN "attached_condition": "v1.a < 2 and v1.max_c > 120 or v1.a > 7" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.b = t2.b and v1.a < 2 and v1.max_c > 120 or v1.a > 7", "materialized": { @@ -1225,7 +1225,7 @@ EXPLAIN "attached_condition": "v1.a < 2 and v1.max_c < 200 or v1.a > 4" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a < 2 and v1.max_c < 200 and t2.c > v1.max_c and v1.max_c = t2.d or v1.max_c = t2.c and v1.a > 4 and t2.c < 500 and t2.b < v1.b", "materialized": { @@ -1302,7 +1302,7 @@ EXPLAIN "attached_condition": "v1.max_c > 400 or v1.max_c < 135" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.max_c > 400 and t2.a > v1.a or v1.max_c < 135 and t2.a < v1.a", "materialized": { @@ -1345,7 +1345,7 @@ EXPLAIN "attached_condition": "v1.max_c > 400 or v1.max_c < 135" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.max_c > 400 and t2.a > v1.a or v1.max_c < 135 and t2.a < v1.a", "materialized": { @@ -1684,7 +1684,7 @@ EXPLAIN "attached_condition": "v1.a = 3 and v1.b = 3" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -1734,7 +1734,7 @@ EXPLAIN "attached_condition": "v1.a = 1 and v1.b = 21" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -1807,7 +1807,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "220", "join_type": "BNL", "attached_condition": "t.b = v.b or v.max_c > 20" } @@ -1931,7 +1931,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a = t2.a and t2.a < 4 or v1.max_c = t2.c and t2.c > 150", "materialized": { @@ -2061,7 +2061,7 @@ EXPLAIN "attached_condition": "v1.a = 8 and v1.max_c = 404" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -2359,7 +2359,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "162", "join_type": "BNL" } } @@ -2471,7 +2471,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -2598,7 +2598,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a = t2.a or v1.b = t2.b and (v1.a = 1 or v1.a = 6)", "materialized": { @@ -2693,7 +2693,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a = 1 or v1.b = 21 or t2.a = 2", "materialized": { @@ -2761,7 +2761,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a < t2.a or t2.a < 11", "materialized": { @@ -2943,7 +2943,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.b is not null", "materialized": { @@ -3038,7 +3038,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a = t2.a or t2.c < 115", "materialized": { @@ -3067,7 +3067,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "incremental", - "buffer_size": "256Kb", + "buffer_size": "4Kb", "join_type": "BNL", "attached_condition": "v1.a = t2.a and v2.a = t2.a or v2.b > 13 and t2.c < 115", "materialized": { @@ -3138,7 +3138,7 @@ EXPLAIN "attached_condition": "v1.max_c < 300" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -3167,7 +3167,7 @@ EXPLAIN "attached_condition": "v2.b < 50 or v2.b = 19" }, "buffer_type": "incremental", - "buffer_size": "256Kb", + "buffer_size": "4Kb", "join_type": "BNL", "attached_condition": "(v2.a = v1.a or v1.a = t2.a) and (v2.b < 50 or v2.b = 19)", "materialized": { @@ -3317,7 +3317,7 @@ EXPLAIN "attached_condition": "v1.a = 1 and v1.b > 10" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.b is not null", "materialized": { @@ -3435,7 +3435,7 @@ EXPLAIN "attached_condition": "t.a = 'b'" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "220", "join_type": "BNL" } } @@ -3544,7 +3544,7 @@ EXPLAIN "attached_condition": "v2.max_c > 300" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "715", "join_type": "BNL", "materialized": { "query_block": { @@ -3574,7 +3574,7 @@ EXPLAIN "attached_condition": "v1.max_c < 500" }, "buffer_type": "incremental", - "buffer_size": "256Kb", + "buffer_size": "9Kb", "join_type": "BNL", "attached_condition": "v1.a = v2.a or v1.a = t2.a", "materialized": { @@ -3790,7 +3790,7 @@ EXPLAIN "attached_condition": "v1.avg_c < 400 or v1.a > 1" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "(v1.avg_c < 400 or v1.a > 1) and v1.a is not null and v1.b is not null", "materialized": { @@ -3935,7 +3935,7 @@ EXPLAIN "attached_condition": "(v1.a = 1 or v1.max_c < 300) and v1.b > 25" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a = 1 or v1.max_c < 300", "materialized": { @@ -4128,7 +4128,7 @@ EXPLAIN "attached_condition": "v1.max_c > 100 and v1.a > 7" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -4229,7 +4229,7 @@ EXPLAIN "attached_condition": "v1.b = 19 and v1.a < 5" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -4271,7 +4271,7 @@ EXPLAIN "attached_condition": "v1.max_c > 400 or v1.avg_c > 270" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "(v1.max_c > 400 or v1.avg_c > 270) and v1.a < t2.a", "materialized": { @@ -4383,7 +4383,7 @@ EXPLAIN "attached_condition": "v1.a = 1 or v1.a = 6" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "(v1.a = t2.a or v1.b = t2.b) and (v1.a = 1 or v1.a = 6)", "materialized": { @@ -4426,7 +4426,7 @@ EXPLAIN "attached_condition": "v1.a > 3 and v1.b > 27 or v1.max_c > 550" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.a > 3 and v1.b > 27 or v1.max_c > 550", "materialized": { @@ -4540,7 +4540,7 @@ EXPLAIN "attached_condition": "v1.a = 1 and (v1.max_c < 500 or v1.avg_c > 500)" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v1.max_c < 500 or v1.avg_c > 500", "materialized": { @@ -4584,7 +4584,7 @@ EXPLAIN "attached_condition": "v2.b > 10" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v2.a < t2.b or v2.max_c > 200", "materialized": { @@ -4706,7 +4706,7 @@ EXPLAIN "attached_condition": "v_union.a < 3 and v_union.c > 100" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -4814,7 +4814,7 @@ EXPLAIN "attached_condition": "(v_union.a < 2 or v_union.c > 800) and v_union.b > 12" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "v_union.a < 2 or v_union.c > 800", "materialized": { @@ -4911,7 +4911,7 @@ EXPLAIN "attached_condition": "v_union.a = 1 and v_union.c < 200" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -5078,7 +5078,7 @@ EXPLAIN "attached_condition": "v1.a = 1" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "materialized": { "query_block": { @@ -5108,7 +5108,7 @@ EXPLAIN "attached_condition": "v_union.a = 1" }, "buffer_type": "incremental", - "buffer_size": "256Kb", + "buffer_size": "4Kb", "join_type": "BNL", "attached_condition": "v_union.c > 800 or v1.max_c > 200", "materialized": { @@ -5923,7 +5923,7 @@ EXPLAIN "attached_condition": "v1.a > 5 and v1.b > 12" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "333", "join_type": "BNL", "materialized": { "query_block": { @@ -6306,7 +6306,7 @@ EXPLAIN "attached_condition": "v4.b > 10 and v4.a > 1 or v4.b < 20" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "238", "join_type": "BNL", "attached_condition": "(v4.b > 10 and v4.a > 1 or v4.b < 20) and v4.a is not null", "materialized": { @@ -6451,7 +6451,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "333", "join_type": "BNL", "materialized": { "query_block": { @@ -6971,7 +6971,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "715", "join_type": "BNL", "materialized": { "query_block": { @@ -7766,7 +7766,7 @@ EXPLAIN "attached_condition": "v2.pk > 2" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "materialized": { "query_block": { @@ -8763,7 +8763,7 @@ EXPLAIN "attached_condition": "v2.i2 = 1" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "materialized": { "query_block": { @@ -8879,7 +8879,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "163", "join_type": "BNL", "attached_condition": "t1.id2 = vc.id2" } @@ -8952,7 +8952,7 @@ EXPLAIN "attached_condition": "v1.a = 1 and v1.b = 1 and v1.max_c > 30" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "materialized": { "query_block": { @@ -9027,7 +9027,7 @@ EXPLAIN "attached_condition": "v1.a = 1 and v1.b = 1 and v1.d = 1 and v1.max_c > 30" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "materialized": { "query_block": { @@ -9758,7 +9758,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "t1.a = dt1.a" } @@ -9817,7 +9817,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "attached_condition": "t1.a = dt.a" } @@ -10313,7 +10313,7 @@ EXPLAIN "attached_condition": "t1.f is not null" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "64", "join_type": "BNL" } } @@ -10488,7 +10488,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "t1.f2 = t.f2" } @@ -10647,7 +10647,7 @@ EXPLAIN "attached_condition": "v1.a = 8" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "materialized": { "query_block": { @@ -10735,7 +10735,7 @@ EXPLAIN "attached_condition": "v1.a = 8" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "materialized": { "query_block": { @@ -11225,7 +11225,7 @@ EXPLAIN "attached_condition": "v1.a > 3 or v1.a = 1 and v1.c < 110" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "attached_condition": "v1.c = t2.c and v1.a > 3 and t2.c > 110 or v1.a = 1 and v1.c < 110", "materialized": { @@ -11566,7 +11566,7 @@ EXPLAIN "attached_condition": "v1.a = 6" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "materialized": { "query_block": { @@ -11656,7 +11656,7 @@ EXPLAIN "attached_condition": "v1.a = 6" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "materialized": { "query_block": { @@ -12150,7 +12150,7 @@ EXPLAIN "attached_condition": "v1.a > 1 or v1.a = 1 and v1.c > 500" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "attached_condition": "v1.c = t2.c and v1.a > 1 and t2.c < 500 or v1.a = 1 and v1.c > 500", "materialized": { @@ -14010,7 +14010,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "attached_condition": "t2.b = v1.b" } @@ -14106,7 +14106,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "173", "join_type": "BNL", "attached_condition": "t2.b = v1.b" } @@ -16413,7 +16413,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "t2.i = t1.i and t2.i = t1.i" } diff --git a/mysql-test/main/except.result b/mysql-test/main/except.result index b9959a3f520..9c5a3eaa93c 100644 --- a/mysql-test/main/except.result +++ b/mysql-test/main/except.result @@ -255,7 +255,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL" } } @@ -278,7 +278,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL" } } @@ -324,7 +324,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "r_filtered": 100 } @@ -358,7 +358,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "r_filtered": 100 } @@ -420,7 +420,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "r_filtered": 100 } @@ -454,7 +454,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "r_filtered": 100 } diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result index 2f60a827cc0..b918e7614af 100644 --- a/mysql-test/main/explain_json.result +++ b/mysql-test/main/explain_json.result @@ -373,7 +373,7 @@ EXPLAIN "attached_condition": "tbl2.b < 5" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "1Kb", "join_type": "BNL", "attached_condition": "tbl2.a = tbl1.a" } @@ -640,7 +640,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "1Kb", "join_type": "BNL" } } @@ -674,7 +674,7 @@ EXPLAIN "first_match": "t2" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "141", "join_type": "BNL", "attached_condition": "t1.b = t2.b and t1.a = t2.a" } @@ -711,7 +711,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "206", "join_type": "BNL", "attached_condition": "t1.b = t2.b and t1.a = t2.a" } @@ -825,7 +825,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "attached_condition": "t2.b <> outer_t1.a" } @@ -876,7 +876,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "1Kb", "join_type": "BNL", "attached_condition": "tbl2.b = tbl1.b" } @@ -1492,7 +1492,7 @@ EXPLAIN "index_condition_bka": "t4.b + 1 <= t3.b + 1" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "400", "join_type": "BKA", "mrr_type": "Rowid-ordered scan" } @@ -1535,7 +1535,7 @@ ANALYZE "index_condition_bka": "t4.b + 1 <= t3.b + 1" }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "400", "join_type": "BKA", "mrr_type": "Rowid-ordered scan", "r_filtered": 100 diff --git a/mysql-test/main/in_subq_cond_pushdown.result b/mysql-test/main/in_subq_cond_pushdown.result index 06248895bd3..522d97f5273 100644 --- a/mysql-test/main/in_subq_cond_pushdown.result +++ b/mysql-test/main/in_subq_cond_pushdown.result @@ -605,7 +605,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "attached_condition": "t1.c = t3.y and t1.a is not null" }, @@ -1505,7 +1505,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "119", "join_type": "BNL", "attached_condition": "t1.a = t3.x and t1.c is not null" }, diff --git a/mysql-test/main/intersect.result b/mysql-test/main/intersect.result index 5c7e9dfc6f6..f2d36e1d0e9 100644 --- a/mysql-test/main/intersect.result +++ b/mysql-test/main/intersect.result @@ -316,7 +316,7 @@ EXPLAIN "filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL" } } @@ -380,7 +380,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "r_filtered": 100 } @@ -459,7 +459,7 @@ ANALYZE "r_filtered": 100 }, "buffer_type": "flat", - "buffer_size": "256Kb", + "buffer_size": "65", "join_type": "BNL", "r_filtered": 100 } diff --git a/mysql-test/main/myisam_mrr,64bit.rdiff b/mysql-test/main/myisam_mrr,64bit.rdiff new file mode 100644 index 00000000000..82f6dfabb65 --- /dev/null +++ b/mysql-test/main/myisam_mrr,64bit.rdiff @@ -0,0 +1,13 @@ +--- main/myisam_mrr.result 2019-02-04 13:47:00.000000000 +0530 ++++ main/myisam_mrr,64bit.reject 2019-02-04 13:50:01.000000000 +0530 +@@ -617,8 +617,8 @@ + show status like 'handler_mrr%'; + Variable_name Value + Handler_mrr_init 1 +-Handler_mrr_key_refills 0 +-Handler_mrr_rowid_refills 0 ++Handler_mrr_key_refills 1 ++Handler_mrr_rowid_refills 1 + set join_buffer_size=10; + explain select sum(t1.b) from t0,t1 where t0.a=t1.a; + id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/main/myisam_mrr.test b/mysql-test/main/myisam_mrr.test index b15fdf60ce7..60d96c602ef 100644 --- a/mysql-test/main/myisam_mrr.test +++ b/mysql-test/main/myisam_mrr.test @@ -12,6 +12,7 @@ set @mrr_buffer_size_save= @@mrr_buffer_size; set mrr_buffer_size=79; -- source include/mrr_tests.inc +-- source include/word_size.inc set @@mrr_buffer_size= @mrr_buffer_size_save; diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index 5a6bb51b501..a547a978a01 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -1571,7 +1571,7 @@ old-style-user-limits FALSE optimizer-prune-level 1 optimizer-search-depth 62 optimizer-selectivity-sampling-limit 100 -optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on optimizer-trace optimizer-trace-max-mem-size 1048576 optimizer-use-condition-selectivity 4 diff --git a/mysql-test/suite/sys_vars/r/optimizer_switch_basic.result b/mysql-test/suite/sys_vars/r/optimizer_switch_basic.result index aa52edcc8fb..72438605d05 100644 --- a/mysql-test/suite/sys_vars/r/optimizer_switch_basic.result +++ b/mysql-test/suite/sys_vars/r/optimizer_switch_basic.result @@ -1,25 +1,25 @@ SET @start_global_value = @@global.optimizer_switch; SELECT @start_global_value; @start_global_value -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on select @@global.optimizer_switch; @@global.optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on select @@session.optimizer_switch; @@session.optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on show global variables like 'optimizer_switch'; Variable_name Value -optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on show session variables like 'optimizer_switch'; Variable_name Value -optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +optimizer_switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on select * from information_schema.global_variables where variable_name='optimizer_switch'; VARIABLE_NAME VARIABLE_VALUE -OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on select * from information_schema.session_variables where variable_name='optimizer_switch'; VARIABLE_NAME VARIABLE_VALUE -OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +OPTIMIZER_SWITCH index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on set global optimizer_switch=10; set session optimizer_switch=5; select @@global.optimizer_switch; @@ -69,4 +69,4 @@ ERROR 42000: Variable 'optimizer_switch' can't be set to the value of 'foobar' SET @@global.optimizer_switch = @start_global_value; SELECT @@global.optimizer_switch; @@global.optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index be5d9a9e670..483d38674ef 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -2743,10 +2743,10 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OPTIMIZER_SWITCH -SESSION_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on -GLOBAL_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +SESSION_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +GLOBAL_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +DEFAULT_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on VARIABLE_SCOPE SESSION VARIABLE_TYPE FLAGSET VARIABLE_COMMENT Fine-tune the optimizer behavior diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 6cd6c674cbf..cd119f98438 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -2967,10 +2967,10 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME OPTIMIZER_SWITCH -SESSION_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on -GLOBAL_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +SESSION_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +GLOBAL_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +DEFAULT_VALUE index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on VARIABLE_SCOPE SESSION VARIABLE_TYPE FLAGSET VARIABLE_COMMENT Fine-tune the optimizer behavior diff --git a/sql/sql_priv.h b/sql/sql_priv.h index dab7a3161be..13ecbe9b1f1 100644 --- a/sql/sql_priv.h +++ b/sql/sql_priv.h @@ -263,7 +263,8 @@ OPTIMIZER_SWITCH_COND_PUSHDOWN_FOR_DERIVED | \ OPTIMIZER_SWITCH_SPLIT_MATERIALIZED | \ OPTIMIZER_SWITCH_COND_PUSHDOWN_FOR_SUBQUERY |\ - OPTIMIZER_SWITCH_USE_ROWID_FILTER) + OPTIMIZER_SWITCH_USE_ROWID_FILTER |\ + OPTIMIZER_SWITCH_OPTIMIZE_JOIN_BUFFER_SIZE) /* Replication uses 8 bytes to store SQL_MODE in the binary log. The day you diff --git a/storage/tokudb/mysql-test/tokudb/r/ext_key_1_innodb.result b/storage/tokudb/mysql-test/tokudb/r/ext_key_1_innodb.result index 55a2cc4b34b..17270ac5115 100644 --- a/storage/tokudb/mysql-test/tokudb/r/ext_key_1_innodb.result +++ b/storage/tokudb/mysql-test/tokudb/r/ext_key_1_innodb.result @@ -1,7 +1,7 @@ drop table if exists t; select @@optimizer_switch; @@optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on create table t (id int not null, x int not null, y int not null, primary key(id), key(x)) engine=innodb; insert into t values (0,0,0),(1,1,1),(2,2,2),(3,2,3),(4,2,4); explain select x,id from t force index (x) where x=0 and id=0; diff --git a/storage/tokudb/mysql-test/tokudb/r/ext_key_1_tokudb.result b/storage/tokudb/mysql-test/tokudb/r/ext_key_1_tokudb.result index 1b5998b1534..0ea5a45af20 100644 --- a/storage/tokudb/mysql-test/tokudb/r/ext_key_1_tokudb.result +++ b/storage/tokudb/mysql-test/tokudb/r/ext_key_1_tokudb.result @@ -1,7 +1,7 @@ drop table if exists t; select @@optimizer_switch; @@optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on create table t (id int not null, x int not null, y int not null, primary key(id), key(x)) engine=tokudb; insert into t values (0,0,0),(1,1,1),(2,2,2),(3,2,3),(4,2,4); explain select x,id from t force index (x) where x=0 and id=0; diff --git a/storage/tokudb/mysql-test/tokudb/r/ext_key_2_innodb.result b/storage/tokudb/mysql-test/tokudb/r/ext_key_2_innodb.result index 0bba5b7c47f..58bc4bcb31a 100644 --- a/storage/tokudb/mysql-test/tokudb/r/ext_key_2_innodb.result +++ b/storage/tokudb/mysql-test/tokudb/r/ext_key_2_innodb.result @@ -1,7 +1,7 @@ drop table if exists t; select @@optimizer_switch; @@optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on create table t (a int not null, b int not null, c int not null, d int not null, primary key(a,b), key(c,a)) engine=innodb; insert into t values (0,0,0,0),(0,1,0,1); explain select c,a,b from t where c=0 and a=0 and b=1; diff --git a/storage/tokudb/mysql-test/tokudb/r/ext_key_2_tokudb.result b/storage/tokudb/mysql-test/tokudb/r/ext_key_2_tokudb.result index 556c5ffd897..dbcbe39cb47 100644 --- a/storage/tokudb/mysql-test/tokudb/r/ext_key_2_tokudb.result +++ b/storage/tokudb/mysql-test/tokudb/r/ext_key_2_tokudb.result @@ -1,7 +1,7 @@ drop table if exists t; select @@optimizer_switch; @@optimizer_switch -index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on +index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on create table t (a int not null, b int not null, c int not null, d int not null, primary key(a,b), key(c,a)) engine=tokudb; insert into t values (0,0,0,0),(0,1,0,1); explain select c,a,b from t where c=0 and a=0 and b=1; From 2e6d8fcc174d41ba1da5a7a4cb3ef285b1df70ff Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Tue, 19 Feb 2019 14:26:23 +0530 Subject: [PATCH 2/6] MDEV-18551: New defaults for eq_range_index_dive_limit The value for eq_range_index_dive_limit is increased to 200. --- mysql-test/main/mysqld--help.result | 2 +- mysql-test/main/range.result | 20 +++ mysql-test/main/range.test | 23 ++++ mysql-test/main/range_mrr_icp.result | 20 +++ mysql-test/main/range_vs_index_merge.result | 120 +++++++++--------- .../main/range_vs_index_merge_innodb.result | 66 +++++----- .../sys_vars/r/sysvars_server_embedded.result | 6 +- .../r/sysvars_server_notembedded.result | 6 +- sql/sys_vars.cc | 2 +- 9 files changed, 164 insertions(+), 101 deletions(-) diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index a547a978a01..e130f324da0 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -1436,7 +1436,7 @@ encrypt-binlog FALSE encrypt-tmp-disk-tables FALSE encrypt-tmp-files FALSE enforce-storage-engine (No default value) -eq-range-index-dive-limit 10 +eq-range-index-dive-limit 200 event-scheduler OFF expensive-subquery-limit 100 expire-logs-days 0 diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index bcb43d1e905..9a2d99e2f82 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -3100,6 +3100,26 @@ a b set eq_range_index_dive_limit=default; drop table t1; # +# MDEV-18551: New defaults for eq_range_index_dive_limit +# +create table ten(a int); +insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int, key(a)); +insert into t1 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C; +insert into t1 select 1 from ten A, ten B,ten C; +create table t2(a int, key(a)); +insert into t2 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C where A.a + B.a*10 + C.a*100 < 199; +# expected type=range, rows=1487 , reason=using index dives +analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range a a 5 NULL 1487 1199.00 100.00 100.00 Using where; Using index +insert into t2 values (200),(201); +# expected type=range, rows=201 , reason=using index statistics +analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,200,201); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range a a 5 NULL 201 1201.00 100.00 100.00 Using where; Using index +drop table t1,ten,t2; +# # End of 10.2 tests # set global innodb_stats_persistent= @innodb_stats_persistent_save; diff --git a/mysql-test/main/range.test b/mysql-test/main/range.test index 9edb3f39ae3..76d893f56b7 100644 --- a/mysql-test/main/range.test +++ b/mysql-test/main/range.test @@ -2074,6 +2074,29 @@ set eq_range_index_dive_limit=default; drop table t1; +--echo # +--echo # MDEV-18551: New defaults for eq_range_index_dive_limit +--echo # + +create table ten(a int); +insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int, key(a)); +insert into t1 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C; +insert into t1 select 1 from ten A, ten B,ten C; + +create table t2(a int, key(a)); +insert into t2 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C where A.a + B.a*10 + C.a*100 < 199; + +let $a= `select group_concat(a) from t2`; + +--echo # expected type=range, rows=1487 , reason=using index dives +eval analyze SELECT * FROM t1 where a in ($a); +insert into t2 values (200),(201); +let $a= `select group_concat(a) from t2`; +--echo # expected type=range, rows=201 , reason=using index statistics +eval analyze SELECT * FROM t1 where a in ($a); +drop table t1,ten,t2; + --echo # --echo # End of 10.2 tests --echo # diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result index 5d55a820673..5cda4111b6d 100644 --- a/mysql-test/main/range_mrr_icp.result +++ b/mysql-test/main/range_mrr_icp.result @@ -3097,6 +3097,26 @@ a b set eq_range_index_dive_limit=default; drop table t1; # +# MDEV-18551: New defaults for eq_range_index_dive_limit +# +create table ten(a int); +insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(a int, key(a)); +insert into t1 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C; +insert into t1 select 1 from ten A, ten B,ten C; +create table t2(a int, key(a)); +insert into t2 select A.a + B.a*10 + C.a*100 from ten A, ten B,ten C where A.a + B.a*10 + C.a*100 < 199; +# expected type=range, rows=1487 , reason=using index dives +analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range a a 5 NULL 1487 1199.00 100.00 100.00 Using where; Using index +insert into t2 values (200),(201); +# expected type=range, rows=201 , reason=using index statistics +analyze SELECT * FROM t1 where a in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,200,201); +id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra +1 SIMPLE t1 range a a 5 NULL 201 1201.00 100.00 100.00 Using where; Using index +drop table t1,ten,t2; +# # End of 10.2 tests # set global innodb_stats_persistent= @innodb_stats_persistent_save; diff --git a/mysql-test/main/range_vs_index_merge.result b/mysql-test/main/range_vs_index_merge.result index 82d2358cebc..efbf41d6372 100644 --- a/mysql-test/main/range_vs_index_merge.result +++ b/mysql-test/main/range_vs_index_merge.result @@ -1079,7 +1079,7 @@ EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CityName 35 NULL 27 Using index condition; Using where +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 28 Using index condition; Using where SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR (Name='Addis Abeba' AND Country='ETH') OR @@ -1109,33 +1109,33 @@ SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); Name Country Population -Addis Abeba ETH 2495000 -Ankara TUR 3038159 -Bangalore IND 2660088 -Basel CHE 166700 -Caracas VEN 1975294 -Dakar SEN 785071 -Delhi IND 7206704 -Dresden DEU 476668 -Jakarta IDN 9604900 -Kaunas LTU 412639 -Lagos NGA 1518000 -Lugansk UKR 469000 -Manila PHL 1581082 -Paris FRA 2125246 -Peking CHN 7472000 -Praha CZE 1181126 -Rabat MAR 623457 -Roma ITA 2643581 -Samara RUS 1156100 -Seattle USA 563374 -Seoul KOR 9981619 -Teheran IRN 6758845 -Tijuana MEX 1212232 -Tokyo JPN 7980230 Toronto CAN 688275 Vancouver CAN 514008 +Basel CHE 166700 +Peking CHN 7472000 +Praha CZE 1181126 +Dresden DEU 476668 +Addis Abeba ETH 2495000 +Paris FRA 2125246 +Jakarta IDN 9604900 +Bangalore IND 2660088 +Delhi IND 7206704 +Teheran IRN 6758845 +Roma ITA 2643581 Venezia ITA 277305 +Tokyo JPN 7980230 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Manila PHL 1581082 +Samara RUS 1156100 +Dakar SEN 785071 +Ankara TUR 3038159 +Lugansk UKR 469000 +Seattle USA 563374 +Caracas VEN 1975294 set optimizer_switch='index_merge=off'; EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR @@ -1166,7 +1166,7 @@ EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CityName 35 NULL 27 Using index condition; Using where +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 28 Using index condition; Using where SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR (Name='Addis Abeba' AND Country='ETH') OR @@ -1196,33 +1196,33 @@ SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); Name Country Population -Addis Abeba ETH 2495000 -Ankara TUR 3038159 -Bangalore IND 2660088 -Basel CHE 166700 -Caracas VEN 1975294 -Dakar SEN 785071 -Delhi IND 7206704 -Dresden DEU 476668 -Jakarta IDN 9604900 -Kaunas LTU 412639 -Lagos NGA 1518000 -Lugansk UKR 469000 -Manila PHL 1581082 -Paris FRA 2125246 -Peking CHN 7472000 -Praha CZE 1181126 -Rabat MAR 623457 -Roma ITA 2643581 -Samara RUS 1156100 -Seattle USA 563374 -Seoul KOR 9981619 -Teheran IRN 6758845 -Tijuana MEX 1212232 -Tokyo JPN 7980230 Toronto CAN 688275 Vancouver CAN 514008 +Basel CHE 166700 +Peking CHN 7472000 +Praha CZE 1181126 +Dresden DEU 476668 +Addis Abeba ETH 2495000 +Paris FRA 2125246 +Jakarta IDN 9604900 +Bangalore IND 2660088 +Delhi IND 7206704 +Teheran IRN 6758845 +Roma ITA 2643581 Venezia ITA 277305 +Tokyo JPN 7980230 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Manila PHL 1581082 +Samara RUS 1156100 +Dakar SEN 785071 +Ankara TUR 3038159 +Lugansk UKR 469000 +Seattle USA 563374 +Caracas VEN 1975294 set optimizer_switch=@save_optimizer_switch; # # Bug mdev-585: range vs index-merge with ORDER BY ... LIMIT n @@ -1900,23 +1900,23 @@ Country='NOR' AND Name IN ('Oslo', 'Bergen') OR Country='ITA' AND Name IN ('Napoli', 'Venezia'); ID Name Country Population 175 Antwerpen BEL 446525 -2808 Bergen NOR 230948 +176 Gent BEL 224180 3068 Berlin DEU 3386667 3087 Bonn DEU 301048 -2918 Braga PRT 90535 -176 Gent BEL 224180 3242 Lahti FIN 96921 -3580 Moscow RUS 8389200 -1466 Napoli ITA 1002619 -2807 Oslo NOR 508726 2974 Paris FRA 2125246 +1466 Napoli ITA 1002619 +1474 Venezia ITA 277305 +2808 Bergen NOR 230948 +2807 Oslo NOR 508726 +2928 Warszawa POL 1615369 +2931 Wroclaw POL 636765 +2918 Braga PRT 90535 2915 Porto PRT 273060 +3580 Moscow RUS 8389200 3581 St Petersburg RUS 4694000 3048 Stockholm SWE 750348 3051 Uppsala SWE 189569 -1474 Venezia ITA 277305 -2928 Warszawa POL 1615369 -2931 Wroclaw POL 636765 explain select * from City where Country='FIN' AND Name IN ('Lahti','Imatra') OR @@ -1930,6 +1930,6 @@ Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR Country='NOR' AND Name IN ('Oslo', 'Bergen') OR Country='ITA' AND Name IN ('Napoli', 'Venezia'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range CountryName,Name Name 35 NULL 20 Using index condition; Using where +1 SIMPLE City range CountryName,Name CountryName 38 NULL 20 Using index condition; Using where DROP DATABASE world; set session optimizer_switch='index_merge_sort_intersection=default'; diff --git a/mysql-test/main/range_vs_index_merge_innodb.result b/mysql-test/main/range_vs_index_merge_innodb.result index 6b6b77232e2..03b43431fe7 100644 --- a/mysql-test/main/range_vs_index_merge_innodb.result +++ b/mysql-test/main/range_vs_index_merge_innodb.result @@ -1085,7 +1085,7 @@ EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CityName 35 NULL 27 Using index condition; Using where +1 SIMPLE City index_merge Country,CountryPopulation,CountryName,CityName CountryName,CityName 38,35 NULL 27 Using sort_union(CountryName,CityName); Using where SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR (Name='Addis Abeba' AND Country='ETH') OR @@ -1116,32 +1116,32 @@ SELECT Name, Country, Population FROM City WHERE (Name='Seattle' AND Country='USA'); Name Country Population Addis Abeba ETH 2495000 -Ankara TUR 3038159 -Bangalore IND 2660088 -Basel CHE 166700 -Caracas VEN 1975294 -Dakar SEN 785071 -Delhi IND 7206704 -Dresden DEU 476668 -Jakarta IDN 9604900 -Kaunas LTU 412639 -Lagos NGA 1518000 -Lugansk UKR 469000 Manila PHL 1581082 -Paris FRA 2125246 -Peking CHN 7472000 -Praha CZE 1181126 -Rabat MAR 623457 -Roma ITA 2643581 -Samara RUS 1156100 -Seattle USA 563374 -Seoul KOR 9981619 +Jakarta IDN 9604900 +Delhi IND 7206704 +Bangalore IND 2660088 Teheran IRN 6758845 -Tijuana MEX 1212232 +Roma ITA 2643581 +Venezia ITA 277305 Tokyo JPN 7980230 Toronto CAN 688275 Vancouver CAN 514008 -Venezia ITA 277305 +Peking CHN 7472000 +Seoul KOR 9981619 +Kaunas LTU 412639 +Rabat MAR 623457 +Tijuana MEX 1212232 +Lagos NGA 1518000 +Paris FRA 2125246 +Dresden DEU 476668 +Dakar SEN 785071 +Basel CHE 166700 +Praha CZE 1181126 +Ankara TUR 3038159 +Lugansk UKR 469000 +Caracas VEN 1975294 +Samara RUS 1156100 +Seattle USA 563374 set optimizer_switch='index_merge=off'; EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR @@ -1172,7 +1172,7 @@ EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CityName 35 NULL 27 Using index condition; Using where +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CityName 35 NULL 28 Using index condition; Using where SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR (Name='Addis Abeba' AND Country='ETH') OR @@ -1906,23 +1906,23 @@ Country='NOR' AND Name IN ('Oslo', 'Bergen') OR Country='ITA' AND Name IN ('Napoli', 'Venezia'); ID Name Country Population 175 Antwerpen BEL 446525 -2808 Bergen NOR 230948 +176 Gent BEL 224180 3068 Berlin DEU 3386667 3087 Bonn DEU 301048 -2918 Braga PRT 90535 -176 Gent BEL 224180 3242 Lahti FIN 96921 -3580 Moscow RUS 8389200 -1466 Napoli ITA 1002619 -2807 Oslo NOR 508726 2974 Paris FRA 2125246 +1466 Napoli ITA 1002619 +1474 Venezia ITA 277305 +2808 Bergen NOR 230948 +2807 Oslo NOR 508726 +2928 Warszawa POL 1615369 +2931 Wroclaw POL 636765 +2918 Braga PRT 90535 2915 Porto PRT 273060 +3580 Moscow RUS 8389200 3581 St Petersburg RUS 4694000 3048 Stockholm SWE 750348 3051 Uppsala SWE 189569 -1474 Venezia ITA 277305 -2928 Warszawa POL 1615369 -2931 Wroclaw POL 636765 explain select * from City where Country='FIN' AND Name IN ('Lahti','Imatra') OR @@ -1936,7 +1936,7 @@ Country='POL' AND Name IN ('Warszawa', 'Wroclaw') OR Country='NOR' AND Name IN ('Oslo', 'Bergen') OR Country='ITA' AND Name IN ('Napoli', 'Venezia'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range CountryName,Name Name 35 NULL 20 Using index condition; Using where +1 SIMPLE City range CountryName,Name CountryName 38 NULL 20 Using index condition; Using where DROP DATABASE world; set session optimizer_switch='index_merge_sort_intersection=default'; set global innodb_stats_persistent= @innodb_stats_persistent_save; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index 483d38674ef..c517403f842 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -881,10 +881,10 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME EQ_RANGE_INDEX_DIVE_LIMIT -SESSION_VALUE 10 -GLOBAL_VALUE 10 +SESSION_VALUE 200 +GLOBAL_VALUE 200 GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE 10 +DEFAULT_VALUE 200 VARIABLE_SCOPE SESSION VARIABLE_TYPE INT UNSIGNED VARIABLE_COMMENT The optimizer will use existing index statistics instead of doing index dives for equality ranges if the number of equality ranges for the index is larger than or equal to this number. If set to 0, index dives are always used. diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index cd119f98438..6d0eb0f8ef2 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -895,10 +895,10 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT NULL VARIABLE_NAME EQ_RANGE_INDEX_DIVE_LIMIT -SESSION_VALUE 10 -GLOBAL_VALUE 10 +SESSION_VALUE 200 +GLOBAL_VALUE 200 GLOBAL_VALUE_ORIGIN COMPILE-TIME -DEFAULT_VALUE 10 +DEFAULT_VALUE 200 VARIABLE_SCOPE SESSION VARIABLE_TYPE INT UNSIGNED VARIABLE_COMMENT The optimizer will use existing index statistics instead of doing index dives for equality ranges if the number of equality ranges for the index is larger than or equal to this number. If set to 0, index dives are always used. diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index a14bfefa752..df9e8525689 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2723,7 +2723,7 @@ static Sys_var_uint Sys_eq_range_index_dive_limit( "ranges for the index is larger than or equal to this number. " "If set to 0, index dives are always used.", SESSION_VAR(eq_range_index_dive_limit), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(0, UINT_MAX32), DEFAULT(10), + VALID_RANGE(0, UINT_MAX32), DEFAULT(200), BLOCK_SIZE(1)); static Sys_var_ulong Sys_range_alloc_block_size( From 3dc6f0410baf2caa81394c3b0f8963807f77fc78 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 19 Feb 2019 09:43:24 +0100 Subject: [PATCH 3/6] MDEV-15693 Stop packaging data directory into ZIPs Remove CMake INSTALL command for COMPONENT DataFiles. mysql_install_db.exe will calculate default datadir, so that it can be called without any parameters. --- sql/CMakeLists.txt | 6 ------ sql/mysql_install_db.cc | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 890b8ff8b86..ecca723b9e4 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -448,12 +448,6 @@ IF(WIN32 AND TARGET mysqld AND NOT CMAKE_CROSSCOMPILING) ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/initdb.dep ) - INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data DESTINATION . - COMPONENT DataFiles - PATTERN "initdb.dep" EXCLUDE - PATTERN "bootstrap.sql" EXCLUDE - PATTERN "aria*" EXCLUDE - ) ELSE() # Not windows or cross compiling, just install an empty directory INSTALL(FILES ${DUMMY_FILE} DESTINATION data/mysql COMPONENT DataFiles) diff --git a/sql/mysql_install_db.cc b/sql/mysql_install_db.cc index 718e49969e0..93a3b54bdc2 100644 --- a/sql/mysql_install_db.cc +++ b/sql/mysql_install_db.cc @@ -39,7 +39,8 @@ struct IUnknown; extern "C" const char* mysql_bootstrap_sql[]; -char default_os_user[]= "NT AUTHORITY\\NetworkService"; +static char default_os_user[]= "NT AUTHORITY\\NetworkService"; +static char default_datadir[MAX_PATH]; static int create_db_instance(); static uint opt_silent; static char datadir_buffer[FN_REFLEN]; @@ -169,8 +170,27 @@ int main(int argc, char **argv) exit(error); if (!opt_datadir) { - my_print_help(my_long_options); - die("parameter --datadir=# is mandatory"); + /* + Figure out default data directory. It "data" directory, next to "bin" directory, where + mysql_install_db.exe resides. + */ + strcpy(default_datadir, self_name); + p = strrchr(default_datadir, FN_LIBCHAR); + if (p) + { + *p= 0; + p= strrchr(default_datadir, FN_LIBCHAR); + if (p) + *p= 0; + } + if (!p) + { + die("--datadir option not provided, and default datadir not found"); + my_print_help(my_long_options); + } + strncat(default_datadir, "\\data", sizeof(default_datadir)); + opt_datadir= default_datadir; + printf("Default data directory is %s\n",opt_datadir); } /* Print some help on errors */ From 47f15ea73c49e90b16a4a4adf5414f51bdbf97a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Thu, 14 Feb 2019 23:03:53 +0200 Subject: [PATCH 4/6] Simplify column data adding method The add method does not need to provide the row order number. It was only used to detect if the minimum/maximum value was populated once or not, so as to force an update for the first encounter of a value. --- sql/sql_statistics.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index db214a1fe28..f903ce143a4 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -324,7 +324,7 @@ private: public: inline void init(THD *thd, Field * table_field); - inline bool add(ha_rows rowno); + inline bool add(); inline void finish(ha_rows rows); inline void cleanup(); }; @@ -2483,7 +2483,7 @@ void Column_statistics_collected::init(THD *thd, Field *table_field) */ inline -bool Column_statistics_collected::add(ha_rows rowno) +bool Column_statistics_collected::add() { bool err= 0; @@ -2492,9 +2492,11 @@ bool Column_statistics_collected::add(ha_rows rowno) else { column_total_length+= column->value_length(); - if (min_value && column->update_min(min_value, rowno == nulls)) + if (min_value && column->update_min(min_value, + is_null(COLUMN_STAT_MIN_VALUE))) set_not_null(COLUMN_STAT_MIN_VALUE); - if (max_value && column->update_max(max_value, rowno == nulls)) + if (max_value && column->update_max(max_value, + is_null(COLUMN_STAT_MAX_VALUE))) set_not_null(COLUMN_STAT_MAX_VALUE); if (count_distinct) err= count_distinct->add(); @@ -2761,7 +2763,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table) table_field= *field_ptr; if (!bitmap_is_set(table->read_set, table_field->field_index)) continue; - if ((rc= table_field->collected_stats->add(rows))) + if ((rc= table_field->collected_stats->add())) break; } if (rc) From f0773b7842fcfd2032b630b4cfc7404a29d12a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Fri, 15 Feb 2019 01:23:00 +0200 Subject: [PATCH 5/6] Introduce analyze_sample_percentage variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The variable controls the amount of sampling analyze table performs. If ANALYZE table with histogram collection is too slow, one can reduce the time taken by setting analyze_sample_percentage to a lower value of the total number of rows. Setting it to 0 will use a formula to compute how many rows to sample: The number of rows collected is capped to a minimum of 50000 and increases logarithmically with a coffecient of 4096. The coffecient is chosen so that we expect an error of less than 3% in our estimations according to the paper: "Random Sampling for Histogram Construction: How much is enough?” – Surajit Chaudhuri, Rajeev Motwani, Vivek Narasayya, ACM SIGMOD, 1998. The drawback of sampling is that avg_frequency number is computed imprecisely and will yeild a smaller number than the real one. --- mysql-test/main/mysqld--help.result | 5 + mysql-test/main/statistics.result | 104 ++++++++++++++++++ mysql-test/main/statistics.test | 88 +++++++++++++++ .../sys_vars/r/sysvars_server_embedded.result | 14 +++ .../r/sysvars_server_notembedded.result | 14 +++ sql/sql_class.h | 1 + sql/sql_statistics.cc | 40 +++++-- sql/sys_vars.cc | 9 ++ 8 files changed, 265 insertions(+), 10 deletions(-) diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index e130f324da0..65fda40720d 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -15,6 +15,10 @@ The following specify which files/extra groups are read (specified before remain --alter-algorithm[=name] Specify the alter table algorithm. One of: DEFAULT, COPY, INPLACE, NOCOPY, INSTANT + --analyze-sample-percentage=# + Percentage of rows from the table ANALYZE TABLE will + sample to collect table statistics. Set to 0 to let + MariaDB decide what percentage of rows to sample. -a, --ansi Use ANSI SQL syntax instead of MySQL syntax. This mode will also set transaction isolation level 'serializable'. --auto-increment-increment[=#] @@ -1385,6 +1389,7 @@ The following specify which files/extra groups are read (specified before remain Variables (--variable-name=value) allow-suspicious-udfs FALSE alter-algorithm DEFAULT +analyze-sample-percentage 100 auto-increment-increment 1 auto-increment-offset 1 autocommit TRUE diff --git a/mysql-test/main/statistics.result b/mysql-test/main/statistics.result index 5f6a7cd7bb3..ee97ec05391 100644 --- a/mysql-test/main/statistics.result +++ b/mysql-test/main/statistics.result @@ -1760,3 +1760,107 @@ DROP TABLE t1; # End of 10.2 tests # set histogram_size=@save_hist_size, histogram_type=@save_hist_type; +# +# Start of 10.4 tests +# +# +# Test analyze_sample_percentage system variable. +# +set @save_use_stat_tables=@@use_stat_tables; +set @save_analyze_sample_percentage=@@analyze_sample_percentage; +set session rand_seed1=42; +set session rand_seed2=62; +set use_stat_tables=PREFERABLY; +set histogram_size=10; +CREATE TABLE t1 (id int); +INSERT INTO t1 (id) VALUES (1), (1), (1), (1), (1), (1), (1); +INSERT INTO t1 (id) SELECT id FROM t1; +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; +INSERT INTO t1 SELECT id+1024 FROM t1; +INSERT INTO t1 SELECT id+2048 FROM t1; +INSERT INTO t1 SELECT id+4096 FROM t1; +INSERT INTO t1 SELECT id+9192 FROM t1; +# +# This query will should show a full table scan analysis. +# +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, +DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) +t1 id 1 17384 0.0000 4.0000 14.0000 0.082,0.086,0.086,0.086,0.086,0.141,0.086,0.086,0.086,0.086,0.086 +set analyze_sample_percentage=0.1; +# +# This query will show an innacurate avg_frequency value. +# +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status Table is already up to date +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, +DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) +t1 id 111 17026 0.0000 4.0000 1.0047 0.039,0.098,0.055,0.118,0.078,0.157,0.082,0.118,0.094,0.063,0.098 +# +# This query will show a better avg_frequency value. +# +set analyze_sample_percentage=25; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status Table is already up to date +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, +DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) +t1 id 1 17384 0.0000 4.0000 3.5736 0.082,0.086,0.086,0.082,0.086,0.145,0.086,0.086,0.082,0.086,0.090 +set analyze_sample_percentage=0; +# +# Test self adjusting sampling level. +# +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status Table is already up to date +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, +DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) +t1 id 1 17384 0.0000 4.0000 7.4523 0.082,0.090,0.086,0.082,0.086,0.145,0.086,0.082,0.086,0.086,0.086 +# +# Test record estimation is working properly. +# +select count(*) from t1; +count(*) +229376 +explain select * from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 229060 +set analyze_sample_percentage=100; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status Table is already up to date +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, +DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) +t1 id 1 17384 0.0000 4.0000 14.0000 0.082,0.086,0.086,0.086,0.086,0.141,0.086,0.086,0.086,0.086,0.086 +explain select * from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 229376 +set use_stat_tables=@save_use_stat_tables; +drop table t1; diff --git a/mysql-test/main/statistics.test b/mysql-test/main/statistics.test index 78439e3e68a..84bb7c10059 100644 --- a/mysql-test/main/statistics.test +++ b/mysql-test/main/statistics.test @@ -901,3 +901,91 @@ DROP TABLE t1; --echo # set histogram_size=@save_hist_size, histogram_type=@save_hist_type; + + +--echo # +--echo # Start of 10.4 tests +--echo # + +--echo # +--echo # Test analyze_sample_percentage system variable. +--echo # +set @save_use_stat_tables=@@use_stat_tables; +set @save_analyze_sample_percentage=@@analyze_sample_percentage; + +set session rand_seed1=42; +set session rand_seed2=62; + +set use_stat_tables=PREFERABLY; +set histogram_size=10; + +CREATE TABLE t1 (id int); +INSERT INTO t1 (id) VALUES (1), (1), (1), (1), (1), (1), (1); +INSERT INTO t1 (id) SELECT id FROM t1; +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; +INSERT INTO t1 SELECT id+1024 FROM t1; +INSERT INTO t1 SELECT id+2048 FROM t1; +INSERT INTO t1 SELECT id+4096 FROM t1; +INSERT INTO t1 SELECT id+9192 FROM t1; + +--echo # +--echo # This query will should show a full table scan analysis. +--echo # +ANALYZE TABLE t1; +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, + DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; + +set analyze_sample_percentage=0.1; + +--echo # +--echo # This query will show an innacurate avg_frequency value. +--echo # +ANALYZE TABLE t1; +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, + DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; + +--echo # +--echo # This query will show a better avg_frequency value. +--echo # +set analyze_sample_percentage=25; +ANALYZE TABLE t1; +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, + DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; + + +set analyze_sample_percentage=0; +--echo # +--echo # Test self adjusting sampling level. +--echo # +ANALYZE TABLE t1; +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, + DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +-- echo # +-- echo # Test record estimation is working properly. +-- echo # +select count(*) from t1; +explain select * from t1; + +set analyze_sample_percentage=100; +ANALYZE TABLE t1; +select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency, + DECODE_HISTOGRAM(hist_type, histogram) +from mysql.column_stats; +explain select * from t1; + +set use_stat_tables=@save_use_stat_tables; + +drop table t1; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result index c517403f842..67cab18a6bb 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_embedded.result @@ -40,6 +40,20 @@ NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST DEFAULT,COPY,INPLACE,NOCOPY,INSTANT READ_ONLY NO COMMAND_LINE_ARGUMENT OPTIONAL +VARIABLE_NAME ANALYZE_SAMPLE_PERCENTAGE +SESSION_VALUE 100.000000 +GLOBAL_VALUE 100.000000 +GLOBAL_VALUE_ORIGIN COMPILE-TIME +DEFAULT_VALUE 100.000000 +VARIABLE_SCOPE SESSION +VARIABLE_TYPE DOUBLE +VARIABLE_COMMENT Percentage of rows from the table ANALYZE TABLE will sample to collect table statistics. Set to 0 to let MariaDB decide what percentage of rows to sample. +NUMERIC_MIN_VALUE 0 +NUMERIC_MAX_VALUE 100 +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY NO +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME AUTOCOMMIT SESSION_VALUE ON GLOBAL_VALUE ON diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 6d0eb0f8ef2..35ce738960f 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -40,6 +40,20 @@ NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST DEFAULT,COPY,INPLACE,NOCOPY,INSTANT READ_ONLY NO COMMAND_LINE_ARGUMENT OPTIONAL +VARIABLE_NAME ANALYZE_SAMPLE_PERCENTAGE +SESSION_VALUE 100.000000 +GLOBAL_VALUE 100.000000 +GLOBAL_VALUE_ORIGIN COMPILE-TIME +DEFAULT_VALUE 100.000000 +VARIABLE_SCOPE SESSION +VARIABLE_TYPE DOUBLE +VARIABLE_COMMENT Percentage of rows from the table ANALYZE TABLE will sample to collect table statistics. Set to 0 to let MariaDB decide what percentage of rows to sample. +NUMERIC_MIN_VALUE 0 +NUMERIC_MAX_VALUE 100 +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST NULL +READ_ONLY NO +COMMAND_LINE_ARGUMENT REQUIRED VARIABLE_NAME AUTOCOMMIT SESSION_VALUE ON GLOBAL_VALUE ON diff --git a/sql/sql_class.h b/sql/sql_class.h index 56b8aca19ab..3b0099ccae8 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -622,6 +622,7 @@ typedef struct system_variables ulong optimizer_selectivity_sampling_limit; ulong optimizer_use_condition_selectivity; ulong use_stat_tables; + double sample_percentage; ulong histogram_size; ulong histogram_type; ulong preload_buff_size; diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index f903ce143a4..27fab974441 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -2729,12 +2729,28 @@ int collect_statistics_for_table(THD *thd, TABLE *table) Field *table_field; ha_rows rows= 0; handler *file=table->file; + double sample_fraction= thd->variables.sample_percentage / 100; + const ha_rows MIN_THRESHOLD_FOR_SAMPLING= 50000; DBUG_ENTER("collect_statistics_for_table"); table->collected_stats->cardinality_is_null= TRUE; table->collected_stats->cardinality= 0; + if (thd->variables.sample_percentage == 0) + { + if (file->records() < MIN_THRESHOLD_FOR_SAMPLING) + { + sample_fraction= 1; + } + else + { + sample_fraction= std::fmin( + (MIN_THRESHOLD_FOR_SAMPLING + 4096 * + log(200 * file->records())) / file->records(), 1); + } + } + for (field_ptr= table->field; *field_ptr; field_ptr++) { table_field= *field_ptr; @@ -2747,7 +2763,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table) /* Perform a full table scan to collect statistics on 'table's columns */ if (!(rc= file->ha_rnd_init(TRUE))) - { + { DEBUG_SYNC(table->in_use, "statistics_collection_start"); while ((rc= file->ha_rnd_next(table->record[0])) != HA_ERR_END_OF_FILE) @@ -2758,17 +2774,20 @@ int collect_statistics_for_table(THD *thd, TABLE *table) if (rc) break; - for (field_ptr= table->field; *field_ptr; field_ptr++) + if (thd_rnd(thd) <= sample_fraction) { - table_field= *field_ptr; - if (!bitmap_is_set(table->read_set, table_field->field_index)) - continue; - if ((rc= table_field->collected_stats->add())) + for (field_ptr= table->field; *field_ptr; field_ptr++) + { + table_field= *field_ptr; + if (!bitmap_is_set(table->read_set, table_field->field_index)) + continue; + if ((rc= table_field->collected_stats->add())) + break; + } + if (rc) break; + rows++; } - if (rc) - break; - rows++; } file->ha_rnd_end(); } @@ -2782,7 +2801,8 @@ int collect_statistics_for_table(THD *thd, TABLE *table) if (!rc) { table->collected_stats->cardinality_is_null= FALSE; - table->collected_stats->cardinality= rows; + table->collected_stats->cardinality= + static_cast(rows / sample_fraction); } bitmap_clear_all(table->write_set); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index df9e8525689..dbfbb452ace 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -350,6 +350,15 @@ static Sys_var_long Sys_pfs_connect_attrs_size( #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ +static Sys_var_double Sys_analyze_sample_percentage( + "analyze_sample_percentage", + "Percentage of rows from the table ANALYZE TABLE will sample " + "to collect table statistics. Set to 0 to let MariaDB decide " + "what percentage of rows to sample.", + SESSION_VAR(sample_percentage), + CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 100), + DEFAULT(100)); + static Sys_var_ulong Sys_auto_increment_increment( "auto_increment_increment", "Auto-increment columns are incremented by this", From 764429271dc94e5af08706dd0ac6fb962c15726d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Sun, 17 Feb 2019 00:44:58 +0200 Subject: [PATCH 6/6] Implement avg_frequency unsmoothed jacknife estimator When sampling data through ANALYZE TABLE, use the estimator to get a better estimation of avg_frequency instead of just using the raw sampled data. --- mysql-test/main/statistics.result | 15 +++-- mysql-test/main/statistics.test | 5 +- sql/sql_statistics.cc | 107 +++++++++++++++++++++++------- 3 files changed, 96 insertions(+), 31 deletions(-) diff --git a/mysql-test/main/statistics.result b/mysql-test/main/statistics.result index ee97ec05391..787f0194532 100644 --- a/mysql-test/main/statistics.result +++ b/mysql-test/main/statistics.result @@ -1768,6 +1768,7 @@ set histogram_size=@save_hist_size, histogram_type=@save_hist_type; # set @save_use_stat_tables=@@use_stat_tables; set @save_analyze_sample_percentage=@@analyze_sample_percentage; +set @save_hist_size=@@histogram_size; set session rand_seed1=42; set session rand_seed2=62; set use_stat_tables=PREFERABLY; @@ -1800,7 +1801,7 @@ select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, a DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats; table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) -t1 id 1 17384 0.0000 4.0000 14.0000 0.082,0.086,0.086,0.086,0.086,0.141,0.086,0.086,0.086,0.086,0.086 +t1 id 1 17384 0.0000 4.0000 14.0000 0.15705,0.15711,0.21463,0.15705,0.15711,0.15706 set analyze_sample_percentage=0.1; # # This query will show an innacurate avg_frequency value. @@ -1813,7 +1814,7 @@ select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, a DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats; table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) -t1 id 111 17026 0.0000 4.0000 1.0047 0.039,0.098,0.055,0.118,0.078,0.157,0.082,0.118,0.094,0.063,0.098 +t1 id 111 17026 0.0000 4.0000 10.4739 0.13649,0.14922,0.16921,0.21141,0.18355,0.15012 # # This query will show a better avg_frequency value. # @@ -1826,7 +1827,7 @@ select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, a DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats; table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) -t1 id 1 17384 0.0000 4.0000 3.5736 0.082,0.086,0.086,0.082,0.086,0.145,0.086,0.086,0.082,0.086,0.090 +t1 id 1 17384 0.0000 4.0000 14.0401 0.15566,0.15590,0.15729,0.21538,0.15790,0.15787 set analyze_sample_percentage=0; # # Test self adjusting sampling level. @@ -1839,7 +1840,7 @@ select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, a DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats; table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) -t1 id 1 17384 0.0000 4.0000 7.4523 0.082,0.090,0.086,0.082,0.086,0.145,0.086,0.082,0.086,0.086,0.086 +t1 id 1 17384 0.0000 4.0000 13.9812 0.15860,0.15767,0.21515,0.15573,0.15630,0.15654 # # Test record estimation is working properly. # @@ -1858,9 +1859,11 @@ select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, a DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats; table_name column_name min_value max_value nulls_ratio avg_length avg_frequency DECODE_HISTOGRAM(hist_type, histogram) -t1 id 1 17384 0.0000 4.0000 14.0000 0.082,0.086,0.086,0.086,0.086,0.141,0.086,0.086,0.086,0.086,0.086 +t1 id 1 17384 0.0000 4.0000 14.0000 0.15705,0.15711,0.21463,0.15705,0.15711,0.15706 explain select * from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 229376 -set use_stat_tables=@save_use_stat_tables; drop table t1; +set analyze_sample_percentage=@save_analyze_sample_percentage; +set histogram_size=@save_hist_size; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/main/statistics.test b/mysql-test/main/statistics.test index 84bb7c10059..880f2987b50 100644 --- a/mysql-test/main/statistics.test +++ b/mysql-test/main/statistics.test @@ -912,6 +912,7 @@ set histogram_size=@save_hist_size, histogram_type=@save_hist_type; --echo # set @save_use_stat_tables=@@use_stat_tables; set @save_analyze_sample_percentage=@@analyze_sample_percentage; +set @save_hist_size=@@histogram_size; set session rand_seed1=42; set session rand_seed2=62; @@ -986,6 +987,8 @@ select table_name, column_name, min_value, max_value, nulls_ratio, avg_length, a from mysql.column_stats; explain select * from t1; -set use_stat_tables=@save_use_stat_tables; drop table t1; +set analyze_sample_percentage=@save_analyze_sample_percentage; +set histogram_size=@save_hist_size; +set use_stat_tables=@save_use_stat_tables; diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 27fab974441..8683368e818 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -325,7 +325,7 @@ public: inline void init(THD *thd, Field * table_field); inline bool add(); - inline void finish(ha_rows rows); + inline void finish(ha_rows rows, double sample_fraction); inline void cleanup(); }; @@ -1540,6 +1540,8 @@ class Histogram_builder uint curr_bucket; /* number of the current bucket to be built */ ulonglong count; /* number of values retrieved */ ulonglong count_distinct; /* number of distinct values retrieved */ + /* number of distinct values that occured only once */ + ulonglong count_distinct_single_occurence; public: Histogram_builder(Field *col, uint col_len, ha_rows rows) @@ -1553,14 +1555,21 @@ public: bucket_capacity= (double) records / (hist_width + 1); curr_bucket= 0; count= 0; - count_distinct= 0; + count_distinct= 0; + count_distinct_single_occurence= 0; } - ulonglong get_count_distinct() { return count_distinct; } + ulonglong get_count_distinct() const { return count_distinct; } + ulonglong get_count_single_occurence() const + { + return count_distinct_single_occurence; + } int next(void *elem, element_count elem_cnt) { count_distinct++; + if (elem_cnt == 1) + count_distinct_single_occurence++; count+= elem_cnt; if (curr_bucket == hist_width) return 0; @@ -1574,7 +1583,7 @@ public: count > bucket_capacity * (curr_bucket + 1)) { histogram->set_prev_value(curr_bucket); - curr_bucket++; + curr_bucket++; } } return 0; @@ -1590,9 +1599,18 @@ int histogram_build_walk(void *elem, element_count elem_cnt, void *arg) return hist_builder->next(elem, elem_cnt); } + + +static int count_distinct_single_occurence_walk(void *elem, + element_count count, void *arg) +{ + ((ulonglong*)arg)[0]+= 1; + if (count == 1) + ((ulonglong*)arg)[1]+= 1; + return 0; +} + C_MODE_END - - /* The class Count_distinct_field is a helper class used to calculate the number of distinct values for a column. The class employs the @@ -1611,6 +1629,9 @@ protected: Unique *tree; /* The helper object to contain distinct values */ uint tree_key_length; /* The length of the keys for the elements of 'tree */ + ulonglong distincts; + ulonglong distincts_single_occurence; + public: Count_distinct_field() {} @@ -1662,30 +1683,40 @@ public: { return tree->unique_add(table_field->ptr); } - + /* @brief Calculate the number of elements accumulated in the container of 'tree' */ - ulonglong get_value() + void walk_tree() { - ulonglong count; - if (tree->elements == 0) - return (ulonglong) tree->elements_in_tree(); - count= 0; - tree->walk(table_field->table, count_distinct_walk, (void*) &count); - return count; + ulonglong counts[2] = {0, 0}; + tree->walk(table_field->table, + count_distinct_single_occurence_walk, counts); + distincts= counts[0]; + distincts_single_occurence= counts[1]; } /* @brief - Build the histogram for the elements accumulated in the container of 'tree' + Calculate a histogram of the tree */ - ulonglong get_value_with_histogram(ha_rows rows) + void walk_tree_with_histogram(ha_rows rows) { Histogram_builder hist_builder(table_field, tree_key_length, rows); tree->walk(table_field->table, histogram_build_walk, (void *) &hist_builder); - return hist_builder.get_count_distinct(); + distincts= hist_builder.get_count_distinct(); + distincts_single_occurence= hist_builder.get_count_single_occurence(); + } + + ulonglong get_count_distinct() + { + return distincts; + } + + ulonglong get_count_distinct_single_occurence() + { + return distincts_single_occurence; } /* @@ -2514,7 +2545,7 @@ bool Column_statistics_collected::add() */ inline -void Column_statistics_collected::finish(ha_rows rows) +void Column_statistics_collected::finish(ha_rows rows, double sample_fraction) { double val; @@ -2532,16 +2563,44 @@ void Column_statistics_collected::finish(ha_rows rows) } if (count_distinct) { - ulonglong distincts; uint hist_size= count_distinct->get_hist_size(); + + /* Compute cardinality statistics and optionally histogram. */ if (hist_size == 0) - distincts= count_distinct->get_value(); + count_distinct->walk_tree(); else - distincts= count_distinct->get_value_with_histogram(rows - nulls); + count_distinct->walk_tree_with_histogram(rows - nulls); + + ulonglong distincts= count_distinct->get_count_distinct(); + ulonglong distincts_single_occurence= + count_distinct->get_count_distinct_single_occurence(); + if (distincts) { - val= (double) (rows - nulls) / distincts; - set_avg_frequency(val); + /* + We use the unsmoothed first-order jackknife estimator" to estimate + the number of distinct values. + With a sufficient large percentage of rows sampled (80%), we revert back + to computing the avg_frequency off of the raw data. + */ + if (sample_fraction > 0.8) + val= (double) (rows - nulls) / distincts; + else + { + if (nulls == 1) + distincts_single_occurence+= 1; + if (nulls) + distincts+= 1; + double fraction_single_occurence= + static_cast(distincts_single_occurence) / rows; + double total_number_of_rows= rows / sample_fraction; + double estimate_total_distincts= total_number_of_rows / + (distincts / + (1.0 - (1.0 - sample_fraction) * fraction_single_occurence)); + val = std::fmax(estimate_total_distincts * (rows - nulls) / rows, 1.0); + } + + set_avg_frequency(val); set_not_null(COLUMN_STAT_AVG_FREQUENCY); } else @@ -2813,7 +2872,7 @@ int collect_statistics_for_table(THD *thd, TABLE *table) continue; bitmap_set_bit(table->write_set, table_field->field_index); if (!rc) - table_field->collected_stats->finish(rows); + table_field->collected_stats->finish(rows, sample_fraction); else table_field->collected_stats->cleanup(); }