@@ -1554,15 +1554,19 @@ SELECT cube(array[40,50,60], array[10,20,30])~>3;
15541554(1 row)
15551555
15561556SELECT cube(array[40,50,60], array[10,20,30])~>0;
1557- ERROR: cube index 0 is out of bounds
1557+ ERROR: zero cube index is not defined
15581558SELECT cube(array[40,50,60], array[10,20,30])~>4;
15591559 ?column?
15601560----------
15611561 50
15621562(1 row)
15631563
15641564SELECT cube(array[40,50,60], array[10,20,30])~>(-1);
1565- ERROR: cube index -1 is out of bounds
1565+ ?column?
1566+ ----------
1567+ -10
1568+ (1 row)
1569+
15661570-- Load some example data and build the index
15671571--
15681572CREATE TABLE test_cube (c cube);
@@ -1726,6 +1730,86 @@ SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper boun
17261730 266 | (22684, 266),(22656, 181)
17271731(15 rows)
17281732
1733+ SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
1734+ ?column? | c
1735+ ----------+-------------------------------
1736+ -100000 | (100000)
1737+ -49951 | (50027, 49230),(49951, 49214)
1738+ -49937 | (49980, 35004),(49937, 34963)
1739+ -49927 | (49985, 6436),(49927, 6338)
1740+ -49908 | (49999, 27218),(49908, 27176)
1741+ -49905 | (49954, 1340),(49905, 1294)
1742+ -49902 | (49944, 25163),(49902, 25153)
1743+ -49898 | (49981, 34876),(49898, 34786)
1744+ -49897 | (49957, 43390),(49897, 43384)
1745+ -49848 | (49853, 18504),(49848, 18503)
1746+ -49818 | (49902, 41752),(49818, 41746)
1747+ -49810 | (49907, 30225),(49810, 30158)
1748+ -49808 | (49843, 5175),(49808, 5145)
1749+ -49805 | (49887, 24274),(49805, 24184)
1750+ -49798 | (49847, 7128),(49798, 7067)
1751+ (15 rows)
1752+
1753+ SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
1754+ ?column? | c
1755+ ----------+-------------------------------
1756+ -100000 | (100000)
1757+ -50027 | (50027, 49230),(49951, 49214)
1758+ -49999 | (49999, 27218),(49908, 27176)
1759+ -49985 | (49985, 6436),(49927, 6338)
1760+ -49981 | (49981, 34876),(49898, 34786)
1761+ -49980 | (49980, 35004),(49937, 34963)
1762+ -49957 | (49957, 43390),(49897, 43384)
1763+ -49954 | (49954, 1340),(49905, 1294)
1764+ -49944 | (49944, 25163),(49902, 25153)
1765+ -49907 | (49907, 30225),(49810, 30158)
1766+ -49902 | (49902, 41752),(49818, 41746)
1767+ -49887 | (49887, 24274),(49805, 24184)
1768+ -49853 | (49853, 18504),(49848, 18503)
1769+ -49847 | (49847, 7128),(49798, 7067)
1770+ -49843 | (49843, 5175),(49808, 5145)
1771+ (15 rows)
1772+
1773+ SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
1774+ ?column? | c
1775+ ----------+-------------------------------
1776+ -100000 | (0, 100000)
1777+ -49992 | (30746, 50040),(30727, 49992)
1778+ -49987 | (36311, 50073),(36258, 49987)
1779+ -49934 | (3531, 49962),(3463, 49934)
1780+ -49915 | (17954, 49975),(17865, 49915)
1781+ -49914 | (2168, 50012),(2108, 49914)
1782+ -49913 | (31287, 49923),(31236, 49913)
1783+ -49885 | (21551, 49983),(21492, 49885)
1784+ -49878 | (43925, 49912),(43888, 49878)
1785+ -49849 | (19128, 49932),(19112, 49849)
1786+ -49844 | (38266, 49852),(38233, 49844)
1787+ -49836 | (14913, 49873),(14849, 49836)
1788+ -49834 | (37595, 49849),(37581, 49834)
1789+ -49830 | (46151, 49848),(46058, 49830)
1790+ -49818 | (29261, 49910),(29247, 49818)
1791+ (15 rows)
1792+
1793+ SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
1794+ ?column? | c
1795+ ----------+-------------------------------
1796+ -100000 | (0, 100000)
1797+ -50073 | (36311, 50073),(36258, 49987)
1798+ -50040 | (30746, 50040),(30727, 49992)
1799+ -50012 | (2168, 50012),(2108, 49914)
1800+ -49983 | (21551, 49983),(21492, 49885)
1801+ -49975 | (17954, 49975),(17865, 49915)
1802+ -49962 | (3531, 49962),(3463, 49934)
1803+ -49932 | (19128, 49932),(19112, 49849)
1804+ -49923 | (31287, 49923),(31236, 49913)
1805+ -49912 | (43925, 49912),(43888, 49878)
1806+ -49910 | (29261, 49910),(29247, 49818)
1807+ -49873 | (14913, 49873),(14849, 49836)
1808+ -49858 | (20007, 49858),(19921, 49778)
1809+ -49852 | (38266, 49852),(38233, 49844)
1810+ -49849 | (37595, 49849),(37581, 49834)
1811+ (15 rows)
1812+
17291813-- Same queries with sequential scan (should give the same results as above)
17301814RESET enable_seqscan;
17311815SET enable_indexscan = OFF;
@@ -1839,4 +1923,84 @@ SELECT c~>4, c FROM test_cube ORDER BY c~>4 LIMIT 15; -- ascending by upper boun
18391923 266 | (22684, 266),(22656, 181)
18401924(15 rows)
18411925
1926+ SELECT c~>(-1), c FROM test_cube ORDER BY c~>(-1) LIMIT 15; -- descending by left bound
1927+ ?column? | c
1928+ ----------+-------------------------------
1929+ -100000 | (100000)
1930+ -49951 | (50027, 49230),(49951, 49214)
1931+ -49937 | (49980, 35004),(49937, 34963)
1932+ -49927 | (49985, 6436),(49927, 6338)
1933+ -49908 | (49999, 27218),(49908, 27176)
1934+ -49905 | (49954, 1340),(49905, 1294)
1935+ -49902 | (49944, 25163),(49902, 25153)
1936+ -49898 | (49981, 34876),(49898, 34786)
1937+ -49897 | (49957, 43390),(49897, 43384)
1938+ -49848 | (49853, 18504),(49848, 18503)
1939+ -49818 | (49902, 41752),(49818, 41746)
1940+ -49810 | (49907, 30225),(49810, 30158)
1941+ -49808 | (49843, 5175),(49808, 5145)
1942+ -49805 | (49887, 24274),(49805, 24184)
1943+ -49798 | (49847, 7128),(49798, 7067)
1944+ (15 rows)
1945+
1946+ SELECT c~>(-2), c FROM test_cube ORDER BY c~>(-2) LIMIT 15; -- descending by right bound
1947+ ?column? | c
1948+ ----------+-------------------------------
1949+ -100000 | (100000)
1950+ -50027 | (50027, 49230),(49951, 49214)
1951+ -49999 | (49999, 27218),(49908, 27176)
1952+ -49985 | (49985, 6436),(49927, 6338)
1953+ -49981 | (49981, 34876),(49898, 34786)
1954+ -49980 | (49980, 35004),(49937, 34963)
1955+ -49957 | (49957, 43390),(49897, 43384)
1956+ -49954 | (49954, 1340),(49905, 1294)
1957+ -49944 | (49944, 25163),(49902, 25153)
1958+ -49907 | (49907, 30225),(49810, 30158)
1959+ -49902 | (49902, 41752),(49818, 41746)
1960+ -49887 | (49887, 24274),(49805, 24184)
1961+ -49853 | (49853, 18504),(49848, 18503)
1962+ -49847 | (49847, 7128),(49798, 7067)
1963+ -49843 | (49843, 5175),(49808, 5145)
1964+ (15 rows)
1965+
1966+ SELECT c~>(-3), c FROM test_cube ORDER BY c~>(-3) LIMIT 15; -- descending by lower bound
1967+ ?column? | c
1968+ ----------+-------------------------------
1969+ -100000 | (0, 100000)
1970+ -49992 | (30746, 50040),(30727, 49992)
1971+ -49987 | (36311, 50073),(36258, 49987)
1972+ -49934 | (3531, 49962),(3463, 49934)
1973+ -49915 | (17954, 49975),(17865, 49915)
1974+ -49914 | (2168, 50012),(2108, 49914)
1975+ -49913 | (31287, 49923),(31236, 49913)
1976+ -49885 | (21551, 49983),(21492, 49885)
1977+ -49878 | (43925, 49912),(43888, 49878)
1978+ -49849 | (19128, 49932),(19112, 49849)
1979+ -49844 | (38266, 49852),(38233, 49844)
1980+ -49836 | (14913, 49873),(14849, 49836)
1981+ -49834 | (37595, 49849),(37581, 49834)
1982+ -49830 | (46151, 49848),(46058, 49830)
1983+ -49818 | (29261, 49910),(29247, 49818)
1984+ (15 rows)
1985+
1986+ SELECT c~>(-4), c FROM test_cube ORDER BY c~>(-4) LIMIT 15; -- descending by upper bound
1987+ ?column? | c
1988+ ----------+-------------------------------
1989+ -100000 | (0, 100000)
1990+ -50073 | (36311, 50073),(36258, 49987)
1991+ -50040 | (30746, 50040),(30727, 49992)
1992+ -50012 | (2168, 50012),(2108, 49914)
1993+ -49983 | (21551, 49983),(21492, 49885)
1994+ -49975 | (17954, 49975),(17865, 49915)
1995+ -49962 | (3531, 49962),(3463, 49934)
1996+ -49932 | (19128, 49932),(19112, 49849)
1997+ -49923 | (31287, 49923),(31236, 49913)
1998+ -49912 | (43925, 49912),(43888, 49878)
1999+ -49910 | (29261, 49910),(29247, 49818)
2000+ -49873 | (14913, 49873),(14849, 49836)
2001+ -49858 | (20007, 49858),(19921, 49778)
2002+ -49852 | (38266, 49852),(38233, 49844)
2003+ -49849 | (37595, 49849),(37581, 49834)
2004+ (15 rows)
2005+
18422006RESET enable_indexscan;
0 commit comments