func (s *selectStmt) explain(ctx *execCtx, w strutil.Formatter) { p, err := s.plan(ctx) if err != nil { w.Format("ERROR: %v\n", err) return } p.explain(w) }
func prettyPrint0(protect map[interface{}]struct{}, sf strutil.Formatter, prefix, suffix string, v interface{}) { if v == nil { return } switch x := v.(type) { case *Token: if x == nil { return } sf.Format("%s%v"+suffix, prefix, x.String()) return } rt := reflect.TypeOf(v) rv := reflect.ValueOf(v) switch rt.Kind() { case reflect.Slice: if rv.Len() == 0 { return } sf.Format("%s[]%T{ // len %d%i\n", prefix, rv.Index(0).Interface(), rv.Len()) for i := 0; i < rv.Len(); i++ { prettyPrint0(protect, sf, fmt.Sprintf("%d: ", i), ",\n", rv.Index(i).Interface()) } sf.Format("%u}" + suffix) case reflect.Struct: sf.Format("%s%T{%i\n", prefix, v) for i := 0; i < rt.NumField(); i++ { f := rv.Field(i) if !f.CanInterface() { continue } prettyPrint0(protect, sf, fmt.Sprintf("%s: ", rt.Field(i).Name), ",\n", f.Interface()) } sf.Format("%u}" + suffix) case reflect.Ptr: if rv.IsNil() { return } rvi := rv.Interface() if _, ok := protect[rvi]; ok { sf.Format("%s&%T{ /* recursive/repetitive pointee not shown */ }"+suffix, prefix, rv.Elem().Interface()) return } if protect == nil { protect = map[interface{}]struct{}{} } protect[rvi] = struct{}{} prettyPrint0(protect, sf, prefix+"&", suffix, rv.Elem().Interface()) case reflect.Int, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int8: if v := rv.Int(); v != 0 { sf.Format("%s%v"+suffix, prefix, v) } case reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint8: if v := rv.Uint(); v != 0 { sf.Format("%s%v"+suffix, prefix, rv.Uint()) } case reflect.Bool: if v := rv.Bool(); v { sf.Format("%s%v"+suffix, prefix, rv.Bool()) } case reflect.String: s := rv.Interface().(string) if s == "" { return } sf.Format("%s%q"+suffix, prefix, s) case reflect.Map: keys := rv.MapKeys() if len(keys) == 0 { return } var buf bytes.Buffer nf := strutil.IndentFormatter(&buf, "· ") var skeys []string for i, k := range keys { prettyPrint0(protect, nf, "", "", k.Interface()) skeys = append(skeys, fmt.Sprintf("%s%10d", buf.Bytes(), i)) } sort.Strings(skeys) sf.Format("%s%T{%i\n", prefix, v) for _, k := range skeys { si := strings.TrimSpace(k[len(k)-10:]) k = k[:len(k)-10] n, _ := strconv.ParseUint(si, 10, 64) mv := rv.MapIndex(keys[n]) prettyPrint0(protect, sf, fmt.Sprintf("%s: ", k), ",\n", mv.Interface()) } sf.Format("%u}" + suffix) default: panic(fmt.Sprintf("prettyPrint: missing support for reflect.Kind == %v", rt.Kind())) } }
func (s *insertIntoStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s *dropTableStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s *alterTableAddStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s *updateStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s *createIndexStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s rollbackStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s commitStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }
func (s beginTransactionStmt) explain(ctx *execCtx, w strutil.Formatter) { w.Format("%s\n", s) }