refactor viableBusStops query #372
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The viableBusStops query as it is generates about 6000 table/index scans (mainly on vehicle, availability, and tour) for a single query like Schleife - Dresden. This refactored version only a couple dozen, but maybe it's just hidden by the materialized CTE (which is materialized only to enforce the join order). It's also not faster (but also, for the queries I tested, not slower). While I think that the results should be equivalent, more testing would be needed for that I guess. So not sure if it even makes sense to merge this, or whether we wait how the system behaves when the tables grow.
The number of parameters for the prepared statement could become another issue, the limit is 2^15 (32k), and we're occasionally passing 10k...