如何加快postgresql中的连接查询速度

时间:2018-03-22 15:59:29

标签: python postgresql psycopg2

我使用psycopg2将两个表连接在一起。但由于某种原因,这个过程花了太长时间。两个表都有索引。这些表有大约280行和5-6列。但它们确实有一个具有复杂国家边界的几何列。

这是查询的样子:

sqlstr = """CREATE TABLE {new_table_name} AS (
              SELECT {geom_table_columns}, {added_columns} 
              FROM {geom_table} 
              INNER JOIN {temp_table} ON 
                (g.{id} = {temp_table}.{id})
            );
         """.format(** {
            'new_table_name': new_table,
            'geom_table': geom_table_name,
            'geom_table_columns': geom_table_columns,
            'temp_table': table_name_temp,
            'id': geom_table_id,
            'added_columns': added_columns
        })

有没有办法让这个内连接查询更快?

0 个答案:

没有答案