Example #1
0
func (rs *localRegion) getRowsFromSelectReq(ctx *selectContext) error {
	// Init ctx.colTps and use it to decode all the rows.
	columns := ctx.sel.TableInfo.Columns
	ctx.colTps = make(map[int64]*types.FieldType, len(columns))
	for _, col := range columns {
		if col.GetPkHandle() {
			continue
		}
		ctx.colTps[col.GetColumnId()] = distsql.FieldTypeFromPBColumn(col)
	}

	kvRanges := rs.extractKVRanges(ctx)
	limit := int64(-1)
	if ctx.sel.Limit != nil {
		limit = ctx.sel.GetLimit()
	}
	for _, ran := range kvRanges {
		if limit == 0 {
			break
		}
		count, err := rs.getRowsFromRange(ctx, ran, limit, ctx.descScan)
		if err != nil {
			return errors.Trace(err)
		}
		limit -= count
	}
	if ctx.aggregate {
		return rs.getRowsFromAgg(ctx)
	}
	return nil
}
Example #2
0
func (h *rpcHandler) getChunksFromSelectReq(ctx *selectContext) ([]tipb.Chunk, error) {
	// Init ctx.colTps and use it to decode all the rows.
	columns := ctx.sel.TableInfo.Columns
	ctx.colTps = make(map[int64]*types.FieldType, len(columns))
	for _, col := range columns {
		if col.GetPkHandle() {
			continue
		}
		ctx.colTps[col.GetColumnId()] = distsql.FieldTypeFromPBColumn(col)
	}

	kvRanges, desc := h.extractKVRanges(ctx)
	limit := int64(-1)
	if ctx.sel.Limit != nil {
		limit = ctx.sel.GetLimit()
	}

	var chunks []tipb.Chunk
	var err error
	for _, ran := range kvRanges {
		if limit == 0 {
			break
		}
		chunks, err = h.getRowsFromRange(ctx, ran, &limit, desc, chunks)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}
	if ctx.aggregate {
		return h.getRowsFromAgg(ctx)
	}
	return chunks, nil
}
Example #3
0
// Put column values into ctx, the values will be used for expr evaluation.
func (rs *localRegion) setColumnValueToCtx(ctx *selectContext, h int64, row map[int64][]byte, cols map[int64]*tipb.ColumnInfo) error {
	for colID, col := range cols {
		if col.GetPkHandle() {
			if mysql.HasUnsignedFlag(uint(col.GetFlag())) {
				ctx.eval.Row[colID] = types.NewUintDatum(uint64(h))
			} else {
				ctx.eval.Row[colID] = types.NewIntDatum(h)
			}
		} else {
			data := row[colID]
			ft := distsql.FieldTypeFromPBColumn(col)
			datum, err := tablecodec.DecodeColumnValue(data, ft)
			if err != nil {
				return errors.Trace(err)
			}
			ctx.eval.Row[colID] = datum
		}
	}
	return nil
}