Индексы, ограничения и язык запросов в PostgreSQL, страница 2

                                               QUERY PLAN

-----------------------------------------------------------------------------

------------------------

 Seq Scan on products  (cost=0.00..24.07 rows=227 width=37) (actual time=0.090..0.223 rows=228 loops=1)

   Filter: ((id >= 573) AND (id <= 800))

 Total runtime: 0.298 ms

(3 rows)

·  Индекс типа BTREE

shop=# EXPLAIN ANALYSE select * from products where id=500;

                                                     QUERY PLAN

-----------------------------------------------------------------------------

------------------------------------

 Index Scan using ind_prod on products  (cost=0.00..8.27 rows=1 width=37) (actual time=0.072..0.073 rows=1 loops=1)

   Index Cond: (id = 500)

 Total runtime: 0.122 ms

(3 rows)

shop=# EXPLAIN ANALYSE select * from products where id<500;

                                               QUERY PLAN

-----------------------------------------------------------------------------

------------------------

 Seq Scan on products  (cost=0.00..21.56 rows=500 width=37) (actual time=0.008..0.266 rows=499 loops=1)

   Filter: (id < 500)

 Total runtime: 0.416 ms

(3 rows)

shop=# EXPLAIN ANALYSE select * from products where id>500;

                                               QUERY PLAN

-----------------------------------------------------------------------------

------------------------

 Seq Scan on products  (cost=0.00..21.56 rows=505 width=37) (actual time=0.080..0.269 rows=505 loops=1)

   Filter: (id > 500)

 Total runtime: 0.410 ms

(3 rows)

shop=# EXPLAIN ANALYSE select * from products where id between 573 and 800;

                                                       QUERY PLAN

-----------------------------------------------------------------------------

-----------------------------------------

 Index Scan using ind_prod on products  (cost=0.00..18.79 rows=227 width=37) (actual time=0.016..0.135 rows=228 loops=1)

   Index Cond: ((id >= 573) AND (id <= 800))

 Total runtime: 0.218 ms

(3 rows)

·  Индекс типа HASH

shop=# EXPLAIN ANALYSE select * from products where id=500;

                                                     QUERY PLAN

-----------------------------------------------------------------------------

------------------------------------

 Index Scan using ind_prod on products  (cost=0.00..8.27 rows=1 width=37) (actual time=0.013..0.014 rows=1 loops=1)

   Index Cond: (id = 500)

 Total runtime: 0.049 ms

(3 rows)

shop=# EXPLAIN ANALYSE select * from products where id<500;

                                               QUERY PLAN

-----------------------------------------------------------------------------

------------------------

 Seq Scan on products  (cost=0.00..21.56 rows=500 width=37) (actual time=0.009..0.264 rows=499 loops=1)

   Filter: (id < 500)

 Total runtime: 0.401 ms

(3 rows)

shop=# EXPLAIN ANALYSE select * from products where id>500;

                                               QUERY PLAN

-----------------------------------------------------------------------------

------------------------

 Seq Scan on products  (cost=0.00..21.56 rows=505 width=37) (actual time=0.080..0.265 rows=505 loops=1)

   Filter: (id > 500)

 Total runtime: 0.403 ms

(3 rows)

shop=# EXPLAIN ANALYSE select * from products where id between 573 and 800;

                                               QUERY PLAN

-----------------------------------------------------------------------------

------------------------

 Seq Scan on products  (cost=0.00..24.07 rows=227 width=37) (actual time=0.090..0.222 rows=228 loops=1)

   Filter: ((id >= 573) AND (id <= 800))