Skip to content

Using RTREE in spatial joins #702

@rafapereirabr

Description

@rafapereirabr

Hey all, I just wanted clarify something about the documentation.

This post from 2025/08 says R-Tree indexing would work fine and improve the performance of spatial join operations. So

SELECT v1.CNTR_ID, v1.NAME_ENGL, v2.CNTR_ID, v2.ISO3_CODE, ST_AsText(v1.geometry) AS geometry
FROM brazil v1
LEFT JOIN countries v2
    ON ST_Intersects(v1.geometry, v2.geometry)

However, this page with the documentation about R-Tree indexing says "The R-tree index will only be used to perform "index scans" when the table is filtered (using a WHERE clause)", which susggest I should use:

SELECT v1.CNTR_ID, v1.NAME_ENGL, v2.CNTR_ID, v2.ISO3_CODE, ST_AsText(v1.geometry) AS geometry
FROM brazil v1, countries v2
    WHERE ST_Intersects(v1.geometry, v2.geometry)

Could you please clarify whether the best approach here? Would R-Tree indexing improve the performance of spatial join operations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions