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
Remove useless WHERE clauses from the transportation layer #1168
Remove useless WHERE clauses from the transportation layer #1168
Conversation
Results evaluating commit 64fb44b (merged with base 893d1df as ec58152). See run details. PostgreSQL DB size in MB: 2793 ⇒ 2793 (0.0% change)
expand for details...
|
i'm all for optimizations like this. One thing we should definitely do is record intentions/assumptions as comments - so perhaps it would be good to add these where clauses as a comment, either verbatim, as a WHERE clause with a comment that these are already implemented somewhere else, or as text specifying what each SQL statement assumes |
Good idea. I just added comments to document the implicit WHERE clauses. |
Thanks! It looks much cleaner! |
PR #1168 removed several `WHERE` clauses in the `transportation_merge_*` table series. With those removed, it appears that `osm_transportation_merge_linestring_gen_z8` and `osm_transportation_merge_linestring` are nearly identical, with the former simply adding an `ST_Simplify()` operation. A grep of the codebase indicates that the _only_ use for `osm_transportation_merge_linestring` is to hold the intermediate result of an `ST_Dump(geometry))` before it is fed into `ST_Simplify()`. Therefore, it appears that we're holding an entire zoom 8 copy of the transportation layer (all motorway/trunk/primary roads) in a materialized view for absolutely no reason at all. This PR removes the `osm_transportation_merge_linestring` intermediate table and changes the definition of `osm_transportation_merge_linestring_gen_z8` to perform the `ST_Dump()` and `ST_Simplify()` transformations directly from the `osm_highway_linestring` table in a single operation.
This PR removes several redundant/unnecessary WHERE clauses from the transportation layer. Specifically:
The table
osm_transportation_merge_linestring
is a view ofosm_highway_linestring
which exposes only motorway/trunk/primary roads:openmaptiles/layers/transportation/update_transportation_merge.sql
Lines 122 to 123 in 9e4be3e
However, the create statement for the table
osm_transportation_merge_linestring_gen_z8
, which is a view ofosm_transportation_merge_linestring
, also contains aWHERE
clause which selects down to motorway/trunk/primary roads. ThisWHERE
is unnecessary:openmaptiles/layers/transportation/update_transportation_merge.sql
Lines 144 to 145 in 9e4be3e
This unneeded
WHERE
clause is similarly present in the create statement forosm_transportation_merge_linestring_gen_z7
, which is a view ofosm_transportation_merge_linestring_gen_z8
:openmaptiles/layers/transportation/update_transportation_merge.sql
Lines 163 to 164 in 9e4be3e
Likewise, there is a similar redundant
WHERE
clause in theosm_transportation_merge_linestring_gen_z5
andosm_transportation_merge_linestring_gen_z6
tables, both of which select down tomotorway
andtrunk
. ThisWHERE
clause is only needed on the z6 table, and is redundant on the z5 table.I am not sure what the performance penalty is for these redundant
WHERE
clauses, but there does not appear to be any reason to keep them, and they may incur a performance cost.