Skip to content

Commit

Permalink
WIP: try adding custom function with hardcoded planner stats
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Feb 7, 2023
1 parent f9abdad commit 21cec74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion healpix_alchemy/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@


def union(tiles):
return _func.unnest(_func.range_agg(tiles), type_=_Tile)
return _func.multirange_unnest(_func.range_agg(tiles), type_=_Tile)
23 changes: 23 additions & 0 deletions healpix_alchemy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,26 @@ def _create_indices(index, parent):
isinstance(index.expressions[0].type, Tile)
):
index.dialect_options['postgresql']['using'] = 'spgist'


@sa.event.listens_for(sa.Table, 'after_create')
def _after_create_table(target, connection, **kwargs):
"""Declare our own version of unnest() with a hardcoded planner row count
estimate that is more appropriate for sky maps.
FIXME: Remove this when PostgreSQL gets better planner support for
multiranges.
See https://github.com/skyportal/healpix-alchemy/pull/55.
"""
connection.execute(sa.text(
'CREATE OR REPLACE FUNCTION multirange_unnest(arg anymultirange)'
' RETURNS SETOF anyrange'
' AS $$ select unnest($1); $$'
' LANGUAGE SQL'
' IMMUTABLE'
' PARALLEL SAFE'
' STRICT'
' COST 1'
' ROWS 2000'
))

0 comments on commit 21cec74

Please sign in to comment.