DNN-4303 Improve performance of SQL structure and scripts