-
Notifications
You must be signed in to change notification settings - Fork 821
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
Rewrite SQL queries so the COALESCE part works correctly #1038
Rewrite SQL queries so the COALESCE part works correctly #1038
Conversation
matthijsmelissen
commented
Oct 10, 2014
- Resolves shop=no shouldn't get rendered #985
- Resolves tourism=attraction not rendered when object also has unrendered amenity tag #1029
* Resolves gravitystorm#985 * Resolves gravitystorm#1029
@pnorman You mentioned:
Is this what you had in mind? I can't say it really simplifies the SQL... What do you think? |
I said this in #942 (comment), which isn't one of these issues. In that case, I was going to move the I am quite skeptical about the SQL changes - it removes the WHERE conditions on the columns and replaces them with a In some ways, this is clearer (SELECT
way, name, religion,
COALESCE(A, B, C) AS feature
FROM
(SELECT
way, z_order, way_area, name,
('A_' || (CASE WHEN A in ('a','b') THEN A ELSE NULL END)) AS A,
('B_' || (CASE WHEN B in ('c','d') THEN B ELSE NULL END)) AS B,
('C_' || (CASE WHEN C in ('e','f') THEN C ELSE NULL END)) AS C
FROM planet_osm_point
) AS p
WHERE NOT COALESCE(A, B, C) IS NULL
ORDER BY z_order, way_area DESC
) AS bar (or replace that So, in summary, 👎, primarily because we can't use this query form for other places where we do use partial indexes. |
I'm still very much on two minds about this. On the one hand, I agree that we should not write code that causes a further performance loss, given that performance is already a problem. On the other hand, having duplicate code is almost guaranteed to at some point lead to errors / inconsistencies when people edit the code. Perhaps @gravitystorm also has an opinion? |
Looking at it more, I see this PR as a worse idea - people will copy the form of the query and use it elsewhere, which would be very bad. |
Would there really be no way in which we can avoid code duplication while still be able to use the partial indexes? |
We require a where clause that operates on on columns, not a computed value. Thinking about it, it's not just partial indexes, but query planning and a slew of other things. |
Yes, makes sense now I think of it. Thanks for the explanation. |
Closing this as it was rejected. |
* Make sure conditions are checked in both WHERE and COALESCE Checking the condition in the WHERE class is necessary for performance. Checking the condition in the COALESCE is necessary to prevent unrendered tags blocking rendering of tags further down in the COALESCE. See also the discussion [here](gravitystorm#1038 (comment)). This is an improvement of gravitystorm#1038. This resolves gravitystorm#985, resolves gravitystorm#1029, resolves gravitystorm#1336. * Give amenity priority over shop. This resolves gravitystorm#963. * Give tourism priority over amenity, shop, leisure, landuse, man_made, natural, and place. This resolves gravitystorm#1269, resolves first issue of gravitystorm#1232.
* Make sure conditions are checked in both WHERE and COALESCE Checking the condition in the WHERE class is necessary for performance. Checking the condition in the COALESCE is necessary to prevent unrendered tags blocking rendering of tags further down in the COALESCE. See also the discussion [here](gravitystorm#1038 (comment)). This is an improvement of gravitystorm#1038. This resolves gravitystorm#985, resolves gravitystorm#1029, resolves gravitystorm#1336. * Give amenity priority over shop. This resolves gravitystorm#963. * Give tourism priority over amenity, shop, leisure, landuse, man_made, natural, and place. This resolves gravitystorm#1269, resolves first issue of gravitystorm#1232.
* Make sure conditions are checked in both WHERE and COALESCE Checking the condition in the WHERE class is necessary for performance. Checking the condition in the COALESCE is necessary to prevent unrendered tags blocking rendering of tags further down in the COALESCE. See also the discussion [here](gravitystorm#1038 (comment)). This is an improvement of gravitystorm#1038. This resolves gravitystorm#985, resolves gravitystorm#1029, resolves gravitystorm#1336. * Give amenity priority over shop. This resolves gravitystorm#963. * Give tourism priority over amenity, shop, leisure, landuse, man_made, natural, and place. This resolves gravitystorm#1269, resolves first issue of gravitystorm#1232.
* Make sure conditions are checked in both WHERE and COALESCE Checking the condition in the WHERE class is necessary for performance. Checking the condition in the COALESCE is necessary to prevent unrendered tags blocking rendering of tags further down in the COALESCE. See also the discussion [here](gravitystorm#1038 (comment)). This is an improvement of gravitystorm#1038. This resolves gravitystorm#985, resolves gravitystorm#1029, resolves gravitystorm#1336. * Give amenity priority over shop. This resolves gravitystorm#963. * Give tourism priority over amenity, shop, leisure, landuse, man_made, natural, and place. This resolves gravitystorm#1269, resolves first issue of gravitystorm#1232.
* Make sure conditions are checked in both WHERE and COALESCE Checking the condition in the WHERE class is necessary for performance. Checking the condition in the COALESCE is necessary to prevent unrendered tags blocking rendering of tags further down in the COALESCE. See also the discussion [here](gravitystorm#1038 (comment)). This is an improvement of gravitystorm#1038. This resolves gravitystorm#985, resolves gravitystorm#1029, resolves gravitystorm#1336. * Give amenity priority over shop. This resolves gravitystorm#963. * Give tourism priority over amenity, shop, leisure, landuse, man_made, natural, and place. This resolves gravitystorm#1269, resolves first issue of gravitystorm#1232.