From e6b2fa861a285babec6be57e30d315b85c06026f Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Mon, 14 Sep 2020 16:44:18 +0800 Subject: [PATCH] add tests --- cmd/explaintest/r/explain_indexmerge.result | 7 +++++++ cmd/explaintest/t/explain_indexmerge.test | 1 + planner/core/stats.go | 4 +--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/explaintest/r/explain_indexmerge.result b/cmd/explaintest/r/explain_indexmerge.result index e533585d9bee4..ef7f6cdf80088 100644 --- a/cmd/explaintest/r/explain_indexmerge.result +++ b/cmd/explaintest/r/explain_indexmerge.result @@ -97,6 +97,13 @@ label = "cop" } set session tidb_enable_index_merge = off; +explain select /*+ use_index_merge(t, primary, tb, tc) */ * from t where a <= 500000 or b <= 1000000 or c <= 3000000; +id estRows task access object operator info +IndexMerge_9 3560000.00 root +├─TableRangeScan_5(Build) 500000.00 cop[tikv] table:t range:[-inf,500000], keep order:false +├─IndexRangeScan_6(Build) 1000000.00 cop[tikv] table:t, index:tb(b) range:[-inf,1000000], keep order:false +├─IndexRangeScan_7(Build) 3000000.00 cop[tikv] table:t, index:tc(c) range:[-inf,3000000], keep order:false +└─TableRowIDScan_8(Probe) 3560000.00 cop[tikv] table:t keep order:false explain select /*+ use_index_merge(t, tb, tc) */ * from t where b < 50 or c < 5000000; id estRows task access object operator info IndexMerge_8 4999999.00 root diff --git a/cmd/explaintest/t/explain_indexmerge.test b/cmd/explaintest/t/explain_indexmerge.test index 8a7089936f0fe..372d23b5c1392 100644 --- a/cmd/explaintest/t/explain_indexmerge.test +++ b/cmd/explaintest/t/explain_indexmerge.test @@ -20,6 +20,7 @@ explain select * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) an explain format="dot" select * from t where (a < 50 or b < 50) and f > 100; set session tidb_enable_index_merge = off; # be forced to use IndexMerge +explain select /*+ use_index_merge(t, primary, tb, tc) */ * from t where a <= 500000 or b <= 1000000 or c <= 3000000; explain select /*+ use_index_merge(t, tb, tc) */ * from t where b < 50 or c < 5000000; explain select /*+ use_index_merge(t, tb, tc) */ * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10; explain select /*+ use_index_merge(t, tb) */ * from t where b < 50 or c < 5000000; diff --git a/planner/core/stats.go b/planner/core/stats.go index eaeac13539527..e33a87bf41291 100644 --- a/planner/core/stats.go +++ b/planner/core/stats.go @@ -425,9 +425,7 @@ func (ds *DataSource) generateIndexMergeOrPaths() { sel = SelectionFactor } possiblePath.CountAfterAccess = sel * ds.tableStats.RowCount - if possiblePath != nil { - ds.possibleAccessPaths = append(ds.possibleAccessPaths, possiblePath) - } + ds.possibleAccessPaths = append(ds.possibleAccessPaths, possiblePath) } } }