Timing is on.
BEGIN
Time: 0.100 ms
DROP INDEX
Time: 0.695 ms
DROP INDEX
Time: 0.189 ms
WRITE WITHOUT SECONDARY INDEXES
                                                                  QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
 Insert on messages  (cost=0.00..275.41 rows=0 width=0) (actual time=30.658..30.659 rows=0 loops=1)
   Buffers: shared hit=39804 read=579 dirtied=749 written=174
   ->  Subquery Scan on "*SELECT*"  (cost=0.00..275.41 rows=10000 width=88) (actual time=0.339..10.740 rows=10000 loops=1)
         Buffers: shared hit=1
         ->  Limit  (cost=0.00..150.41 rows=10000 width=80) (actual time=0.338..9.999 rows=10000 loops=1)
               Buffers: shared hit=1
               ->  Nested Loop  (cost=0.00..42113.50 rows=2800000 width=80) (actual time=0.337..9.452 rows=10000 loops=1)
                     Buffers: shared hit=1
                     ->  Function Scan on generate_series  (cost=0.00..100.00 rows=10000 width=0) (actual time=0.322..0.365 rows=667 loops=1)
                     ->  Materialize  (cost=0.00..14.20 rows=280 width=32) (actual time=0.000..0.001 rows=15 loops=667)
                           Buffers: shared hit=1
                           ->  Seq Scan on chats c  (cost=0.00..12.80 rows=280 width=32) (actual time=0.004..0.006 rows=15 loops=1)
                                 Buffers: shared hit=1
 Planning:
   Buffers: shared hit=65
 Planning Time: 0.146 ms
 Trigger for constraint messages_chat_id_fkey: time=25.322 calls=10000
 Trigger for constraint messages_sender_id_fkey: time=32.144 calls=10000
 Execution Time: 88.932 ms
(19 rows)

Time: 89.644 ms
ROLLBACK
Time: 0.131 ms
BEGIN
Time: 0.082 ms
WRITE WITH EXISTING INDEXES
                                                                  QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
 Insert on messages  (cost=0.00..275.41 rows=0 width=0) (actual time=50.655..50.656 rows=0 loops=1)
   Buffers: shared hit=90871 read=26 dirtied=348 written=320
   ->  Subquery Scan on "*SELECT*"  (cost=0.00..275.41 rows=10000 width=88) (actual time=0.446..11.088 rows=10000 loops=1)
         Buffers: shared hit=1
         ->  Limit  (cost=0.00..150.41 rows=10000 width=80) (actual time=0.445..10.291 rows=10000 loops=1)
               Buffers: shared hit=1
               ->  Nested Loop  (cost=0.00..42113.50 rows=2800000 width=80) (actual time=0.444..9.751 rows=10000 loops=1)
                     Buffers: shared hit=1
                     ->  Function Scan on generate_series  (cost=0.00..100.00 rows=10000 width=0) (actual time=0.410..0.455 rows=667 loops=1)
                     ->  Materialize  (cost=0.00..14.20 rows=280 width=32) (actual time=0.000..0.001 rows=15 loops=667)
                           Buffers: shared hit=1
                           ->  Seq Scan on chats c  (cost=0.00..12.80 rows=280 width=32) (actual time=0.005..0.008 rows=15 loops=1)
                                 Buffers: shared hit=1
 Planning Time: 0.077 ms
 Trigger for constraint messages_chat_id_fkey: time=25.106 calls=10000
 Trigger for constraint messages_sender_id_fkey: time=31.329 calls=10000
 Execution Time: 107.873 ms
(17 rows)

Time: 108.260 ms
ROLLBACK
Time: 0.109 ms
