code: func compilePattern(pattern string, escape byte) (patChars, patTypes []byte) {
  	var lastAny bool
  	patChars = make([]byte, len(pattern))
  	patTypes = make([]byte, len(pattern))
  	patLen := 0
  	for i := 0; i < len(pattern); i++ {
  		var tp byte
  		var c = pattern[i]
  		switch c {
  		case escape:
  			lastAny = false
  			tp = patMatch
  			if i < len(pattern)-1 {
  				i++
  				c = pattern[i]
  				if c == escape || c == '_' || c == '%' {
  					// valid escape.
  				} else {
  					// invalid escape, fall back to escape byte
  					// mysql will treat escape character as the origin value even
  					// the escape sequence is invalid in Go or C.
  					// e.g, \m is invalid in Go, but in MySQL we will get "m" for select '\m'.
  					// Following case is correct just for escape \, not for others like +.
  					// TODO: add more checks for other escapes.
  					i--
  					c = escape
  				}
  			}
  		case '_':
  			lastAny = false
  			tp = patOne
  		case '%':
  			if lastAny {
  				continue
  			}
  			lastAny = true
  			tp = patAny
  		default:
  			lastAny = false
  			tp = patMatch
  		}
  		patChars[patLen] = c
  		patTypes[patLen] = tp
  		patLen++
  	}
  	for i := 0; i < patLen-1; i++ {
  		if (patTypes[i] == patAny) && (patTypes[i+1] == patOne) {
  			patTypes[i] = patOne
  			patTypes[i+1] = patAny
  		}
  	}
  	patChars = patChars[:patLen]
  	patTypes = patTypes[:patLen]
  	return
  }
docs: // Handle escapes and wild cards convert pattern characters and pattern types.