KeyDB icon indicating copy to clipboard operation
KeyDB copied to clipboard

[BUG] GEOSEARCH BYBOX misses members that are inside the box

Open jiren-the-gray opened this issue 1 month ago • 0 comments

Describe the bug

GEOSEARCH ... BYBOX drops members that lie inside the requested box. The member is stored, it is within the box on every other measure KeyDB itself offers - GEODIST puts it well inside, and the equivalent BYRADIUS search finds it - but the BYBOX search does not return it.

GEOADD c 45.05 74.9 p_east 1 70 q_center            -> 2
GEOSEARCH c FROMLONLAT 1 66 BYBOX 2500 2000 km ASC  -> 1) "q_center"
                                                       expected: q_center and p_east

Redis 8.10.2, Garnet 2.2.2 and Dragonfly 2.0.2 all return both members for this query. The member that is dropped is not marginal: with the box 2500 km wide and 2000 km tall (half-extents 1250 km and 1000 km), p_east sits 1530 km from the centre along a path that is inside the box, and both the huge-box control and the radius control find it on KeyDB too:

GEODIST  c q_center p_east km                        -> "1530.8895"
GEOSEARCH c FROMLONLAT 1 66 BYRADIUS 2000 km ASC     -> q_center, p_east     (KeyDB: both)
GEOSEARCH c FROMLONLAT 1 66 BYBOX 20000 20000 km ASC -> q_center, p_east     (KeyDB: both)
GEOSEARCH c FROMLONLAT 1 66 BYBOX 2500 2000 km ASC   -> q_center             (KeyDB: one)
ZRANGE   c 0 -1                                      -> q_center, p_east     (both stored)

So the member is reachable and the data is fine; it is the box search at this size that loses it. For an application doing "what is in this rectangle" over a high-latitude region, results are silently incomplete - no error, just a short list.

To reproduce

docker run -d -p 6402:6379 eqalpha/keydb:x86_64_v6.3.4

From a clean keyspace (FLUSHALL), on one connection:

GEOADD c 45.05 74.9 p_east 1 70 q_center
GEOSEARCH c FROMLONLAT 1 66 BYBOX 2500 2000 km ASC
    -> 1) "q_center"                       expected 1) "q_center"  2) "p_east"
GEOSEARCH c FROMLONLAT 1 66 BYBOX 2500 2000 km ASC WITHDIST
    -> 1) 1) "q_center" 2) "444.9051"      expected also p_east at ~1850.0293

Each row below is an independent sequence from a clean keyspace with those two members.

case expected Redis 8.10.2 Garnet Dragonfly KeyDB 6.3.4
BYBOX 2500 2000 km from (1,66) q_center, p_east both both both q_center only
same, WITHDIST both, p_east ~1850 km both both both q_center only
control: BYBOX 20000 20000 km both both both both both
control: BYRADIUS 2000 km both both both both both
control: GEODIST q_center p_east km ~1530.89 1530.8895 1530.8894 1530.8895 1530.8895
control: ZRANGE c 0 -1 both stored both both both both

A self-contained Python 3 reproducer (standard library only) that runs every case against KeyDB and reference servers and prints this table is attached as repro.py; it exits 0 when the bug reproduces.

Expected behavior

Both members should be returned, as they are by Redis 8.10.2, Garnet and Dragonfly. The GEOSEARCH documentation defines BYBOX as returning the members inside an axis-aligned box of the given width and height centred on the search origin; a member whose position is inside that box is a member of the result.

The internal inconsistency is the clearer argument: within KeyDB, BYRADIUS 2000 km and BYBOX 20000 20000 km from the same centre both return p_east, so KeyDB's own membership test accepts it. Only the BYBOX 2500 2000 km search drops it, which points at the candidate-cell selection rather than at the membership test.

Additional information

Version and environment. KeyDB 6.3.4, from the published container image eqalpha/keydb:x86_64_v6.3.4 (digest sha256:eceb1806730c7850395b8262300182c2e15a6e5dacbf0b72cbab110518caf43f); INFO server reports redis_version:6.3.4. Source read at 7e7e5e57d25fe246a8201f0acf5e7363c0bf1e14 (tag v6.3.4). Host: Ubuntu 24.04.5 LTS, kernel 7.0.0-38-generic (x86_64), Docker. Default configuration, single node.

jiren-the-gray avatar Oct 20 '26 15:10 jiren-the-gray