Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arrivals_departures/connections: move id column into separate view #66

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

derhuerst
Copy link
Member

Currently, queries on arrivals_departures & connections are slow as soon as there are frequencies-based rows in there. This is because the frequencies_it – which is needed for arrival_departure_id/connection_id – calculation uses a row_number() over a PARTITION BY.

This PR

  • moves these expensive columns into separate views arrivals_departures_with_ids/connections_with_ids;
  • adapts arrival_departure_by_arrival_departure_id/connection_by_connection_id to use the new views;
  • adds benchmarking for the case described above.

derhuerst and others added 4 commits November 2, 2024 16:42
For the ID, we use frequencies_it, which we compute using a PARTITION BY. Because the latter is prohibitively slow, we move the entire computation into a separate view.

Co-Authored-By: Holger Bruch <[email protected]>
@derhuerst derhuerst added the breaking breaking change label Nov 4, 2024
Copy link
Member Author

@derhuerst derhuerst left a comment

Choose a reason for hiding this comment

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

Currently, this still causes different sets of arrivals/departures for the (functionally) same query.

git checkout main
# import data...
psql -c 'SELECT route_id, route_short_name, trip_id, trip_headsign, frequencies_it, stop_sequence_consec, t_arrival, t_departure, stop_id, stop_name, station_id FROM arrivals_departures WHERE trip_id = \'171756466\' AND date = \'2022-08-23\' AND t_departure >= \'2022-08-23T06:10+01:00\' AND t_departure <= \'2022-08-23T06:24+01:00\' ORDER BY route_id, trip_id, date, frequencies_it, stop_sequence_consec' | sponge before
git checkout arrs-deps-cons-ids
# import data...
psql -c 'SELECT route_id, route_short_name, trip_id, trip_headsign, frequencies_it, stop_sequence_consec, t_arrival, t_departure, stop_id, stop_name, station_id FROM arrivals_departures_with_ids WHERE trip_id = \'171756466\' AND date = \'2022-08-23\' AND t_departure >= \'2022-08-23T06:10+01:00\' AND t_departure <= \'2022-08-23T06:24+01:00\' ORDER BY route_id, trip_id, date, frequencies_it, stop_sequence_consec' | sponge after
diff before after

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

Successfully merging this pull request may close these issues.

1 participant