Mysql – using view (necessary) with where conditions (dynamically)

MySQLmysql-5.5view

Suppose we have two tables like A {a1, a2, a3 …} and B{b1, b2, b3 …}

We are using a MySQl view like

Select a.a1, b.b1 from A a Left JOIN  B b ON a.a2=b.b2 

Now our requirement is that we have to put "where conditions" dynamically on some columns of A and B, so we have to again join table and putting a where condition (In current code).

Now as joining twice is increasing our query execution time and I am trying to reduce the time.

We can't remove the view as per the security requirement (SQL SECURITY).

Is there a way to handle this scenario, I thought of using functions with "SQL SECURITY" or there are any other alternatives.

Best Answer

Try a newer version of MySQL. The view implementation in MySQL-5.5 was very simplistic. I've seen later versions take the view expression into account when doing query planning.