“Hey diddle diddle, the cat and the fiddle” is a very old nursery rhyme -probably from the 16th century. It was first printed in Mother Goose’s Melody, from around 1765, where we find the closest version to the modern one.
The text of this song is more or less nonsense, although there are many approaches for an explanation or an origin.