FoundationDB/sql-layer — pull request #1271 by nathanlws (2014-05-01 17:54:56+00:00)
Title: Fix ALTER ADD FOREIGN KEY when rows already exist

There are three distinct but tightly related pieces:

ALTER ADD FOREIGN KEY did not result in existing rows being checked. OnlineHelper needed to be aware of ConstraintHandler, in addition to ConstraintChecked.

ConstraintChecker and ConstraintHandler don't both need to exist. These handled NOT NULL and FOREIGN KEY, respectively. Add NotNullHandler in ConstraintHandler to eliminate the checker. The other constraint types (UNIQUE, PRIMARY) are still handled specially elsewhere.

TableChangeValidator was not updated when foreign keys were added. Add an FK pass with corresponding new change levels.

The current ALTER flow is showing quite a bit of brittleness, particularly in how information is, and more importantly isn't, propagated through the various layers. For example, exact constraints that were added are not stored. Checking all constraints when adding a new one wasn't a big deal when NOT NULL was the only one but the cumulative cost of multiple foreign keys (on a single table) certainly is. Needs some though and design before tackling.