Skip to content

fix: make iterate_properties query scale linearly - #203

Merged
pesap merged 2 commits into
NatLabRockies:mainfrom
jennielu92:fix/property-query-scenario-join
Oct 21, 2026
Merged

pesap merged 2 commits into
NatLabRockies:mainfrom
jennielu92:fix/property-query-scenario-join

Conversation

@jennielu92

Copy link
Copy Markdown
Contributor

The property query scanned all of t_data for every membership, because t_data.membership_id had no index, and scanned a materialized scenario CTE for every output row. The CTE repeated each scenario tag once per membership of its Scenario object, so on large models it grew to millions of rows. Both scans made the query quadratic: on a 747 MB Eastern Interconnect XML it ran 13+ hours without finishing.

Add an index on t_data.membership_id, and join scenario tags through the t_tag primary key instead of the CTE. The scenario category filter now reads scenario_category.name. On a NYISO subset (87k data rows) the query went from 50+ minutes to under a second, returning identical rows, including with scenario and scenario-category filters.

The property query scanned all of t_data for every membership, because
t_data.membership_id had no index, and scanned a materialized scenario
CTE for every output row. The CTE repeated each scenario tag once per
membership of its Scenario object, so on large models it grew to millions
of rows. Both scans made the query quadratic: on a 747 MB Eastern
Interconnect XML it ran 13+ hours without finishing.

Add an index on t_data.membership_id, and join scenario tags through the
t_tag primary key instead of the CTE. The scenario category filter now
reads scenario_category.name. On a NYISO subset (87k data rows) the query
went from 50+ minutes to under a second, returning identical rows,
including with scenario and scenario-category filters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the tests label Oct 20, 2026
@pesap
pesap requested a review from mcllerena October 20, 2026 19:23

@mcllerena mcllerena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@pesap
pesap merged commit 1e1c040 into NatLabRockies:main Oct 21, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants