1. A method for applying a query to an event stream, comprising: storing one or more event constraints specifying a predetermined order or occurrence of events in a stream of events ordered by timestamps, wherein the event constraints represent prior knowledge to discern event patterns that can appear in the event stream from patterns that cannot appear in the event stream; generating a query with one or more correlation rules representing one or more event patterns to be detected in the event stream; analyzing the query for query unsatisfiability using the event constraints and predicting whether upcoming events satisfy the constraints in the query; performing constraint aware complex event processing on the query and the event constraints by determining whether the event stream corresponds to the correlation rules in the query; and optimizing the query by detecting and terminating an unsatisfiable query as early as possible using the query and the event constraints, where the event stream can be partitioned into multiple sub-sequences based on a predetermined criteria, each partition of the event stream comprising a trace, and where for a query Q, event constraints C and a partial trace h p , Q is said to be runtime unsatisfiable if there does not exist a trace h e that is consistent with C and contains a match to Q, where h p is prefix of h e where event data becomes available in order of occurrences and the partial trace h p is the prefix of the trace h e and wherein the trace comprises sub-sequences of the stream of events (event history) and wherein the query Q is runtime unsatisfiable if there does not exist a remaining trace h p =h e −h p that contains a match to a remaining query.