Timing is on.
BEGIN
Time: 0.114 ms
DROP INDEX
Time: 0.510 ms
DROP INDEX
Time: 0.255 ms
WRITE WITHOUT SECONDARY INDEXES
                                                                  QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
 Insert on messages  (cost=0.00..275.41 rows=0 width=0) (actual time=38.420..38.421 rows=0 loops=1)
   Buffers: shared hit=39651 read=676 dirtied=815 written=143
   ->  Subquery Scan on "*SELECT*"  (cost=0.00..275.41 rows=10000 width=88) (actual time=0.387..11.577 rows=10000 loops=1)
         Buffers: shared hit=1
         ->  Limit  (cost=0.00..150.41 rows=10000 width=80) (actual time=0.386..10.826 rows=10000 loops=1)
               Buffers: shared hit=1
               ->  Nested Loop  (cost=0.00..42113.50 rows=2800000 width=80) (actual time=0.385..10.225 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.358..0.388 rows=345 loops=1)
                     ->  Materialize  (cost=0.00..14.20 rows=280 width=32) (actual time=0.000..0.001 rows=29 loops=345)
                           Buffers: shared hit=1
                           ->  Seq Scan on chats c  (cost=0.00..12.80 rows=280 width=32) (actual time=0.009..0.013 rows=29 loops=1)
                                 Buffers: shared hit=1
 Planning:
   Buffers: shared hit=65
 Planning Time: 0.148 ms
 Trigger for constraint messages_chat_id_fkey: time=26.385 calls=10000
 Trigger for constraint messages_sender_id_fkey: time=45.532 calls=10000
 Execution Time: 111.483 ms
(19 rows)

Time: 112.022 ms
ROLLBACK
Time: 0.118 ms
BEGIN
Time: 0.125 ms
CREATE INDEX
Time: 0.326 ms
WRITE WITH EXISTING INDEXES
                                                                  QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
 Insert on messages  (cost=0.00..275.41 rows=0 width=0) (actual time=48.708..48.709 rows=0 loops=1)
   Buffers: shared hit=90737 read=23 dirtied=292 written=245
   ->  Subquery Scan on "*SELECT*"  (cost=0.00..275.41 rows=10000 width=88) (actual time=0.533..11.244 rows=10000 loops=1)
         Buffers: shared hit=1
         ->  Limit  (cost=0.00..150.41 rows=10000 width=80) (actual time=0.532..10.510 rows=10000 loops=1)
               Buffers: shared hit=1
               ->  Nested Loop  (cost=0.00..42113.50 rows=2800000 width=80) (actual time=0.531..9.910 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.497..0.525 rows=345 loops=1)
                     ->  Materialize  (cost=0.00..14.20 rows=280 width=32) (actual time=0.000..0.001 rows=29 loops=345)
                           Buffers: shared hit=1
                           ->  Seq Scan on chats c  (cost=0.00..12.80 rows=280 width=32) (actual time=0.008..0.011 rows=29 loops=1)
                                 Buffers: shared hit=1
 Planning Time: 0.055 ms
 Trigger for constraint messages_chat_id_fkey: time=26.086 calls=10000
 Trigger for constraint messages_sender_id_fkey: time=41.720 calls=10000
 Execution Time: 117.756 ms
(17 rows)

Time: 118.278 ms
ROLLBACK
Time: 0.159 ms
