unepwcmc/carbon-benefits — pull request #25 by strk (2014-02-21 11:06:24+00:00)
Title: Improve speed of the SQL_RESTORATION query

I've seen it taking 1/230 of the time for this query polygon:

MULTIPOLYGON(((2.724609375 42.71473218539458,
3.2958984375 43.929549935614595,
4.8779296875 43.77109381775651,
4.2626953125 42.65012181368025,
2.724609375 42.71473218539458)))

The patch is intentionally localized, but at a glance other
SQL queries could be modified with the same pattern, basically
unrolling the subquery into filtering directly the cross product.

The patch is untested in its context as I don't know how to test
(hint: "make check" support would be gold ;)