From ef178a3513f0665009dc7f461582e15bab8da898 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 20 Mar 2017 17:34:44 +0800 Subject: [PATCH] fix bug --- plan/physical_plan_builder.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plan/physical_plan_builder.go b/plan/physical_plan_builder.go index fe37632ee27cd..0fcb3e4dcf712 100644 --- a/plan/physical_plan_builder.go +++ b/plan/physical_plan_builder.go @@ -852,6 +852,16 @@ func buildIndexScanByKeyAndCorCol(p *DataSource, idx *model.IndexInfo, fakeConds fakeAccessConditions, restFakeConds := detachIndexScanConditions(fakeConds, is) accessConditions := make([]expression.Expression, 0, len(fakeAccessConditions)) restOrigConds := make([]expression.Expression, 0, len(restFakeConds)) + // accessConditions is not in original order. So we could only use brute force there. + for i := 0; i < len(fakeConds); i++ { + for _, cond := range fakeAccessConditions { + if fakeConds[i].Equal(cond, p.ctx) { + accessConditions = append(accessConditions, origConds[i]) + } else { + restOrigConds = append(restOrigConds, origConds[i]) + } + } + } for i, j := 0, 0; i < len(fakeConds); { if j < len(fakeAccessConditions) && fakeConds[i].Equal(fakeAccessConditions[j], p.ctx) { accessConditions = append(accessConditions, origConds[i]) @@ -962,8 +972,12 @@ func (p *Selection) getUsableIndicesAndPk(ds *DataSource) ([]*model.IndexInfo, m for i, col := range ds.Columns { if mysql.HasPriKeyFlag(col.Flag) { pkCol = ds.schema.Columns[i] + break } } + if pkCol == nil { + return usableIdxs, pkName + } checker := conditionChecker{ pkName: pkCol.ColName, length: types.UnspecifiedLength,