Nonsense Expressions

I always assumed it was from "having a rub down", as in getting a wash, and the "a dub dub" was purely for lyrical goodness.
What surprised me was the umm... bawdy aspect... shall we say. I keep picturing a disreputable fellow in a trenchcoat, looking through the peephole mumbling to himself... rub a dub dub...rub a dub dub. :D

I wonder if that a general trend, nursery rhymes of today being rather cruder originally than the modern versions?
Rubbing is just something you do in a tub. People say "rub-a-dub-dub" to their babies when they wash them. I say it to my dogs. Although they're usually dirty enough that it becomes "scrub-a-dub-dub." It's too perfect of a rhyme to not be used in any poem about a bathtub, whether it's bawdy or innocent. I wouldn't read too much into it.

The fact that the earliest written reference only goes back to the 1300's is no surprise. Printing hadn't even been invented yet and the mass literacy that it engendered was a long way off. Only royal scribes, monks and scholars were writing things down, and they probably didn't devote a lot of their precious time and ink to silly rhymes. :)