Reconfigured SQL query process