1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Add index-only scan support to btree_gist.

inet, cidr, and timetz indexes still cannot support index-only scans,
because they don't store the original unmodified value in the index, but a
derived approximate value.
This commit is contained in:
Heikki Linnakangas
2015-03-27 23:35:16 +02:00
parent 735cd6128a
commit e09b48316c
46 changed files with 614 additions and 51 deletions

View File

@ -64,3 +64,13 @@ SELECT count(*) FROM bittmp WHERE a > '011011000100010111011000110000100';
350
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT a FROM bittmp WHERE a BETWEEN '1000000' and '1000001';
QUERY PLAN
-----------------------------------------------------------------------
Index Only Scan using bitidx on bittmp
Index Cond: ((a >= B'1000000'::"bit") AND (a <= B'1000001'::"bit"))
(2 rows)

View File

@ -71,3 +71,20 @@ SELECT count(*) FROM byteatmp WHERE a = '2eb2c961c1cbf6 cf8d7b68cb9a2f36 7bbed
1
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT a FROM byteatmp where a > 'ffa'::bytea;
QUERY PLAN
--------------------------------------------
Index Only Scan using byteaidx on byteatmp
Index Cond: (a > '\x666661'::bytea)
(2 rows)
SELECT a FROM byteatmp where a > 'ffa'::bytea;
a
--------------------------------
\x666662656532373363376262
\x6666626663313331336339633835
(2 rows)

View File

@ -74,10 +74,10 @@ SELECT count(*) FROM moneytmp WHERE a > '22649.64'::money;
EXPLAIN (COSTS OFF)
SELECT a, a <-> '21472.79' FROM moneytmp ORDER BY a <-> '21472.79' LIMIT 3;
QUERY PLAN
-----------------------------------------------
QUERY PLAN
--------------------------------------------------
Limit
-> Index Scan using moneyidx on moneytmp
-> Index Only Scan using moneyidx on moneytmp
Order By: (a <-> '$21,472.79'::money)
(3 rows)

View File

@ -64,3 +64,19 @@ SELECT count(*) FROM chartmp WHERE a > '31b0'::char(32);
400
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT * FROM chartmp WHERE a BETWEEN '31a' AND '31c';
QUERY PLAN
---------------------------------------------------------------
Index Only Scan using charidx on chartmp
Index Cond: ((a >= '31a'::bpchar) AND (a <= '31c'::bpchar))
(2 rows)
SELECT * FROM chartmp WHERE a BETWEEN '31a' AND '31c';
a
------
31b0
(1 row)

View File

@ -64,3 +64,19 @@ SELECT count(*) FROM chartmp WHERE a > '31b0'::char(32);
214
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT * FROM chartmp WHERE a BETWEEN '31a' AND '31c';
QUERY PLAN
---------------------------------------------------------------
Index Only Scan using charidx on chartmp
Index Cond: ((a >= '31a'::bpchar) AND (a <= '31c'::bpchar))
(2 rows)
SELECT * FROM chartmp WHERE a BETWEEN '31a' AND '31c';
a
------
31b0
(1 row)

View File

@ -74,10 +74,10 @@ SELECT count(*) FROM datetmp WHERE a > '2001-02-13'::date;
EXPLAIN (COSTS OFF)
SELECT a, a <-> '2001-02-13' FROM datetmp ORDER BY a <-> '2001-02-13' LIMIT 3;
QUERY PLAN
----------------------------------------------
QUERY PLAN
------------------------------------------------
Limit
-> Index Scan using dateidx on datetmp
-> Index Only Scan using dateidx on datetmp
Order By: (a <-> '02-13-2001'::date)
(3 rows)

View File

@ -74,10 +74,10 @@ SELECT count(*) FROM float4tmp WHERE a > -179.0::float4;
EXPLAIN (COSTS OFF)
SELECT a, a <-> '-179.0' FROM float4tmp ORDER BY a <-> '-179.0' LIMIT 3;
QUERY PLAN
-----------------------------------------------
QUERY PLAN
----------------------------------------------------
Limit
-> Index Scan using float4idx on float4tmp
-> Index Only Scan using float4idx on float4tmp
Order By: (a <-> (-179)::real)
(3 rows)

View File

@ -77,7 +77,7 @@ SELECT a, a <-> '-1890.0' FROM float8tmp ORDER BY a <-> '-1890.0' LIMIT 3;
QUERY PLAN
-----------------------------------------------------
Limit
-> Index Scan using float8idx on float8tmp
-> Index Only Scan using float8idx on float8tmp
Order By: (a <-> (-1890)::double precision)
(3 rows)

View File

@ -74,10 +74,10 @@ SELECT count(*) FROM int2tmp WHERE a > 237::int2;
EXPLAIN (COSTS OFF)
SELECT a, a <-> '237' FROM int2tmp ORDER BY a <-> '237' LIMIT 3;
QUERY PLAN
-------------------------------------------
QUERY PLAN
------------------------------------------------
Limit
-> Index Scan using int2idx on int2tmp
-> Index Only Scan using int2idx on int2tmp
Order By: (a <-> 237::smallint)
(3 rows)

View File

@ -74,10 +74,10 @@ SELECT count(*) FROM int4tmp WHERE a > 237::int4;
EXPLAIN (COSTS OFF)
SELECT a, a <-> '237' FROM int4tmp ORDER BY a <-> '237' LIMIT 3;
QUERY PLAN
-------------------------------------------
QUERY PLAN
------------------------------------------------
Limit
-> Index Scan using int4idx on int4tmp
-> Index Only Scan using int4idx on int4tmp
Order By: (a <-> 237)
(3 rows)

