Beispiel #1
0
func (q *qvalue) Format(buf *bytes.Buffer, f parser.FmtFlags) {
	if f == parser.FmtQualify {
		tableAlias := q.colRef.source.findTableAlias(q.colRef.colIdx)
		if tableAlias.TableName != "" {
			if tableAlias.DatabaseName != "" {
				parser.FormatNode(buf, f, tableAlias.DatabaseName)
				buf.WriteByte('.')
			}
			parser.FormatNode(buf, f, tableAlias.TableName)
			buf.WriteByte('.')
		}
	}
	buf.WriteString(q.colRef.get().Name)
}
Beispiel #2
0
func (s *selectNode) ExplainPlan(v bool) (name, description string, children []planNode) {
	subplans := []planNode{s.source.plan}

	subplans = s.planner.collectSubqueryPlans(s.filter, subplans)

	for _, e := range s.render {
		subplans = s.planner.collectSubqueryPlans(e, subplans)
	}

	if len(subplans) == 1 && !v {
		return s.source.plan.ExplainPlan(v)
	}

	var buf bytes.Buffer

	buf.WriteString("from (")
	for i, col := range s.source.info.sourceColumns {
		if i > 0 {
			buf.WriteString(", ")
		}
		if col.hidden {
			buf.WriteByte('*')
		}
		alias := s.source.info.findTableAlias(i)
		parser.FormatNode(&buf, parser.FmtSimple, &alias)
		buf.WriteByte('.')
		parser.FormatNode(&buf, parser.FmtSimple, parser.Name(col.Name))
	}
	buf.WriteByte(')')

	name = "render/filter"
	if s.explain != explainNone {
		name = fmt.Sprintf("%s(%s)", name, explainStrings[s.explain])
	}

	return name, buf.String(), subplans
}