1. A computer-implemented method comprising: accessing a program with one or more queries to a database that contains relations described by at least one database schema; receiving the database schema and at least one entity type hierarchy for the database; and inferring a first type program from definitions in the program by replacing each use of a database relation in the program by its type in the database schema, and the type is at least portion of a second type program, wherein each of the first type program and the second type program is a derived program using type symbols without other extensional relation symbols, and each of the first type program and the second type program do not contain negation, wherein the first type program and the second type program uses monadic extensions; testing portion of the first type program that has been inferred for type emptiness and type inclusion; and providing at least one of error information and optimization information regarding the type emptiness and type inclusion being found for the type.