View File

@ -77,7 +77,7 @@ SELECT a, a <-> '464571291354841' FROM int8tmp ORDER BY a <-> '464571291354841'
QUERY PLAN
---------------------------------------------------
Limit
-> Index Scan using int8idx on int8tmp
-> Index Only Scan using int8idx on int8tmp
Order By: (a <-> 464571291354841::bigint)
(3 rows)

View File

@ -77,7 +77,7 @@ SELECT a, a <-> '199 days 21:21:23' FROM intervaltmp ORDER BY a <-> '199 days 21
QUERY PLAN
---------------------------------------------------------------------------
Limit
-> Index Scan using intervalidx on intervaltmp
-> Index Only Scan using intervalidx on intervaltmp
Order By: (a <-> '@ 199 days 21 hours 21 mins 23 secs'::interval)
(3 rows)

View File

@ -64,3 +64,26 @@ SELECT count(*) FROM macaddrtmp WHERE a > '22:00:5c:e5:9b:0d'::macaddr;
540
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT * FROM macaddrtmp WHERE a < '02:03:04:05:06:07'::macaddr;
QUERY PLAN
--------------------------------------------------
Index Only Scan using macaddridx on macaddrtmp
Index Cond: (a < '02:03:04:05:06:07'::macaddr)
(2 rows)
SELECT * FROM macaddrtmp WHERE a < '02:03:04:05:06:07'::macaddr;
a
-------------------
01:02:37:05:4f:36
01:02:37:05:4f:36
01:02:37:05:4f:36
01:02:37:05:4f:36
01:43:b5:79:eb:0f
01:43:b5:79:eb:0f
01:43:b5:79:eb:0f
01:43:b5:79:eb:0f
(8 rows)

View File

@ -186,3 +186,22 @@ SELECT count(*) FROM numerictmp WHERE a > 0 ;
576
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT * FROM numerictmp WHERE a BETWEEN 1 AND 300 ORDER BY a;
QUERY PLAN
-----------------------------------------------------------------
Sort
Sort Key: a
-> Index Only Scan using numericidx on numerictmp
Index Cond: ((a >= 1::numeric) AND (a <= 300::numeric))
(4 rows)
SELECT * FROM numerictmp WHERE a BETWEEN 1 AND 300 ORDER BY a;
a
------------
204.035430
207.400532
(2 rows)

View File

@ -71,3 +71,19 @@ SELECT count(*) FROM texttmp WHERE a = '2eb2c961c1cbf6 cf8d7b68cb9a2f36 7bbedb
1
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT * FROM texttmp WHERE a BETWEEN '31a' AND '31c';
QUERY PLAN
-----------------------------------------------------------
Index Only Scan using textidx on texttmp
Index Cond: ((a >= '31a'::text) AND (a <= '31c'::text))
(2 rows)
SELECT * FROM texttmp WHERE a BETWEEN '31a' AND '31c';
a
------
31b0
(1 row)

View File

@ -71,3 +71,19 @@ SELECT count(*) FROM texttmp WHERE a = '2eb2c961c1cbf6 cf8d7b68cb9a2f36 7bbedb
1
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT * FROM texttmp WHERE a BETWEEN '31a' AND '31c';
QUERY PLAN
-----------------------------------------------------------
Index Only Scan using textidx on texttmp
Index Cond: ((a >= '31a'::text) AND (a <= '31c'::text))
(2 rows)
SELECT * FROM texttmp WHERE a BETWEEN '31a' AND '31c';
a
------
31b0
(1 row)

View File

@ -77,7 +77,7 @@ SELECT a, a <-> '10:57:11' FROM timetmp ORDER BY a <-> '10:57:11' LIMIT 3;
QUERY PLAN
--------------------------------------------------------------
Limit
-> Index Scan using timeidx on timetmp
-> Index Only Scan using timeidx on timetmp
Order By: (a <-> '10:57:11'::time without time zone)
(3 rows)

View File

@ -77,7 +77,7 @@ SELECT a, a <-> '2004-10-26 08:55:08' FROM timestamptmp ORDER BY a <-> '2004-10-
QUERY PLAN
-----------------------------------------------------------------------------------
Limit
-> Index Scan using timestampidx on timestamptmp
-> Index Only Scan using timestampidx on timestamptmp
Order By: (a <-> 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(3 rows)

View File

@ -197,7 +197,7 @@ SELECT a, a <-> '2018-12-18 10:59:54 GMT+2' FROM timestamptztmp ORDER BY a <-> '
QUERY PLAN
------------------------------------------------------------------------------------
Limit
-> Index Scan using timestamptzidx on timestamptztmp
-> Index Only Scan using timestamptzidx on timestamptztmp
Order By: (a <-> 'Tue Dec 18 04:59:54 2018 PST'::timestamp with time zone)
(3 rows)

View File

@ -64,3 +64,13 @@ SELECT count(*) FROM varbittmp WHERE a > '1110100111010'::varbit;
50
(1 row)
-- Test index-only scans
SET enable_bitmapscan=off;
EXPLAIN (COSTS OFF)
SELECT a FROM bittmp WHERE a BETWEEN '1000000' and '1000001';
QUERY PLAN
-----------------------------------------------------------------------
Index Only Scan using bitidx on bittmp
Index Cond: ((a >= B'1000000'::"bit") AND (a <= B'1000001'::"bit"))
(2 rows)