Add semantic checking to unique constraints in AST

This avoids the unnecessary creation of an additional legacy query tree for every statement.