func (e *XSelectIndexExec) doIndexRequest(txn kv.Transaction) (*xapi.SelectResult, error) { selIdxReq := new(tipb.SelectRequest) startTs := txn.StartTS() selIdxReq.StartTs = &startTs selIdxReq.IndexInfo = tablecodec.IndexToProto(e.table.Meta(), e.indexPlan.Index) var err error selIdxReq.Ranges, err = indexRangesToPBRanges(e.indexPlan.Ranges) if err != nil { return nil, errors.Trace(err) } return xapi.Select(txn.GetClient(), selIdxReq, 1) }
// Convert tipb.Request to kv.Request. func composeRequest(req *tipb.SelectRequest, concurrency int) (*kv.Request, error) { kvReq := &kv.Request{ Concurrency: concurrency, } if req.IndexInfo != nil { kvReq.Tp = kv.ReqTypeIndex tid := req.IndexInfo.GetTableId() kvReq.KeyRanges = tablecodec.EncodeIndexRanges(tid, req.Ranges) } else { kvReq.Tp = kv.ReqTypeSelect tid := req.GetTableInfo().GetTableId() kvReq.KeyRanges = tablecodec.EncodeTableRanges(tid, req.Ranges) } var err error kvReq.Data, err = proto.Marshal(req) if err != nil { return nil, errors.Trace(err) } return kvReq, nil }
func (e *XSelectTableExec) doRequest() error { txn, err := e.ctx.GetTxn(false) if err != nil { return errors.Trace(err) } selReq := new(tipb.SelectRequest) startTs := txn.StartTS() selReq.StartTs = &startTs selReq.Fields = resultFieldsToPBExpression(e.tablePlan.Fields()) selReq.Where = conditionsToPBExpression(e.tablePlan.FilterConditions...) selReq.Ranges = tableRangesToPBRanges(e.tablePlan.Ranges) selReq.TableInfo = tablecodec.TableToProto(e.tablePlan.Table) e.result, err = xapi.Select(txn.GetClient(), selReq, 1) if err != nil { return errors.Trace(err) } return nil }
func (e *XSelectIndexExec) doTableRequest(txn kv.Transaction, handles []int64) (*xapi.SelectResult, error) { selTableReq := new(tipb.SelectRequest) startTs := txn.StartTS() selTableReq.StartTs = &startTs selTableReq.TableInfo = tablecodec.TableToProto(e.indexPlan.Table) selTableReq.Fields = resultFieldsToPBExpression(e.indexPlan.Fields()) for _, h := range handles { if h == math.MaxInt64 { // We can't convert MaxInt64 into an left closed, right open range. continue } pbRange := new(tipb.KeyRange) pbRange.Low = codec.EncodeInt(nil, h) pbRange.High = codec.EncodeInt(nil, h) selTableReq.Ranges = append(selTableReq.Ranges, pbRange) } selTableReq.Where = conditionsToPBExpression(e.indexPlan.FilterConditions...) return xapi.Select(txn.GetClient(), selTableReq, 10) }