代码拉取完成,页面将自动刷新
// multi_get.go MultiGetOp 算子——IN 子句多点查优化(OPT-2)
package executor
import (
"fmt"
"gitee.com/bigant/vds/internal/sql/planner"
"gitee.com/bigant/vds/internal/storage/engine"
)
// MultiGetOp 多点查算子:对 WHERE pk IN (v1, v2, ...) 的每个值执行一次 txn.Get()。
type MultiGetOp struct {
txn engine.Transaction
plan *planner.PhysicalMultiGet
results []Row
schema *planner.Schema
pos int
opened bool
}
// NewMultiGetOp 创建 MultiGetOp
func NewMultiGetOp(txn engine.Transaction, plan *planner.PhysicalMultiGet) *MultiGetOp {
return &MultiGetOp{txn: txn, plan: plan, pos: -1}
}
// Open 预取所有行(对每个 key 执行一次 Get)
func (op *MultiGetOp) Open() error {
if op.opened {
return nil
}
op.opened = true
op.results = make([]Row, 0, len(op.plan.Keys))
for _, key := range op.plan.Keys {
val, err := op.txn.Get(key)
if err != nil {
return fmt.Errorf("multi_get: get: %w", err)
}
if val == nil {
continue // key 不存在,跳过
}
op.results = append(op.results, Row{val})
}
op.pos = 0
op.schema = op.plan.OutputCols
return nil
}
// Next 返回下一行
func (op *MultiGetOp) Next() (Row, *planner.Schema, error) {
if op.pos >= len(op.results) {
return nil, nil, nil
}
row := op.results[op.pos]
op.pos++
return row, op.schema, nil
}
// Close 释放资源
func (op *MultiGetOp) Close() error {
op.results = nil
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。