{//最简单、原始的、可能的查询计划 public Plan createPlan(QueryData data, Transaction tx) { //第一步:为每一个出现的表或者视图定义创建一个plan List <Plan> plans = new List <Plan>(); foreach (string tblname in data.tables()) { string viewdef = SimpleDB.mdMgr().getViewDef(tblname, tx); if (viewdef != null) { plans.Add(SimpleDB.planner().createQueryPlan(viewdef, tx)); } else { plans.Add(new TablePlan(tblname, tx)); } } //第二步:创建所有表计划的叉积运算 Plan p = plans[0]; plans.RemoveAt(0); foreach (Plan nextplan in plans) { p = new ProductPlan(p, nextplan); } //第三步:为predicate添加一个选择运算selection p = new SelectPlan(p, data.pred()); //第四步:做字段名称上的投影运算 p = new ProjectPlan(p, data.fields()); return(p); }
public int executeDelete(DeleteData data, Transaction tx) { Plan p = new TablePlan(data.tableName(), tx); p = new SelectPlan(p, data.pred()); UpdateScan us = (UpdateScan)p.open(); int count = 0; while (us.next()) { us.delete(); count++; } us.close(); return(count); }
public int executeModify(ModifyData data, Transaction tx) { Plan p = new TablePlan(data.tableName(), tx); p = new SelectPlan(p, data.pred()); UpdateScan us = (UpdateScan)p.open(); int count = 0; while (us.next()) { Constant val = data.newValue().evaluate(us); //返回此处的表达式的常量值 us.setVal(data.targetField(), val); //设置要更改字段处的值 count++; } us.close(); return(count); }