Testing custom operator classes

In our example, the test data consists of just two rows. Therefore, PostgreSQL will never use an index because the table is just too small to justify the overhead of even opening the index. To be able to still test without having to load too much data, you can advise the optimizer to make sequential scans more expensive.

Making operations more expensive can be done in your session using the following instruction:

SET enable_seqscan TO off; 

The index works as expected:

test=# explain SELECT * FROM t_sva WHERE sva = '0000112273';  
                                  QUERY PLAN ------------------------------------------------------------------  Index Only Scan using idx_special on t_sva    (cost=0.13..8.14 rows=1 width=32)  Index Cond: (sva = '0000112273'::text) ...

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.