Skip to content

Commit

Permalink
Node back-end: ensure that Z filtering on regular BB query is materia…
Browse files Browse the repository at this point in the history
…lized

This materialization is required since Postgres 12. Unfortunately,
inlining this part of the query destroys some estimates and leads to
less ideal plans.
  • Loading branch information
tomka committed Apr 4, 2020
1 parent 1370561 commit c70ff93
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django/applications/catmaid/control/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,10 @@ class Postgis2dNodeProvider(PostgisNodeProvider):
"""

TREENODE_STATEMENT_NAME = PostgisNodeProvider.TREENODE_STATEMENT_NAME + '_2d'
# MATERIALIZED seems to be needed at the moment, at least for large queries.
# For smaller FOVs, the NOT MATERIALIZED version seems to do better.
treenode_query = """
WITH z_filtered_edge AS (
WITH z_filtered_edge AS MATERIALIZED (
SELECT te.id, te.parent_id, te.edge
FROM treenode_edge te
WHERE floatrange(ST_ZMin(te.edge),
Expand Down Expand Up @@ -1264,7 +1266,7 @@ class Postgis2dBlurryNodeProvider(PostgisNodeProvider):

TREENODE_STATEMENT_NAME = PostgisNodeProvider.TREENODE_STATEMENT_NAME + '_2d_blurry'
treenode_query = """
WITH z_filtered_edge AS (
WITH z_filtered_edge AS MATERIALIZED (
SELECT te.id, te.parent_id, te.edge
FROM treenode_edge te
WHERE floatrange(ST_ZMin(te.edge), ST_ZMax(te.edge), '[]') && floatrange({z1}, {z2}, '[)')
Expand Down

0 comments on commit c70ff93

Please sign in to comment.