plan: fix convert to physical plan, when there are multiple index ranges (#1532)

This commit is contained in:
zimulala
2016-08-01 18:05:39 +08:00
committed by GitHub
parent 9a53a54fe7
commit 0aa312bbef
3 changed files with 21 additions and 3 deletions

View File

@ -14,8 +14,9 @@
package plan
import (
"github.com/pingcap/tidb/util/types"
"math"
"github.com/pingcap/tidb/util/types"
)
// matchProperty implements PhysicalPlan matchProperty interface.

View File

@ -362,6 +362,14 @@ func (s *testPlanSuite) TestRefine(c *C) {
sql: "select a from t where c <= 5 and c >= 3 and d = 1",
best: "Index(t.c_d_e)[[3,5]]->Selection->Projection",
},
{
sql: "select a from t where c = 1 or c = 2 or c = 3",
best: "Index(t.c_d_e)[[1,1] [2,2] [3,3]]->Projection",
},
{
sql: "select a from t where c = 1 or c = 2 or c = 3 or c = 4 or c = 5",
best: "Table(t)->Selection->Projection",
},
}
for _, ca := range cases {
comment := Commentf("for %s", ca.sql)

View File

@ -14,13 +14,14 @@
package plan
import (
"math"
"github.com/juju/errors"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/plan/statistics"
"github.com/pingcap/tidb/util/types"
"math"
)
const (
@ -47,7 +48,15 @@ func getRowCountByIndexRange(table *statistics.Table, indexRange *IndexRange, in
rowCount, err = table.Columns[offset].LessRowCount(r)
rowCount = table.Count - rowCount
} else {
rowCount, err = table.Columns[offset].BetweenRowCount(l, r)
compare, err1 := l.CompareDatum(r)
if err1 != nil {
return 0, errors.Trace(err1)
}
if compare == 0 {
rowCount, err = table.Columns[offset].EqualRowCount(l)
} else {
rowCount, err = table.Columns[offset].BetweenRowCount(l, r)
}
}
if err != nil {
return 0, errors.Trace(err)