Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpatialJoin not activated for ST_Distance(p, q) BETWEEN d1 and d2 #14569

Open
jagill opened this issue May 21, 2020 · 1 comment
Open

SpatialJoin not activated for ST_Distance(p, q) BETWEEN d1 and d2 #14569

jagill opened this issue May 21, 2020 · 1 comment

Comments

@jagill
Copy link
Contributor

jagill commented May 21, 2020

The conditions

ST_DISTANCE(p1.p, p2.p) < 4 AND ST_DISTANCE(p1.p, p2.p) > 2

and

ST_DISTANCE(p1.p, p2.p) between 2 and 4

are the same, but the first triggers a Spatial Join and the second does not. Example queries:

EXPLAIN (TYPE DISTRIBUTED)
WITH points AS (
  SELECT
    ST_POINT(x, y) AS p
  FROM (
    VALUES
      (1, 1),
      (2, 2)
  ) AS t (x, y)
)
SELECT
  *
FROM points p1,
  points p2
WHERE
  ST_DISTANCE(p1.p, p2.p) < 4
  AND ST_DISTANCE(p1.p, p2.p) > 2
EXPLAIN (TYPE DISTRIBUTED)
WITH points AS (
  SELECT
    ST_POINT(x, y) AS p
  FROM (
    VALUES
      (1, 1),
      (2, 2)
  ) AS t (x, y)
)
SELECT
  *
FROM points p1,
  points p2
WHERE
  ST_DISTANCE(p1.p, p2.p) BETWEEN 2 AND 4
@mbasmanova
Copy link
Contributor

Oh... This is because spatial join is triggered only for ST_DISTANCE(a, b) < r and ST_DISTANCE(a, b) <= r. In the first query, spatial join is trigged by < 4 with conjunct > 2 applied after the join. In the second query, there is no eligible condition. It would be cool to enhance the optimizer to trigger spatial joins ST_DISTANCE(a, b) between r1 and r2.

CC: @zhenxiao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants