Bitmap heap and index scans
As mentioned in the last chapter, PostgreSQL is capable of combining indexes together when two of them are relevant for answering a query. The customers
table in the Dell Store example has an index on both the customerid
and the username
. These are both pretty boring bits of data:
SELECT customerid,username from customers limit 3; customerid | username ------------+---------- 1 | user1 2 | user2 3 | user3
The following somewhat contrived query only returns two rows, but it can use both indexes to accelerate that, and after tweaking the number of values referenced it's possible to demonstrate that:
SELECT customerid,username FROM customers WHERE customerid<10000 AND username<'user100'; customerid | username ------------+---------- 1 | user1 10 | user10 EXPLAIN ANALYZE SELECT customerid,username FROM customers WHERE customerid<10000 AND username<'user100'; QUERY PLAN...