Bad performance when computing deletable and writable state
Since #9357 (closed) we compute a _write
and _delete
value based on ir.rule
by adding a SQL expression as SELECT expression.
This is killing performance when the ir.rule
comes from __access__
because it uses a where
operator which is converted into a IN
subquery. So the database can not really optimize, especially when the target table is very large because it need to retrieve all the target record ids for which the user has access.
So for example with the account.move.line
, we got a subquery expression like:
(("a"."move" IN (SELECT "b"."id" AS "id" FROM "account_move" AS "b" WHERE (("b"."company" IN (1)))))) AS "_delete"
So it needs to materialize a table with all the moves of the company (which can be very large).
I do not see how we could rewrite the query to be more efficient.
But we can optimize for the case where the rule for write and delete are the same as the rule for read. In this case we know the expressions for _delete
and _write
are True
for all readable records.