Skip to content

[16.0][FIX] pms_l10n_es: INE report, avoid OR subqueries in groups - #471

Merged
OCA-git-bot merged 1 commit into
OCA:16.0from
commitsun:16.0-fix-pms_l10n_es-ine-persons-perf
Nov 2, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:16.0from
commitsun:16.0-fix-pms_l10n_es-ine-persons-perf

Conversation

@DarioLodeiros

Copy link
Copy Markdown
Member

On a large multi-property database the INE report took between 2 and 3.5 minutes per month and hotel. Almost all of that time went into two queries: the occupancy and ADR of the "persons" group.

The "persons" and "others" group domains are an OR between two conditions on the reservation:

"|",
("reservation_id.partner_id", "=", False),
("reservation_id.partner_id.is_company", "=", False),

Each side becomes a reservation_id IN (SELECT ... FROM pms_reservation ...) subquery over the whole reservation table. Under an OR, PostgreSQL cannot turn them into semi-joins. When the subquery result does not fit in work_mem, it materializes it and scans it again for every candidate reservation line. The plan we captured read about 96M shared buffers for ~1,500 lines.

This change classifies the reservations of the property and period once, in Python. The two groups then filter by reservation_id in ids. The semantics are the same: many2one paths already resolve with active_test=False, a missing partner/channel counts as "not company"/"not online", and is_company/is_on_line NULL counts as false.

Same database, one month, three properties:

property before after XML
A 174 s 3.4 s byte-identical
B 229 s 3.8 s byte-identical
C 66 s 3.7 s byte-identical

A test now covers the customer and channel groups (persons, companies, internet, others), which had no coverage.

Not changed here (separate follow-up): ine_calculate_occupancy divides by the INE-room nights of every property, not only the selected one. The percentages are normalized afterwards, so this only affects rounding, but on multi-property databases it costs precision.

@oca-cla-bot

oca-cla-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

The "persons" and "others" group domains were an OR between two
conditions on the reservation. Each side became a subquery over the
whole reservation table, which PostgreSQL cannot plan as a semi-join
under an OR: on a large database the report took minutes.

Classify the reservations of the property and period once in Python
and filter both groups by reservation id. Same semantics: many2one
paths already resolve with active_test=False, and a missing partner or
channel counts as not company / not online.

Add a test for the customer and channel groups of the XML.
@DarioLodeiros
DarioLodeiros force-pushed the 16.0-fix-pms_l10n_es-ine-persons-perf branch from 3227d73 to 83ec9dc Compare November 2, 2026 16:11
@DarioLodeiros

Copy link
Copy Markdown
Member Author

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-471-by-DarioLodeiros-bump-patch, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 3699672 into OCA:16.0 Nov 2, 2026
8 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at d6252a6. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants