I have a database design which has a separate DB for separate customer data. The database has a Data table which contains right now in one month ~4 million rows.

For queries I create custom views which map a customer id to a specific database. The Views look like this:

```
CREATE ALGORITHM = MERGE VIEW DataView AS

SELECT
  100 AS CustomerID,
  c1db.Data.*
FROM
  Customer100_DB c1db

UNION ALL

SELECT
  101 AS CustomerID,
  c2db.Data.*
FROM
  Customer101_DB c2db;

```

Now my queries generally look like:

```
  SELECT COUNT(*) FROM DataView WHERE CustomerID = ... AND ....;

```

My issue is that the corresponding index in the Data table is not used when querying the view as soon as it contains at least 2 databases.
I.e. when removing the [...]UNION ALL SELECT...[...] from the view it uses the index fine or when querying the Data table directly.
Is there a design issue here or is there any way for me to give the optimizer a better chance to push down the index (using MariaDB 10.3)?