本文整理汇总了Golang中github.com/pingcap/tidb/xapi.Select函数的典型用法代码示例。如果您正苦于以下问题:Golang Select函数的具体用法?Golang Select怎么用?Golang Select使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Select函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: doIndexRequest
func (e *XSelectIndexExec) doIndexRequest() (*xapi.SelectResult, error) {
txn, err := e.ctx.GetTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
selIdxReq := new(tipb.SelectRequest)
startTs := txn.StartTS()
selIdxReq.StartTs = &startTs
selIdxReq.IndexInfo = xapi.IndexToProto(e.table.Meta(), e.indexPlan.Index)
if len(e.indexPlan.FilterConditions) == 0 {
// Push limit to index request only if there is not filter conditions.
selIdxReq.Limit = e.indexPlan.LimitCount
}
if e.indexPlan.Desc {
selIdxReq.OrderBy = append(selIdxReq.OrderBy, &tipb.ByItem{Desc: &e.indexPlan.Desc})
}
fieldTypes := make([]*types.FieldType, len(e.indexPlan.Index.Columns))
for i, v := range e.indexPlan.Index.Columns {
fieldTypes[i] = &(e.table.Cols()[v.Offset].FieldType)
}
selIdxReq.Ranges, err = indexRangesToPBRanges(e.indexPlan.Ranges, fieldTypes)
if err != nil {
return nil, errors.Trace(err)
}
concurrency := 1
if e.indexPlan.OutOfOrder {
concurrency = 10
}
return xapi.Select(txn.GetClient(), selIdxReq, concurrency)
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:30,代码来源:executor_xapi.go
示例2: doRequest
func (e *NewXSelectTableExec) 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.Where = e.where
selReq.Ranges = tableRangesToPBRanges(e.ranges)
columns := e.Columns
selReq.TableInfo = &tipb.TableInfo{
TableId: proto.Int64(e.tableInfo.ID),
}
if e.supportDesc && e.desc {
selReq.OrderBy = append(selReq.OrderBy, &tipb.ByItem{Desc: &e.desc})
}
selReq.Limit = e.limitCount
selReq.TableInfo.Columns = xapi.ColumnsToProto(columns, e.tableInfo.PKIsHandle)
// Aggregate Info
selReq.Aggregates = e.aggFuncs
selReq.GroupBy = e.byItems
e.result, err = xapi.Select(txn.GetClient(), selReq, defaultConcurrency)
if err != nil {
return errors.Trace(err)
}
//if len(selReq.Aggregates) > 0 || len(selReq.GroupBy) > 0 {
if e.aggregate {
// The returned rows should be aggregate partial result.
e.result.SetFields(e.aggFields)
}
return nil
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:33,代码来源:new_executor_xapi.go
示例3: doTableRequest
func (e *NewXSelectIndexExec) doTableRequest(handles []int64) (*xapi.SelectResult, error) {
txn, err := e.ctx.GetTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
// The handles are not in original index order, so we can't push limit here.
selTableReq := new(tipb.SelectRequest)
startTs := txn.StartTS()
selTableReq.StartTs = &startTs
selTableReq.TableInfo = &tipb.TableInfo{
TableId: proto.Int64(e.table.Meta().ID),
}
selTableReq.TableInfo.Columns = xapi.ColumnsToProto(e.indexPlan.Columns, e.table.Meta().PKIsHandle)
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 = kv.Key(pbRange.Low).PrefixNext()
selTableReq.Ranges = append(selTableReq.Ranges, pbRange)
}
selTableReq.Where = e.where
// Aggregate Info
resp, err := xapi.Select(txn.GetClient(), selTableReq, defaultConcurrency)
if err != nil {
return nil, errors.Trace(err)
}
return resp, nil
}
开发者ID:yubobo,项目名称:tidb,代码行数:31,代码来源:new_executor_xapi.go
示例4: doIndexRequest
func (e *XSelectIndexExec) doIndexRequest() (xapi.SelectResult, error) {
selIdxReq := new(tipb.SelectRequest)
selIdxReq.StartTs = e.txn.StartTS()
selIdxReq.IndexInfo = xapi.IndexToProto(e.table.Meta(), e.indexPlan.Index)
if e.indexPlan.Desc {
selIdxReq.OrderBy = append(selIdxReq.OrderBy, &tipb.ByItem{Desc: e.indexPlan.Desc})
}
fieldTypes := make([]*types.FieldType, len(e.indexPlan.Index.Columns))
for i, v := range e.indexPlan.Index.Columns {
fieldTypes[i] = &(e.table.Cols()[v.Offset].FieldType)
}
if !e.indexPlan.DoubleRead || e.where == nil {
// TODO: when where condition is all index columns limit can be pushed too.
selIdxReq.Limit = e.indexPlan.LimitCount
}
concurrency := 1
if !e.indexPlan.DoubleRead {
concurrency = defaultConcurrency
selIdxReq.Aggregates = e.aggFuncs
selIdxReq.GroupBy = e.byItems
selIdxReq.Where = e.where
} else if e.indexPlan.OutOfOrder {
concurrency = defaultConcurrency
}
keyRanges, err := indexRangesToKVRanges(e.table.Meta().ID, e.indexPlan.Index.ID, e.indexPlan.Ranges, fieldTypes)
if err != nil {
return nil, errors.Trace(err)
}
return xapi.Select(e.txn.GetClient(), selIdxReq, keyRanges, concurrency, !e.indexPlan.OutOfOrder)
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:30,代码来源:executor_xapi.go
示例5: doRequest
func (e *XSelectTableExec) doRequest() error {
var err error
selReq := new(tipb.SelectRequest)
selReq.StartTs = e.txn.StartTS()
selReq.Where = e.where
columns := e.Columns
selReq.TableInfo = &tipb.TableInfo{
TableId: e.tableInfo.ID,
}
if e.supportDesc && e.desc {
selReq.OrderBy = append(selReq.OrderBy, &tipb.ByItem{Desc: e.desc})
}
selReq.Limit = e.limitCount
selReq.TableInfo.Columns = xapi.ColumnsToProto(columns, e.tableInfo.PKIsHandle)
// Aggregate Info
selReq.Aggregates = e.aggFuncs
selReq.GroupBy = e.byItems
kvRanges := tableRangesToKVRanges(e.table.Meta().ID, e.ranges)
e.result, err = xapi.Select(e.txn.GetClient(), selReq, kvRanges, defaultConcurrency, e.keepOrder)
if err != nil {
return errors.Trace(err)
}
//if len(selReq.Aggregates) > 0 || len(selReq.GroupBy) > 0 {
if e.aggregate {
// The returned rows should be aggregate partial result.
e.result.SetFields(e.aggFields)
}
e.result.Fetch()
return nil
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:31,代码来源:executor_xapi.go
示例6: doTableRequest
func (e *XSelectIndexExec) doTableRequest(handles []int64) (xapi.SelectResult, error) {
// The handles are not in original index order, so we can't push limit here.
selTableReq := new(tipb.SelectRequest)
if e.indexPlan.OutOfOrder {
selTableReq.Limit = e.indexPlan.LimitCount
}
selTableReq.StartTs = e.txn.StartTS()
selTableReq.TableInfo = &tipb.TableInfo{
TableId: e.table.Meta().ID,
}
selTableReq.TableInfo.Columns = xapi.ColumnsToProto(e.indexPlan.Columns, e.table.Meta().PKIsHandle)
selTableReq.Where = e.where
// Aggregate Info
selTableReq.Aggregates = e.aggFuncs
selTableReq.GroupBy = e.byItems
keyRanges := tableHandlesToKVRanges(e.table.Meta().ID, handles)
resp, err := xapi.Select(e.txn.GetClient(), selTableReq, keyRanges, defaultConcurrency, false)
if err != nil {
return nil, errors.Trace(err)
}
if e.aggregate {
// The returned rows should be aggregate partial result.
resp.SetFields(e.aggFields)
}
resp.Fetch()
return resp, nil
}
开发者ID:yangxuanjia,项目名称:tidb,代码行数:27,代码来源:executor_xapi.go
示例7: doTableRequest
func (e *NewXSelectIndexExec) doTableRequest(handles []int64) (xapi.SelectResult, error) {
// The handles are not in original index order, so we can't push limit here.
selTableReq := new(tipb.SelectRequest)
selTableReq.StartTs = e.txn.StartTS()
selTableReq.TableInfo = &tipb.TableInfo{
TableId: e.table.Meta().ID,
}
selTableReq.TableInfo.Columns = xapi.ColumnsToProto(e.indexPlan.Columns, e.table.Meta().PKIsHandle)
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 = kv.Key(pbRange.Low).PrefixNext()
selTableReq.Ranges = append(selTableReq.Ranges, pbRange)
}
selTableReq.Where = e.where
// Aggregate Info
selTableReq.Aggregates = e.aggFuncs
selTableReq.GroupBy = e.byItems
// Aggregate Info
resp, err := xapi.Select(e.txn.GetClient(), selTableReq, defaultConcurrency, false)
if err != nil {
return nil, errors.Trace(err)
}
if e.aggregate {
// The returned rows should be aggregate partial result.
resp.SetFields(e.aggFields)
}
resp.Fetch()
return resp, nil
}
开发者ID:c4pt0r,项目名称:tidb,代码行数:34,代码来源:new_executor_xapi.go
示例8: doIndexRequest
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)
}
开发者ID:astaxie,项目名称:tidb,代码行数:12,代码来源:executor_xapi.go
示例9: doRequest
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
}
开发者ID:astaxie,项目名称:tidb,代码行数:18,代码来源:executor_xapi.go
示例10: doTableRequest
func (e *XSelectIndexExec) doTableRequest(handles []int64) (*xapi.SelectResult, error) {
txn, err := e.ctx.GetTxn(false)
if err != nil {
return nil, errors.Trace(err)
}
// The handles are not in original index order, so we can't push limit here.
selTableReq := new(tipb.SelectRequest)
startTs := txn.StartTS()
selTableReq.StartTs = &startTs
columns := make([]*model.ColumnInfo, 0, len(e.indexPlan.Fields()))
for _, v := range e.indexPlan.Fields() {
if v.Referenced {
columns = append(columns, v.Column)
}
}
selTableReq.TableInfo = &tipb.TableInfo{
TableId: proto.Int64(e.table.Meta().ID),
}
selTableReq.TableInfo.Columns = xapi.ColumnsToProto(columns, e.table.Meta().PKIsHandle)
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 = kv.Key(pbRange.Low).PrefixNext()
selTableReq.Ranges = append(selTableReq.Ranges, pbRange)
}
selTableReq.Where = e.where
// Aggregate Info
selTableReq.Aggregates = e.aggFuncs
selTableReq.GroupBy = e.byItems
resp, err := xapi.Select(txn.GetClient(), selTableReq, defaultConcurrency)
if err != nil {
return nil, errors.Trace(err)
}
if e.aggregate {
// The returned rows should be aggregate partial result.
resp.SetFields(e.aggFields)
}
return resp, nil
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:44,代码来源:executor_xapi.go
示例11: doRequest
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 = e.where
selReq.Ranges = tableRangesToPBRanges(e.tablePlan.Ranges)
if e.supportDesc {
if e.tablePlan.Desc {
selReq.OrderBy = append(selReq.OrderBy, &tipb.ByItem{Desc: &e.tablePlan.Desc})
}
// Limit can be pushed only if desc is supported.
if e.allFiltersPushed {
selReq.Limit = e.tablePlan.LimitCount
}
}
columns := make([]*model.ColumnInfo, 0, len(e.tablePlan.Fields()))
for _, v := range e.tablePlan.Fields() {
if v.Referenced {
columns = append(columns, v.Column)
}
}
selReq.TableInfo = &tipb.TableInfo{
TableId: proto.Int64(e.table.Meta().ID),
}
selReq.TableInfo.Columns = xapi.ColumnsToProto(columns, e.table.Meta().PKIsHandle)
// Aggregate Info
selReq.Aggregates = e.aggFuncs
selReq.GroupBy = e.byItems
e.result, err = xapi.Select(txn.GetClient(), selReq, defaultConcurrency)
if err != nil {
return errors.Trace(err)
}
if len(selReq.Aggregates) > 0 || len(selReq.GroupBy) > 0 {
// The returned rows should be aggregate partial result.
e.result.SetFields(e.aggFields)
}
return nil
}
开发者ID:duzhanyuan,项目名称:tidb,代码行数:43,代码来源:executor_xapi.go
示例12: doTableRequest
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)
}
开发者ID:astaxie,项目名称:tidb,代码行数:19,代码来源:executor_xapi.go
示例13: doRequest
func (e *NewTableScanExec) 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.Where = e.where
selReq.Ranges = tableRangesToPBRanges(e.ranges)
columns := e.Columns
selReq.TableInfo = &tipb.TableInfo{
TableId: proto.Int64(e.tableInfo.ID),
}
selReq.TableInfo.Columns = tablecodec.ColumnsToProto(columns, e.tableInfo.PKIsHandle)
e.result, err = xapi.Select(txn.GetClient(), selReq, defaultConcurrency)
if err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:anywhy,项目名称:tidb,代码行数:21,代码来源:new_executor.go
注:本文中的github.com/pingcap/tidb/xapi.Select函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论