简体   繁体   English

如何加快 BigQuery 中的空间连接?

[英]How to speed-up a spatial join in BigQuery?

I have a BigQuery table with point registers along a whole country, and I need to assign a "censal zone" to each one of them, which polygons are contained in another table.我有一个 BigQuery 表,其中包含整个国家的点寄存器,我需要为它们中的每一个分配一个“人口统计区”,这些多边形包含在另一个表中。 I've been trying to do so using a query like this one:我一直在尝试使用这样的查询来做到这一点:

SELECT id_point, code_censal_zone
    FROM `points_table`
    JOIN `zones_table`
    ON ST_CONTAINS(zone_polygon, point_geo)

The first table is quite large, so the query performes very inefficiently as it is comparing each possible pairs of (point, censal zone).第一个表非常大,因此查询执行效率非常低,因为它正在比较每个可能的 (point, censal zone) 对。 However, both tables have a column identifier for the municipality in which they are in, so the question is, can rewrite my query in some way that ST_CONTAINS(*) is performed for each (point, censal zone) pair that belongs to the same municipality, hence not comparing all posible censal zones within the country for each point?但是,这两个表都有一个列标识符,表示它们所在的自治市,所以问题是,可以以某种方式重写我的查询,即对属于相同的每个(点、人口普查区)对执行ST_CONTAINS(*)市,因此不比较每个点在国内所有可能的人口普查区? Can I do this without having to read points_table multiple times?我可以这样做而不必多次阅读points_table吗?

SELECT id_point, code_censal_zone
    FROM `points_table`
    JOIN `zones_table`
    ON 1.municipality = 2.municipality
    AND ST_CONTAINS(zone_geo, point_geo)

I'm quite new to BigQuery so I don't really know if a query like this would actually do what I'am expecting, as I couldn't find anything in the documentation.我对 BigQuery 还是很陌生,所以我真的不知道这样的查询是否真的能达到我的预期,因为我在文档中找不到任何内容。

Thanks!谢谢!

SELECT id_point, code_censal_zone
    FROM `points_table`
    JOIN `zones_table`
    ON 1.municipality = 2.municipality
    AND ST_CONTAINS(zone_geo, point_geo)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM