Wedge formations are a more effective way to attack a square, but not a garauntee of success. It’s bloody difficult to maintain any formation when charging full-bore across uneven ground strewn with debris and bodies living and dead. Even without the effect of casualties during the charge, the riders may not be fully drilled for keeping formation. Quite often they were using replacement horses that had never been in combat, much less a charge. So cavalry tended to arrive as a mass rather than a wedge.
As for lancers, their longer weapons may have been good against rifle/bayonets, but even if each rider nailed the guy he was aiming for, he was still left with up to a dozen more infantry who were aiming just for him. That’s the advantage of high density for the square. Charging cavalry just can’t pack enough guys into the small frontage to kill or even fight every foot soldier. They have to break the square with momentum before they can kill it with weapons. If the foot soldiers are veterans or just plain determined, it’s unlikely that the horses will move them.