当我启用hashjoin时,为什么查询计划没有改变?

时间:2015-06-04 10:12:06

标签: sql postgresql

我在PostgreSQL 9.2中尝试手动更改查询计划,如下所示pgadmin

SET enable_hashjoin TO true;
EXPLAIN ANALYZE
SELECT *
FROM tbl1 
FULL OUTER JOIN tbl2 ON SOME_CONDITION
FULL OUTER JOIN tbl3 ON SOME_CONDITION
OFFSET 2000 LIMIT 20

结果完全和原来一样:

EXPLAIN ANALYZE
SELECT *
FROM tbl1 
FULL OUTER JOIN tbl2 ON SOME_CONDITION
FULL OUTER JOIN tbl3 ON SOME_CONDITION
OFFSET 2000 LIMIT 20

结果:

"  ->  Merge Full Join  (cost=899265.88..980151.59 rows=441998 width=127) (actual time=11985.047..11993.662 rows=2020 loops=1)"
"        Merge Cond: ((daily_profit.currency_id = players_external_transactions.currency_id) AND (daily_profit.platform_id = players_external_transactions.platform_id) AND (daily_profit.partner_id = players_external_transactions.partner_id) AND (daily_profit.player_id = players_external_transactions.player_id))"
"        ->  GroupAggregate  (cost=816428.39..888252.93 rows=441998 width=21) (actual time=10413.132..10420.008 rows=1611 loops=1)"
"              Group Key: daily_profit.currency_id, daily_profit.platform_id, daily_profit.partner_id, daily_profit.player_id"
"              ->  Sort  (cost=816428.39..827478.32 rows=4419971 width=21) (actual time=10413.121..10416.994 rows=8380 loops=1)"
"                    Sort Key: daily_profit.currency_id, daily_profit.platform_id, daily_profit.partner_id, daily_profit.player_id"
"                    Sort Method: external merge  Disk: 134104kB"
"                    ->  Seq Scan on daily_profit  (cost=0.00..147267.71 rows=4419971 width=21) (actual time=0.019..1148.922 rows=4415703 loops=1)"

如您所见,我们在这里合并完全加入。但我期望像哈希加入这样的东西在计划中。我做错了什么?

0 个答案:

没有答案