A while back I ripped a regex out of my SQL parser and replaced it with twenty lines of hand-written string scanning. Then I got nervous. Hand-rolling a scanner because you assume regex is slow is exactly the kind of premature optimization I make fun of other people for. So I filed an issue against myself: prove the hand-rolled version is actually faster, or delete it and go back to the regex.
Months later I sat down to settle it. The honest regex came back about ninety times slower. And the reason had nothing to do with raw matching speed.
What the code does
The function answers one small question: does a specific table alias appear in this piece of SQL, followed by a dot? That's how the parser notices a subquery reaching out to an outer table, like o.id pointing at an orders o defined outside it.
func containsWordDot(text, word string) bool {
if word == "" {
return false
}
needle := word + "."
idx := 0
for {
pos := strings.Index(tex
Discussion
Break the silence
Take the opportunity to kick things off.