fix bugs in foreign key constraints
add conditions to filter out bsfilter keys