avoid index use when filtering by layer

This commit is contained in:
Sarah Hoffmann 2023-11-22 20:54:04 +01:00
parent e7dc24c026
commit ac5ef64701

View File

@ -114,14 +114,14 @@ def _make_interpolation_subquery(table: SaFromClause, inner: SaFromClause,
def _filter_by_layer(table: SaFromClause, layers: DataLayer) -> SaColumn: def _filter_by_layer(table: SaFromClause, layers: DataLayer) -> SaColumn:
orexpr: List[SaExpression] = [] orexpr: List[SaExpression] = []
if layers & DataLayer.ADDRESS and layers & DataLayer.POI: if layers & DataLayer.ADDRESS and layers & DataLayer.POI:
orexpr.append(table.c.rank_address.between(1, 30)) orexpr.append(no_index(table.c.rank_address).between(1, 30))
elif layers & DataLayer.ADDRESS: elif layers & DataLayer.ADDRESS:
orexpr.append(table.c.rank_address.between(1, 29)) orexpr.append(no_index(table.c.rank_address).between(1, 29))
orexpr.append(sa.and_(table.c.rank_address == 30, orexpr.append(sa.and_(no_index(table.c.rank_address) == 30,
sa.or_(table.c.housenumber != None, sa.or_(table.c.housenumber != None,
table.c.address.has_key('addr:housename')))) table.c.address.has_key('addr:housename'))))
elif layers & DataLayer.POI: elif layers & DataLayer.POI:
orexpr.append(sa.and_(table.c.rank_address == 30, orexpr.append(sa.and_(no_index(table.c.rank_address) == 30,
table.c.class_.not_in(('place', 'building')))) table.c.class_.not_in(('place', 'building'))))
if layers & DataLayer.MANMADE: if layers & DataLayer.MANMADE:
@ -131,7 +131,7 @@ def _filter_by_layer(table: SaFromClause, layers: DataLayer) -> SaColumn:
if not layers & DataLayer.NATURAL: if not layers & DataLayer.NATURAL:
exclude.extend(('natural', 'water', 'waterway')) exclude.extend(('natural', 'water', 'waterway'))
orexpr.append(sa.and_(table.c.class_.not_in(tuple(exclude)), orexpr.append(sa.and_(table.c.class_.not_in(tuple(exclude)),
table.c.rank_address == 0)) no_index(table.c.rank_address) == 0))
else: else:
include = [] include = []
if layers & DataLayer.RAILWAY: if layers & DataLayer.RAILWAY:
@ -139,7 +139,7 @@ def _filter_by_layer(table: SaFromClause, layers: DataLayer) -> SaColumn:
if layers & DataLayer.NATURAL: if layers & DataLayer.NATURAL:
include.extend(('natural', 'water', 'waterway')) include.extend(('natural', 'water', 'waterway'))
orexpr.append(sa.and_(table.c.class_.in_(tuple(include)), orexpr.append(sa.and_(table.c.class_.in_(tuple(include)),
table.c.rank_address == 0)) no_index(table.c.rank_address) == 0))
if len(orexpr) == 1: if len(orexpr) == 1:
return orexpr[0] return orexpr[0]