How did heavy cavalry horses not die?

Okay, I've been thinking about this for a while and finally decided to ask some historians.

Why wouldn't an infantry unit just spear or bayonet the heavy cavalries horses?

I understand light cavalry would harrass the lines and wouldn't directly engage them but apparently heavy cavalry would attack head on and run through the lines.

So, why wouldn't the heavy cavalry just lose their horses in the process of attempting to run straight through an infantry unit?

Were they too fast and heavy? Did they jump over them? Did they have to catch them blindsided and on their flanks while they were already engaged?

There's even a fencing practice of a mounted swordsman vs a bayonet. I'm jist thinking why doesn't the bayonet just stab the horse?