explain (analyze) select i from unnest(array[1,2,3,4,5]) as i where exists (select 1 from v_vars where var_order = i);
QUERY PLAN
---------------------------------------------------------------------------------------------------------------
Hash Semi Join (cost=3.69..5.88 rows=75 width=4) (actual time=0.091..0.094 rows=5 loops=1)
Hash Cond: ((i.i)::numeric = v_vars.var_order)
-> Function Scan on unnest i (cost=0.00..1.00 rows=100 width=4) (actual time=0.009..0.009 rows=5 loops=1)
-> Hash (cost=2.75..2.75 rows=75 width=5) (actual time=0.052..0.052 rows=75 loops=1)
Buckets: 1024 Batches: 1 Memory Usage: 11kB
-> Seq Scan on v_vars (cost=0.00..2.75 rows=75 width=5) (actual time=0.011..0.026 rows=75 loops=1)
Planning time: 0.566 ms
Execution time: 0.135 ms
(8 строк)
explain (analyze) select var_order from v_vars where var_order in (1,2,3,4,5);
QUERY PLAN
------------------------------------------------------------------------------------------------
Seq Scan on v_vars (cost=0.00..3.22 rows=5 width=5) (actual time=0.020..0.067 rows=5 loops=1)
Filter: (var_order = ANY ('{1,2,3,4,5}'::numeric[]))
Rows Removed by Filter: 70
Planning time: 0.194 ms
Execution time: 0.086 ms
(5 строк)
SELECT ID FROM table WHERE ID IN (1,2,3,4,5,6,7)
MacBook-Pro:~ leah$ time python -c 'set(range(1,1000022)) - set(range(1,1000000))'
real 0m0.306s
user 0m0.186s
sys 0m0.092s
MacBook-Pro:~ leah$