Plan 1: db> explain analyze execute test_001(31855344); QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=333067.77..333067.79 rows=10 width=1804) (actual time=652.739..652.741 rows=2 loops=1) -> Sort (cost=333067.77..333067.86 rows=36 width=1804) (actual time=652.736..652.736 rows=2 loops=1) Sort Key: ta.a, ta.b -> Hash Join (cost=3364.30..333066.84 rows=36 width=1804) (actual time=648.159..652.709 rows=2 loops=1) Hash Cond: (ta.b = tb.b) -> Index Scan using pk_table_a on table_a ta (cost=0.00..324786.18 rows=388532 width=16) (actual time=454.389..460.138 rows=2 loops=1) Index Cond: (a = $1) -> Hash (cost=524.58..524.58 rows=41658 width=1788) (actual time=187.192..187.192 rows=41671 loops=1) -> Seq Scan on table_b2 tb (cost=0.00..524.58 rows=41658 width=1788) (actual time=5.540..113.387 rows=41671 loops=1) Total runtime: 652.980 ms Plan 2: db> explain analyze execute test_001(31855344); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.00..498511.80 rows=10 width=1804) (actual time=17.729..21.672 rows=2 loops=1) -> Nested Loop (cost=0.00..1794642.48 rows=36 width=1804) (actual time=17.729..21.671 rows=2 loops=1) -> Index Scan using pk_table_a on table_a ta (cost=0.00..324880.88 rows=388638 width=16) (actual time=0.146..0.198 rows=2 loops=1) Index Cond: (a = $1) -> Index Scan using pk_table_b2 on table_b2 tb (cost=0.00..3.77 rows=1 width=1788) (actual time=10.729..10.731 rows=1 loops=2) Index Cond: (ta.b = tb.b) Total runtime: 21.876 ms Plan 3: db> explain analyze execute test_001(31855344); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.00..853.14 rows=10 width=325) (actual time=20.117..28.104 rows=2 loops=1) -> Nested Loop (cost=0.00..2024323.48 rows=23728 width=325) (actual time=20.116..28.101 rows=2 loops=1) -> Index Scan using pk_table_a on table_a ta (cost=0.00..327561.01 rows=388684 width=16) (actual time=0.023..0.027 rows=2 loops=1) Index Cond: (a = $1) -> Index Scan using pk_table_b1 on table_b1 tb (cost=0.00..4.35 rows=1 width=309) (actual time=14.032..14.034 rows=1 loops=2) Index Cond: (ta.b = tb.b) Total runtime: 28.200 ms