Can DBIx:Class optimize a COUNT(*) query and remove JOINs that are not used?

72 views Asked by At

Pagination calls a ->count in DBIx::Class on a relationship that also has JOIN condition.

But the query itself does not use the JOIN condition, however, it is included in the query anyways.

This makes the COUNT(*) query slow.

Is there any way to instruct DBIx::Class to omit unused relationships from the final query?

The query looks like this:

SELECT COUNT(*)
FROM products me
LEFT JOIN models model ON model.id = me.product_model_id
WHERE (me.manufacturer_id = 123)

And I wish it could be reduced to:

SELECT COUNT(*)
FROM products me
WHERE (me.manufacturer_id = 123)
0

There are 0 answers