MySQL: How to omit where clause when All is selected for a variable

As the title says; I’m looking for a way to simply omit the relevant part of the where clause whenever All is selected for a variable.

As background, the generated queries become fairly complex with many in() clauses, which eventually runs into performance issues with the query optimizer (specifics).

I understand why this is done (values for a variable can be custom and aren’t necessarily literally all possible values from the table; plus the fact that it’s simply a substitution trick in the query; but this would be a huge performance boost for complex dashboards with many queries.

Has anyone else run into this and found solutions?