Keep in mind that cavalry was ideally employed in the pursuit, rather than the attack. Thrusting from horseback at a fleeing person is not as hard as it sounds, and even in the attack, 'giving point' was the preferred technique until the melée.
The lance is of course the ultimate pursuit weapon, but is fairly useless in melée, in which case lancers or uhlans dropped their lances and went to swords anyway.
By the time of the minié ball and percussion caps, cavalry charges were obsolete. Infantry no longer needed to form square, just line up and shoot the hell out of the cavalry - clearly demonstrated in the American civil war, although the Germans tried a couple of boot to boot charges in the Franco-Prussian war (e.g. von Bülow death ride) which further demonstrated the futility of cavalry charges in the face of modern weapons.
Going back to the matter of the rapier - it is a rather heavy and slow dueling weapon, and the introduction of the Colischmarche (or Konigsmark) signaled the end for the rapier in favor of what became the smallsword. The rapier's existence owed more to the difficulty in making thin but durable blades given the forging and metallurgy of the time, as well as it's roots in the cruciform swords that proceeded it. As well noted by Ash, all of these weapons were civilian weapons, although smallswords were worn by high ranking military officers beginning in the late 18th century - more as a badge indicating the wearer's status as a gentleman than for any military utility.
The smallsword has evolved into the modern epée.
You may find Burton's 'Book of the sword' helpful in distinguishing patterns. My own expertise is with Napoleonic weapons, but I've been fencing epée of and on for the last 25 years.
Just for reference, here a comparison of the weapons:
Rapier:
Colischmarche
Smallsword