1 Star 1 Fork 0

听见安静 / vds

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
multi_get.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
// 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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bigant/vds.git
git@gitee.com:bigant/vds.git
bigant
vds
vds
v1.2.7

搜索帮助