It's possible that you have a data integrity problem. Viewing that upgrade script: app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.21-1.4.0.22.php, what it does is add an unique key on the increment_id column. This failing suggests that in one of these tables you have duplicate increment IDs:
'sales/order', 'sales/order_grid', 'sales/creditmemo', 'sales/creditmemo_grid', 'sales/invoice', 'sales/invoice_grid', 'sales/shipment','sales/shipment_grid'
I'd recommend going through and trying to remove items that are duplicates manually. Be sure to take a backup first.
There's a useful post on stackoverflow of someone with a similar experience: https://stackoverflow.com/a/13201613/1960680
... View more