【发布时间】:2014-08-07 08:27:34
【问题描述】:
该表包含大约 3 亿行。我需要根据两列选择这些行。
SELECT *
FROM table_1
WHERE column_1
IN (SELECT column FROM table_2)
AND column_2
IN (SELECT column FROM table_2)
table_1 有 3 亿行。 table_2 有 100 万个不同的行。
我也使用了 exists 方法:
SELECT *
FROM table_1
WHERE EXISTS (
SELECT 1
FROM table_2
WHERE column=table_1.column_1)
AND EXISTS (
SELECT 1
FROM table_2
WHERE column=table_1.column_2)
但是太慢了。我在 table_1 中的两列和 table_2 中的列上创建了索引。在 12G RAM 戴尔服务器上需要两个多小时。
有没有更好的方法来处理这么大的桌子? Hadoop 能解决这个问题吗?
【问题讨论】:
-
发布查询的
explain。 postgresql.org/docs/current/static/sql-explain.html
标签: sql postgresql