WalkSelect walk a select statement filling out plan.
(p *Select)
| 25 | |
| 26 | // WalkSelect walk a select statement filling out plan. |
| 27 | func (m *PlannerDefault) WalkSelect(p *Select) error { |
| 28 | |
| 29 | // u.Debugf("VisitSelect ctx:%p %+v", p.Ctx, p.Stmt) |
| 30 | |
| 31 | needsFinalProject := true |
| 32 | |
| 33 | if len(p.Stmt.From) == 0 { |
| 34 | |
| 35 | return m.WalkLiteralQuery(p) |
| 36 | |
| 37 | } else if len(p.Stmt.From) == 1 { |
| 38 | |
| 39 | p.Stmt.From[0].Source = p.Stmt // TODO: move to a Finalize() in query parser/planner |
| 40 | |
| 41 | srcPlan, err := NewSource(m.Ctx, p.Stmt.From[0], true) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | p.From = append(p.From, srcPlan) |
| 46 | p.Add(srcPlan) |
| 47 | |
| 48 | err = m.Planner.WalkSourceSelect(srcPlan) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | if srcPlan.Complete && !needsFinalProjection(p.Stmt) { |
| 54 | goto finalProjection |
| 55 | } |
| 56 | |
| 57 | } else { |
| 58 | |
| 59 | var prevSource *Source |
| 60 | var prevTask Task |
| 61 | |
| 62 | for i, from := range p.Stmt.From { |
| 63 | |
| 64 | // Need to rewrite the From statement to ensure all fields necessary to support |
| 65 | // joins, wheres, etc exist but is standalone query |
| 66 | from.Rewrite(p.Stmt) |
| 67 | srcPlan, err := NewSource(m.Ctx, from, false) |
| 68 | if err != nil { |
| 69 | return nil |
| 70 | } |
| 71 | err = m.Planner.WalkSourceSelect(srcPlan) |
| 72 | if err != nil { |
| 73 | u.Errorf("Could not visitsubselect %v %s", err, from) |
| 74 | return err |
| 75 | } |
| 76 | |
| 77 | // now fold into previous task |
| 78 | if i != 0 { |
| 79 | from.Seekable = true |
| 80 | // fold this source into previous |
| 81 | curMergeTask := NewJoinMerge(prevTask, srcPlan, prevSource.Stmt, srcPlan.Stmt) |
| 82 | prevTask = curMergeTask |
| 83 | } else { |
| 84 | prevTask = srcPlan |
nothing calls this directly
no test coverage detected