SELECT b[1:1][2][2],
d[1:1][2]
- FROM arrtest;
+ FROM arrtest ORDER BY 1, 2;
b | d
-----------------------+---------------
- {{{113,142},{1,147}}} | {}
{} | {}
{} | {{elt1,elt2}}
+ {{{113,142},{1,147}}} | {}
(3 rows)
INSERT INTO arrtest(a) VALUES('{1,null,3}');
);
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
a | b
-------------------+--------------------------------------
- {1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
[0:4]={1,2,3,4,5} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
+ {1,2,3,4,5} | {{1,2,3},{4,5,6},{7,8,9}}
(2 rows)
-SELECT a[:3], b[:2][:2] FROM arrtest_s;
+SELECT a[:3], b[:2][:2] FROM arrtest_s ORDER BY a, b;
a | b
-----------+---------------------------
{1,2,3} | {{1,2},{4,5}}
{1,2,3,4} | {{1,2,3},{4,5,6},{7,8,9}}
(2 rows)
-SELECT a[2:], b[2:][2:] FROM arrtest_s;
+SELECT a[2:], b[2:][2:] FROM arrtest_s ORDER BY a, b;
a | b
-----------+---------------
{2,3,4,5} | {{5,6},{8,9}}
-- updates
UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{11,12}, {14,15}}'
WHERE array_lower(a,1) = 1;
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
a | b
-------------------+--------------------------------------
[0:4]={1,2,3,4,5} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,9}}
(2 rows)
UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{25,26}, {28,29}}';
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
a | b
---------------------+---------------------------------------
[0:4]={1,2,3,23,24} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,25}}
(2 rows)
UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}';
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
a | b
------------------------+---------------------------------------
[0:4]={11,12,13,14,15} | [0:2][0:2]={{1,2,3},{4,5,6},{7,8,25}}
--
-- Test Index-only plans on GiST indexes
--
-create table gist_tbl (b box, p point, c circle);
+create table gist_tbl (b box, p point, c circle) distribute by replication;
insert into gist_tbl
select box(point(0.05*i, 0.05*i), point(0.05*i, 0.05*i)),
point(0.05*i, 0.05*i),
QUERY PLAN
--------------------------------------------------------------
Remote Fast Query Execution
- Node/s: datanode_1, datanode_2
+ Node/s: datanode_1
-> Index Only Scan using gist_tbl_point_index on gist_tbl
Index Cond: (p <@ '(0.5,0.5),(0,0)'::box)
(4 rows)
p
-------------
(0,0)
- (0.1,0.1)
- (0.2,0.2)
- (0.3,0.3)
- (0.4,0.4)
- (0.5,0.5)
(0.05,0.05)
+ (0.1,0.1)
(0.15,0.15)
+ (0.2,0.2)
(0.25,0.25)
+ (0.3,0.3)
(0.35,0.35)
+ (0.4,0.4)
(0.45,0.45)
+ (0.5,0.5)
(11 rows)
-- Also test an index-only knn-search
order by p <-> point(0.201, 0.201);
QUERY PLAN
--------------------------------------------------------------
- Remote Subquery Scan on all (datanode_1,datanode_2)
+ Remote Fast Query Execution
+ Node/s: datanode_1
-> Index Only Scan using gist_tbl_point_index on gist_tbl
Index Cond: (p <@ '(0.5,0.5),(0,0)'::box)
Order By: (p <-> '(0.201,0.201)'::point)
-(4 rows)
+(5 rows)
select p from gist_tbl where p <@ box(point(0,0), point(0.5, 0.5))
order by p <-> point(0.201, 0.201);
order by point(0.101, 0.101) <-> p;
QUERY PLAN
--------------------------------------------------------------
- Remote Subquery Scan on all (datanode_1,datanode_2)
+ Remote Fast Query Execution
+ Node/s: datanode_1
-> Index Only Scan using gist_tbl_point_index on gist_tbl
Index Cond: (p <@ '(0.5,0.5),(0,0)'::box)
Order By: (p <-> '(0.101,0.101)'::point)
-(4 rows)
+(5 rows)
select p from gist_tbl where p <@ box(point(0,0), point(0.5, 0.5))
order by point(0.101, 0.101) <-> p;
QUERY PLAN
------------------------------------------------------------
Remote Fast Query Execution
- Node/s: datanode_1, datanode_2
+ Node/s: datanode_1
-> Index Only Scan using gist_tbl_box_index on gist_tbl
Index Cond: (b <@ '(6,6),(5,5)'::box)
(4 rows)
b
-------------------------
(5,5),(5,5)
- (5.1,5.1),(5.1,5.1)
- (5.2,5.2),(5.2,5.2)
- (5.3,5.3),(5.3,5.3)
- (5.4,5.4),(5.4,5.4)
- (5.5,5.5),(5.5,5.5)
- (5.6,5.6),(5.6,5.6)
- (5.7,5.7),(5.7,5.7)
- (5.8,5.8),(5.8,5.8)
- (5.9,5.9),(5.9,5.9)
- (6,6),(6,6)
(5.05,5.05),(5.05,5.05)
+ (5.1,5.1),(5.1,5.1)
(5.15,5.15),(5.15,5.15)
+ (5.2,5.2),(5.2,5.2)
(5.25,5.25),(5.25,5.25)
+ (5.3,5.3),(5.3,5.3)
(5.35,5.35),(5.35,5.35)
+ (5.4,5.4),(5.4,5.4)
(5.45,5.45),(5.45,5.45)
+ (5.5,5.5),(5.5,5.5)
(5.55,5.55),(5.55,5.55)
+ (5.6,5.6),(5.6,5.6)
(5.65,5.65),(5.65,5.65)
+ (5.7,5.7),(5.7,5.7)
(5.75,5.75),(5.75,5.75)
+ (5.8,5.8),(5.8,5.8)
(5.85,5.85),(5.85,5.85)
+ (5.9,5.9),(5.9,5.9)
(5.95,5.95),(5.95,5.95)
+ (6,6),(6,6)
(21 rows)
drop index gist_tbl_box_index;
QUERY PLAN
---------------------------------------------------------
Remote Fast Query Execution
- Node/s: datanode_1, datanode_2
+ Node/s: datanode_1
-> Index Scan using gist_tbl_multi_index on gist_tbl
Index Cond: (p <@ '(6,6),(5,5)'::box)
(4 rows)
b | p
-------------------------+-------------
(5,5),(5,5) | (5,5)
- (5.1,5.1),(5.1,5.1) | (5.1,5.1)
- (5.2,5.2),(5.2,5.2) | (5.2,5.2)
- (5.3,5.3),(5.3,5.3) | (5.3,5.3)
- (5.4,5.4),(5.4,5.4) | (5.4,5.4)
- (5.5,5.5),(5.5,5.5) | (5.5,5.5)
(5.05,5.05),(5.05,5.05) | (5.05,5.05)
+ (5.1,5.1),(5.1,5.1) | (5.1,5.1)
(5.15,5.15),(5.15,5.15) | (5.15,5.15)
+ (5.2,5.2),(5.2,5.2) | (5.2,5.2)
(5.25,5.25),(5.25,5.25) | (5.25,5.25)
+ (5.3,5.3),(5.3,5.3) | (5.3,5.3)
(5.35,5.35),(5.35,5.35) | (5.35,5.35)
+ (5.4,5.4),(5.4,5.4) | (5.4,5.4)
(5.45,5.45),(5.45,5.45) | (5.45,5.45)
+ (5.5,5.5),(5.5,5.5) | (5.5,5.5)
(11 rows)
drop index gist_tbl_multi_index;
(1 row)
-- check the conversion to/from text and set_netmask
-SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
+SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL ORDER BY 1, 2;
ten | set_masklen
-----+------------------
- | 192.168.1.226/24
- | 192.168.1.226/24
- | 192.168.1.0/24
- | 192.168.1.0/24
- | 192.168.1.255/24
- | 192.168.1.255/24
+ | 9.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 10.1.2.3/24
| 11.1.2.3/24
- | 9.1.2.3/24
+ | 192.168.1.0/24
+ | 192.168.1.0/24
+ | 192.168.1.226/24
+ | 192.168.1.226/24
+ | 192.168.1.255/24
+ | 192.168.1.255/24
+ | ::4.3.2.1/24
| 10:23::f1/24
| 10:23::ffff/24
- | ::4.3.2.1/24
(17 rows)
-- check that btree index works correctly
---+---
(0 rows)
-SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i;
+SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i, c;
c | i
-------------+-------------
10.0.0.0/8 | 9.1.2.3/8
- 10.0.0.0/32 | 10.1.2.3/8
10.0.0.0/8 | 10.1.2.3/8
10.0.0.0/8 | 10.1.2.3/8
+ 10.0.0.0/32 | 10.1.2.3/8
10.1.0.0/16 | 10.1.2.3/16
10.1.2.0/24 | 10.1.2.3/24
10.1.2.3/32 | 10.1.2.3
10.0.0.0/8 | 11.1.2.3/8
(8 rows)
-SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i;
+SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i, c;
c | i
----------------+----------------
10.0.0.0/8 | 9.1.2.3/8
10.0.0.0/8 | 10.1.2.3/8
- 10.0.0.0/32 | 10.1.2.3/8
10.0.0.0/8 | 10.1.2.3/8
+ 10.0.0.0/32 | 10.1.2.3/8
10.1.0.0/16 | 10.1.2.3/16
10.1.2.0/24 | 10.1.2.3/24
10.1.2.3/32 | 10.1.2.3
10:23::8000/113 | 10:23::ffff
(8 rows)
-SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i;
+SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i, c;
c | i
--------------------+------------------
10.0.0.0/8 | 9.1.2.3/8
10.0.0.0/8 | 10.1.2.3/8
- 10.0.0.0/32 | 10.1.2.3/8
10.0.0.0/8 | 10.1.2.3/8
+ 10.0.0.0/32 | 10.1.2.3/8
10.1.0.0/16 | 10.1.2.3/16
10.1.2.0/24 | 10.1.2.3/24
10.1.2.3/32 | 10.1.2.3
SELECT inet_merge(c, i) FROM INET_TBL;
ERROR: cannot merge addresses from different families
-- fix it by inet_same_family() condition
-SELECT inet_merge(c, i) FROM INET_TBL WHERE inet_same_family(c, i);
+SELECT inet_merge(c, i) FROM INET_TBL WHERE inet_same_family(c, i) ORDER BY 1;
inet_merge
-----------------
+ 8.0.0.0/6
+ 10.0.0.0/7
+ 10.0.0.0/8
+ 10.0.0.0/8
+ 10.0.0.0/8
+ 10.1.0.0/16
+ 10.1.2.0/24
+ 10.1.2.3/32
192.168.1.0/24
192.168.1.0/24
192.168.1.0/24
192.168.1.0/24
192.168.1.0/24
192.168.1.0/24
- 10.0.0.0/8
- 10.0.0.0/8
- 10.1.2.3/32
- 10.1.2.0/24
- 10.1.0.0/16
- 10.0.0.0/8
- 10.0.0.0/7
- 8.0.0.0/6
+ ::/24
10:23::/64
10:23::8000/113
- ::/24
(17 rows)
{"a": [["b", {"x": 1}], ["b", {"x": 2}]], "c": 3}
(1 row)
-select * from nestjsonb where j @> '[[14]]';
+select * from nestjsonb where j @> '[[14]]' order by j;
j
-----------------
[[14, 2, 3]]
{"a": [["b", {"x": 1}], ["b", {"x": 2}]], "c": 3}
(1 row)
-select * from nestjsonb where j @> '[[14]]';
+select * from nestjsonb where j @> '[[14]]' order by j;
j
-----------------
[[14, 2, 3]]
-- Infinite lines
--
--DROP TABLE LINE_TBL;
-CREATE TABLE LINE_TBL (s line);
+CREATE TABLE LINE_TBL (s line) DISTRIBUTE BY REPLICATION;
INSERT INTO LINE_TBL VALUES ('{1,-1,1}');
INSERT INTO LINE_TBL VALUES ('(0,0),(6,6)');
INSERT INTO LINE_TBL VALUES ('10,-10 ,-5,-4');
during tsrange,
exclude using gist (room with =, during with &&),
exclude using gist (speaker with =, during with &&)
-);
+) distribute by replication;
insert into test_range_excl
values(int4range(123, 123, '[]'), int4range(1, 1, '[]'), '[2010-01-02 10:00, 2010-01-02 11:00)');
insert into test_range_excl
SELECT b[1:1][2][2],
d[1:1][2]
- FROM arrtest;
+ FROM arrtest ORDER BY 1, 2;
INSERT INTO arrtest(a) VALUES('{1,null,3}');
SELECT a FROM arrtest ORDER BY 1;
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
-SELECT * FROM arrtest_s;
-SELECT a[:3], b[:2][:2] FROM arrtest_s;
-SELECT a[2:], b[2:][2:] FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
+SELECT a[:3], b[:2][:2] FROM arrtest_s ORDER BY a, b;
+SELECT a[2:], b[2:][2:] FROM arrtest_s ORDER BY a, b;
SELECT a[:], b[:] FROM arrtest_s;
-- updates
UPDATE arrtest_s SET a[:3] = '{11, 12, 13}', b[:2][:2] = '{{11,12}, {14,15}}'
WHERE array_lower(a,1) = 1;
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
UPDATE arrtest_s SET a[3:] = '{23, 24, 25}', b[2:][2:] = '{{25,26}, {28,29}}';
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}';
-SELECT * FROM arrtest_s;
+SELECT * FROM arrtest_s ORDER BY a, b;
UPDATE arrtest_s SET a[:] = '{23, 24, 25}'; -- fail, too small
INSERT INTO arrtest_s VALUES(NULL, NULL);
UPDATE arrtest_s SET a[:] = '{11, 12, 13, 14, 15}'; -- fail, no good with null
-- Test Index-only plans on GiST indexes
--
-create table gist_tbl (b box, p point, c circle);
+create table gist_tbl (b box, p point, c circle) distribute by replication;
insert into gist_tbl
select box(point(0.05*i, 0.05*i), point(0.05*i, 0.05*i)),
SELECT max(c) AS max, min(c) AS min FROM INET_TBL;
-- check the conversion to/from text and set_netmask
-SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
+SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL ORDER BY 1, 2;
-- check that btree index works correctly
CREATE INDEX inet_idx1 ON inet_tbl(i);
SELECT * FROM inet_tbl WHERE i && '192.168.1.0/24'::cidr ORDER BY i;
SELECT * FROM inet_tbl WHERE i >>= '192.168.1.0/24'::cidr ORDER BY i;
SELECT * FROM inet_tbl WHERE i >> '192.168.1.0/24'::cidr ORDER BY i;
-SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i;
-SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i;
+SELECT * FROM inet_tbl WHERE i < '192.168.1.0/24'::cidr ORDER BY i, c;
+SELECT * FROM inet_tbl WHERE i <= '192.168.1.0/24'::cidr ORDER BY i, c;
SELECT * FROM inet_tbl WHERE i = '192.168.1.0/24'::cidr ORDER BY i;
SELECT * FROM inet_tbl WHERE i >= '192.168.1.0/24'::cidr ORDER BY i;
SELECT * FROM inet_tbl WHERE i > '192.168.1.0/24'::cidr ORDER BY i;
-SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i;
+SELECT * FROM inet_tbl WHERE i <> '192.168.1.0/24'::cidr ORDER BY i, c;
-- test index-only scans
EXPLAIN (COSTS OFF)
-- now, this one should fail
SELECT inet_merge(c, i) FROM INET_TBL;
-- fix it by inet_same_family() condition
-SELECT inet_merge(c, i) FROM INET_TBL WHERE inet_same_family(c, i);
+SELECT inet_merge(c, i) FROM INET_TBL WHERE inet_same_family(c, i) ORDER BY 1;
set enable_bitmapscan = off;
select * from nestjsonb where j @> '{"a":[[{"x":2}]]}'::jsonb;
select * from nestjsonb where j @> '{"c":3}';
-select * from nestjsonb where j @> '[[14]]';
+select * from nestjsonb where j @> '[[14]]' order by j;
set enable_seqscan = off;
set enable_bitmapscan = on;
select * from nestjsonb where j @> '{"a":[[{"x":2}]]}'::jsonb;
select * from nestjsonb where j @> '{"c":3}';
-select * from nestjsonb where j @> '[[14]]';
+select * from nestjsonb where j @> '[[14]]' order by j;
reset enable_seqscan;
reset enable_bitmapscan;
--
--DROP TABLE LINE_TBL;
-CREATE TABLE LINE_TBL (s line);
+CREATE TABLE LINE_TBL (s line) DISTRIBUTE BY REPLICATION;
INSERT INTO LINE_TBL VALUES ('{1,-1,1}');
INSERT INTO LINE_TBL VALUES ('(0,0),(6,6)');
during tsrange,
exclude using gist (room with =, during with &&),
exclude using gist (speaker with =, during with &&)
-);
+) distribute by replication;
insert into test_range_excl
values(int4range(123, 123, '[]'), int4range(1, 1, '[]'), '[2010-01-02 10:00, 2010-01-02 11:00)');