Change ListView SQL query

Hello.

I'm using SugarCRM Community 6.5.22.

In the system I'm operating, there is millions of registers in various modules, slowing down the system to the point of crashing when acessing the modules ListView (mysql process goes to 100% CPU / Memory usage in the server).

So, in the modules ListView, I need to clean the base sql search query to show nothing if there is no search fields filled in.

I tried customizing the Listview sql query (views/view.list.php), putting a "LIMIT 0" in the 'custom_where' parameter, but as the sql query goes through all registers to check if there is something, the slowdown persists.

I searched through the system core code and only found a point where the select query is stored in a php session...

What would be the best way to change the ListView SQL query even before it is processed?

Any help would be appreciated.

Thanks!