Open StyXman opened 3 weeks ago
Ok, no, in fact the WHERE
s a quite importan (duh; I shouldn't come up with these ideas so late at night). Still, I have the impression there is some rotting on the tunnel and bridges queries, so they could be updated, and that we can do some extra optimization in the railway branch.
Regarding if the queries for the roads, tunnels and bridges layers can be unified - you answered that yourself i think. You don't really want the bridges and tunnels queries to unnecessarily include all the normal roads. Still: The duplication of a lot of code between those layer is annoying. Hence ideas to avoid this are welcome.
Beyond that: There is definitely room for improvement - and if you want to work on that this would be welcome as well. For example the service column could be set to NULL
for railways - and the int_surface
and int_access
columns should IMO be named in the railways queries for better readability.
You mention that
features are cached between layers
that is not true - at least not within Mapnik - PostgreSQL might cache when the same query is run multiple times. The cache-features
parameter applies only when having several styles on the same layer (via attachments in CartoCSS).
You don't really want the bridges and tunnels queries to unnecessarily include all the normal roads
Yeah, I tried converting the bridges and tunnel info into fields and replace the id filters to things like [tunnel = 'yes']
and carto
went from running in ~30s to not finishing after 5m :)
if you want to work on that this would be welcome as well
OK, here's my plan: I'll start introducing one change at a time, get a review, then move to the next one. The question whether you prefer a single final PR or multiple small ones is up to you, but I think several small ones is better.
the service column could be set to
NULL
for railways - and theint_surface
andint_access
columns should IMO be named in the railways queries for better readability
OK, let's make a checklist (they don't quite work, be we'll make them work :):
[ ] Make sure all three have the same code except the WHERE
clauses. Add comments about keeping them in sync.
[ ] NULL AS int_surface
on the railway branch
[ ] NULL AS access
on the railway branch
[ ] NULL AS service
on the railway branch
What about horse
, bicycle
, foot
and tracktype
? Feels like they all could become NULL AS foo
too.
OK, here's my plan: I'll start introducing one change at a time, get a review, then move to the next one. The question whether you prefer a single final PR or multiple small ones is up to you, but I think several small ones is better.
If you just want to do internal changes without a change in rendering, grouping several smaller changes in usually fine. If you want to do larger re-structuring or visible changes it is better not to do too many things at once or to mix structural with simple form changes.
OK, let's make a checklist (they don't quite work, be we'll make them work :):
I copied that to the initial comment so github shows the progress.
What about
horse
,bicycle
,foot
andtracktype
? Feels like they all could becomeNULL AS foo
too.
horse
, bicycle
and foot
are gone since #4952. tracktype
should go completely as well - #4322. :smirk:
Thanks for taking this on - I had also noticed a lot of cruft in the roads queries (e.g. creating an int_surface
for railways!). It would be really good to clean up.
I'm puzzled why the roads queries contain things like 'INT-minor'::text
. The ::text
seems redundant?
Another oddity is why some "null" values are returned as 'null'
rather than simply NULL?
A final oddity is why CASE WHEN feature IN ('highway_motorway_link', 'highway_trunk_link', 'highway_primary_link', 'highway_secondary_link', 'highway_tertiary_link')
is evaluated, when link
has already been evaluated to yes
or no
?
Plenty to go at!
What about 'null' AS surface
in the railway branch? Would NULL
be better?
@imagico can you show me how to do one of those demo data sources?
What about 'null' AS surface in the railway branch? Would NULL be better?
I think yes. Mapnik/Carto handling of NULL values has in the past been somewhat obscure which has probably let to the habit of using 'null' strings. I don't think this is necessary. We don't even have a filter for surface on railways in MSS i think so the value of surface there is simply irrelevant.
@imagico can you show me how to do one of those demo data sources?
You mean the tag combination test sets like here - those are drawn in JOSM and run through osmium renumber
and then imported into a test database.
Mapnik/Carto handling of NULL values has in the past been somewhat obscure
I agree. I think once I tried to come up with what's actually going on there and came up gaslighted by mapnik
. I decided never to look again and do NULL
vs 'null'
incantations until it behaves like I need to. Good to hear if it's more stable now :)
those are drawn in JOSM
Huh... :)
Ok, I started with this. The specific plan is like this: Each change goes in it's own commit, so if a particular thing is not liked it can easily be rolled back. I'll fix the query for roads-casing, and once we're satisfied, I'll copy it over the other 2, leaving the WHERE
clauses intact.
OK, I think this is enough for now. I will also like to add spaces after commas where permitted (not in regexps), to make it more consistent, like in COALESCE(layer,0)
, but I either leave that for the last or I'll do in another PR.
Space after comma is currently not part of our SQL style guide. We mostly have spaces between items in IN(...)
but we mostly do not have spaces between function parameters. Changing that to be fully consistent would mean a lot of changes in project.mml. I am not sure if that is worth the trouble.
In any case - changes to formatting of globally re-used blocks like COALESCE(layer,0)
should not be mixed with changes to individual queries.
OK, so no objections so far. I'll copy the query over the other two and let's see what it gives.
Done, and set to ready for review.
I noticed that the queries for those layers are slightly different, but in my opinion not enough to really have separate definitions. Here is what I found. I'm taking as a base the one that is already used elsewhere,
roads_sql
.Todos (copied from below):
WHERE
clauses. Add comments about keeping them in sync.NULL AS int_surface
on the railway branchNULL AS access
on the railway branchNULL AS service
on the railway branchShort version
Both queries differ only slightly from the roads query. In particular, they differ the same way, except on how they focus on the topic they handle. Even more, I modified my fork of this style to have a single definition for all 4 layers (namely:
tunnels
,roads-casing
,bridges
androads-fill
) and it seems to work just fine. In particular, given how bothtunnels
andbridges
use less sophisticates expression for filtering tunnels and bridges, I have the impression they have suffered from rotting, whereroads_sql
has been improved but the other two hasn't.tunnels
bridges
Proposal
Given that:
I propose to merge all 3 queries into a single query, which should include the simplification in surface handling for the railway branch, and probably similar simplification for other fields that make no sense for those ways.
I think I can provide such a patch without much effort; for the moment I'll keep developing it on my own style.