Postgresql 等待查询完成(从不完成)

Postgresql 等待查询完成(从不完成),postgresql,postgis,common-table-expression,spatial,Postgresql,Postgis,Common Table Expression,Spatial,当我运行此查询时,会在“等待查询完成”处出错 with cte1 as ( select id as c, ST_SetSRID(ST_MakePoint(lo, la), 4326) as u_t1 from t1 ), cte2 as ( select t2.a1 as c, st_union(t2.way) as c

当我运行此查询时,会在“等待查询完成”处出错

with
    cte1 as (
        select
            id as c,
            ST_SetSRID(ST_MakePoint(lo, la), 4326) as u_t1
        from t1
        ),
    cte2 as (
        select
            t2.a1 as c,
            st_union(t2.way) as c1
            from t2
            group by c
        ),
    cte3 as(
            select sum (t3.a2) as sum1              
                from cte1, cte2, t3
                where st_intersects(cte1.u_t1, cte2.c1)
                group by cte2.c1
        )
 select 
    cte3.sum1
    cte2.c  
    from cte3,  cte2

查询的建议是
SUM
a
INT
列与
ST\u相交
限制。在ct1和ct2中推导了st_相交的属性。我想这可能需要一些时间,但问题是查询永远不会完成

知道为什么吗


谢谢

问题可能在这里:

cte3 as(
        select sum (t3.a2) as sum1              
            from cte1, cte2, t3
            where st_intersects(cte1.u_t1, cte2.c1)
            group by cte2.c1
    )
可以联接三个表,但在
cte1
cte2
之间只有联接条件。因此,您将从该连接中获得所有可能的行组合,并将其与结果集中
t3
中的行(笛卡尔乘积)中的行组合。这可能很大,也是您的问题的原因

要避免该问题,请养成使用标准联接语法的习惯:

FROM cte1
   JOIN cte2 ON st_intersects(cte1.u_t1, cte2.c1)
   JOIN t3 ON ...

然后您不能忘记连接条件,因为在子句上没有
是一个语法错误。

如果不使用ANSI连接语法,您将创建潜在的巨大笛卡尔乘积。请在这里花几分钟时间:谢谢您的回复。我正在自学,虽然有时我需要帮助,但谢谢你的链接。