Query control with a smart database proxy