You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[FIX] orm: in recompute_fields, avoid memory error from postgresql
improves 13adede
Queries run through client-side cursors will make postgresql materialze the
whole of the result immediately (which is actually, why `cr.rowcount` is always
available right after `execute` in this case). With server side cursors (named
cursors) on the other hand, tuples are materialized when they are fetched.
This is why running the `query` for ids through the client-side cursor just to
be able to access `cr.rowcount`, can cause an out-of-memory exception from
PostgreSQL.
We fix this by wrapping the query in a `CREATE TABLE AS` statement that inserts
returned ids into a temporary table. We then use a named_cursor to fetch ids
from this table in chunks, server-side.
Another approach would have been to just wrap the query in a `SELECT count(*)`
query and run this once to get the `count`. The approach using `CREATE TABLE
AS` has been chosen over that solution to support queries that include DML
statements (e.g. `UPDATE ... RETURNING`) that affect the results of the
compute, as it allows us to run the query on the main (client) cursor, while
still using a named_cursor for fetching the ids memory-efficiently.
closes#322
Related: odoo/upgrade#8487
Signed-off-by: Christophe Simonis (chs) <chs@odoo.com>
0 commit comments