Added in-memory sorting to foreignkey.go