Users should have the ability to cancel a query on planning or execution stages.
Firstly we should have API to retrieve the identifier of the query and API to cancel a query by the identifier.
For cancel planning see AbstractRelOptPlanner.java:91, here CancelFlag is used to cancel planning loop. We need to pass it into a newly created context and bind its state with PlanningContext#queryCancel to break possible infinite planning loop. See also PlanningContext#unwrap