Skip to content

Commit 892ecb4

Browse files
committed
Add regression tests for part tables
1 parent a15bef5 commit 892ecb4

File tree

6 files changed

+180
-2
lines changed

6 files changed

+180
-2
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/lib/pq v1.10.9
2121
github.com/libp2p/go-reuseport v0.4.0
2222
github.com/opentracing/opentracing-go v1.2.0
23-
github.com/pg-sharding/lyx v0.0.0-20241121162747-96974c4732ca
23+
github.com/pg-sharding/lyx v0.0.0-20241220063316-440788a6dff7
2424
github.com/pkg/errors v0.9.1
2525
github.com/rs/zerolog v1.33.0
2626
github.com/sevlyar/go-daemon v0.1.6

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
166166
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
167167
github.com/pg-sharding/lyx v0.0.0-20241121162747-96974c4732ca h1:BDLxfrLVBfEUTqmOunYbtYVW0DAiwiArUFuKo1L3fpU=
168168
github.com/pg-sharding/lyx v0.0.0-20241121162747-96974c4732ca/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
169+
github.com/pg-sharding/lyx v0.0.0-20241210102931-535cefdc0a05 h1:dfJU//ioyB527afamLk0Rhvk7cxP+dg0A8akXKOG8JI=
170+
github.com/pg-sharding/lyx v0.0.0-20241210102931-535cefdc0a05/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
171+
github.com/pg-sharding/lyx v0.0.0-20241220055224-7c1f61d714fa h1:YDYN4134eiAw50gsX/gb6APT290yg2OtjqaAI5fuNII=
172+
github.com/pg-sharding/lyx v0.0.0-20241220055224-7c1f61d714fa/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
173+
github.com/pg-sharding/lyx v0.0.0-20241220063316-440788a6dff7 h1:2W5vNsu5ldyLVSbfP+oMf0WaiAqoIKjf0h91h8VbSTo=
174+
github.com/pg-sharding/lyx v0.0.0-20241220063316-440788a6dff7/go.mod h1:2dPBQAhqv/30mhzj2yBXQkXhsGJQ8GhM+oWOfbGua58=
169175
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
170176
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
171177
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

router/qrouter/proxy_routing.go

+12
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,18 @@ func (qr *ProxyQrouter) CheckTableIsRoutable(ctx context.Context, node *lyx.Crea
686686
var err error
687687
var ds *distributions.Distribution
688688
var relname string
689+
690+
if node.PartitionOf != nil {
691+
switch q := node.PartitionOf.(type) {
692+
case *lyx.RangeVar:
693+
relname = q.RelationName
694+
_, err = qr.mgr.GetRelationDistribution(ctx, relname)
695+
return err
696+
default:
697+
return fmt.Errorf("Partition of is not a range var")
698+
}
699+
}
700+
689701
switch q := node.TableRv.(type) {
690702
case *lyx.RangeVar:
691703
relname = q.RelationName

test/regress/schedule/router

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ test: alter_distribution
1616
test: show_processing
1717
test: copy_multishard
1818
test: copy_reference_table
19-
19+
test: part_table
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
-- Check partitioned tables.
2+
\c spqr-console
3+
4+
SPQR router admin console
5+
Here you can configure your routing rules
6+
------------------------------------------------
7+
You can find documentation here
8+
https://github.com/pg-sharding/spqr/tree/master/docs
9+
10+
-- SETUP
11+
CREATE DISTRIBUTION ds1 COLUMN TYPES varchar hash;
12+
add distribution
13+
------------------------
14+
distribution id -> ds1
15+
(1 row)
16+
17+
CREATE KEY RANGE krid1 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1;
18+
add key range
19+
---------------
20+
bound -> 0
21+
(1 row)
22+
23+
CREATE KEY RANGE krid2 FROM 2147483648 ROUTE TO sh2 FOR DISTRIBUTION ds1;
24+
add key range
25+
---------------------
26+
bound -> 2147483648
27+
(1 row)
28+
29+
-- the set of all unsigned 32-bit integers (0 to 4294967295)
30+
ALTER DISTRIBUTION ds1 ATTACH RELATION xxhash_part DISTRIBUTION KEY i HASH FUNCTION MURMUR;
31+
attach table
32+
--------------------------------
33+
relation name -> xxhash_part
34+
distribution id -> ds1
35+
(2 rows)
36+
37+
\c regress
38+
CREATE TABLE xxhash_part (i uuid, d date) partition by range (d);
39+
NOTICE: send query to shard(s) : sh1,sh2
40+
create table xxhash_part_1 partition of xxhash_part for values from ('2024-12-01') to ('2024-12-31');
41+
NOTICE: send query to shard(s) : sh1,sh2
42+
create table xxhash_part_2 partition of xxhash_part for values from ('2024-11-01') to ('2024-11-30');
43+
NOTICE: send query to shard(s) : sh1,sh2
44+
create table xxhash_part_3 partition of xxhash_part for values from ('2024-10-01') to ('2024-10-31');
45+
NOTICE: send query to shard(s) : sh1,sh2
46+
insert into xxhash_part (i,d ) values ('b37da10c-25a0-4473-96fd-c3871bd81d00', '2024-12-23');
47+
NOTICE: send query to shard(s) : sh2
48+
insert into xxhash_part (i,d ) values ('b1569ed9-4029-495f-8d7c-02b216528c0a', '2024-12-21');
49+
NOTICE: send query to shard(s) : sh1
50+
insert into xxhash_part (i,d ) values ('0583484b-e407-41e3-9c75-66c1994944c8', '2024-12-20');
51+
NOTICE: send query to shard(s) : sh2
52+
insert into xxhash_part (i,d ) values ('b14f8871-ba67-4244-8fa6-45edabaf6206', '2024-12-22');
53+
NOTICE: send query to shard(s) : sh1
54+
insert into xxhash_part (i,d ) values ('7906fd75-60ae-4e1d-99c5-da19d4b63515', '2024-11-23');
55+
NOTICE: send query to shard(s) : sh2
56+
insert into xxhash_part (i,d ) values ('99d75dea-c62c-4bb3-9d6e-eda36432bda0', '2024-11-21');
57+
NOTICE: send query to shard(s) : sh2
58+
insert into xxhash_part (i,d ) values ('0bd49f01-b01f-4c18-bd44-d75746a7c71c', '2024-11-20');
59+
NOTICE: send query to shard(s) : sh2
60+
insert into xxhash_part (i,d ) values ('3dcd025f-b016-4d1c-aaa8-4f8462f9aa8e', '2024-11-22');
61+
NOTICE: send query to shard(s) : sh1
62+
insert into xxhash_part (i,d ) values ('93043bc0-b6d3-4bb6-b1b4-869d2b4a4967', '2024-10-23');
63+
NOTICE: send query to shard(s) : sh1
64+
insert into xxhash_part (i,d ) values ('f6a01c78-9ce8-4cc3-a78f-32bebc4ccb4a', '2024-10-21');
65+
NOTICE: send query to shard(s) : sh1
66+
insert into xxhash_part (i,d ) values ('b3e31fad-80fa-48df-bcc0-51ffd1594df3', '2024-10-20');
67+
NOTICE: send query to shard(s) : sh2
68+
insert into xxhash_part (i,d ) values ('d15707df-f256-49a5-a693-3feda5afe678', '2024-10-22');
69+
NOTICE: send query to shard(s) : sh2
70+
SELECT * FROM xxhash_part ORDER BY d /* __spqr__execute_on: sh1 */;
71+
NOTICE: send query to shard(s) : sh1
72+
i | d
73+
--------------------------------------+------------
74+
f6a01c78-9ce8-4cc3-a78f-32bebc4ccb4a | 2024-10-21
75+
93043bc0-b6d3-4bb6-b1b4-869d2b4a4967 | 2024-10-23
76+
3dcd025f-b016-4d1c-aaa8-4f8462f9aa8e | 2024-11-22
77+
b1569ed9-4029-495f-8d7c-02b216528c0a | 2024-12-21
78+
b14f8871-ba67-4244-8fa6-45edabaf6206 | 2024-12-22
79+
(5 rows)
80+
81+
SELECT * FROM xxhash_part ORDER BY d /* __spqr__execute_on: sh2 */;
82+
NOTICE: send query to shard(s) : sh2
83+
i | d
84+
--------------------------------------+------------
85+
b3e31fad-80fa-48df-bcc0-51ffd1594df3 | 2024-10-20
86+
d15707df-f256-49a5-a693-3feda5afe678 | 2024-10-22
87+
0bd49f01-b01f-4c18-bd44-d75746a7c71c | 2024-11-20
88+
99d75dea-c62c-4bb3-9d6e-eda36432bda0 | 2024-11-21
89+
7906fd75-60ae-4e1d-99c5-da19d4b63515 | 2024-11-23
90+
0583484b-e407-41e3-9c75-66c1994944c8 | 2024-12-20
91+
b37da10c-25a0-4473-96fd-c3871bd81d00 | 2024-12-23
92+
(7 rows)
93+
94+
--TEARDOWN
95+
DROP TABLE xxhash_part;
96+
NOTICE: send query to shard(s) : sh1,sh2
97+
\c spqr-console
98+
99+
SPQR router admin console
100+
Here you can configure your routing rules
101+
------------------------------------------------
102+
You can find documentation here
103+
https://github.com/pg-sharding/spqr/tree/master/docs
104+
105+
DROP DISTRIBUTION ALL CASCADE;
106+
drop distribution
107+
------------------------
108+
distribution id -> ds1
109+
(1 row)
110+
111+
DROP KEY RANGE ALL;
112+
drop key range
113+
----------------
114+
(0 rows)
115+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
-- Check partitioned tables.
3+
\c spqr-console
4+
5+
-- SETUP
6+
CREATE DISTRIBUTION ds1 COLUMN TYPES varchar hash;
7+
8+
CREATE KEY RANGE krid1 FROM 0 ROUTE TO sh1 FOR DISTRIBUTION ds1;
9+
CREATE KEY RANGE krid2 FROM 2147483648 ROUTE TO sh2 FOR DISTRIBUTION ds1;
10+
11+
-- the set of all unsigned 32-bit integers (0 to 4294967295)
12+
ALTER DISTRIBUTION ds1 ATTACH RELATION xxhash_part DISTRIBUTION KEY i HASH FUNCTION MURMUR;
13+
14+
15+
\c regress
16+
CREATE TABLE xxhash_part (i uuid, d date) partition by range (d);
17+
18+
create table xxhash_part_1 partition of xxhash_part for values from ('2024-12-01') to ('2024-12-31');
19+
create table xxhash_part_2 partition of xxhash_part for values from ('2024-11-01') to ('2024-11-30');
20+
create table xxhash_part_3 partition of xxhash_part for values from ('2024-10-01') to ('2024-10-31');
21+
22+
insert into xxhash_part (i,d ) values ('b37da10c-25a0-4473-96fd-c3871bd81d00', '2024-12-23');
23+
insert into xxhash_part (i,d ) values ('b1569ed9-4029-495f-8d7c-02b216528c0a', '2024-12-21');
24+
insert into xxhash_part (i,d ) values ('0583484b-e407-41e3-9c75-66c1994944c8', '2024-12-20');
25+
insert into xxhash_part (i,d ) values ('b14f8871-ba67-4244-8fa6-45edabaf6206', '2024-12-22');
26+
27+
insert into xxhash_part (i,d ) values ('7906fd75-60ae-4e1d-99c5-da19d4b63515', '2024-11-23');
28+
insert into xxhash_part (i,d ) values ('99d75dea-c62c-4bb3-9d6e-eda36432bda0', '2024-11-21');
29+
insert into xxhash_part (i,d ) values ('0bd49f01-b01f-4c18-bd44-d75746a7c71c', '2024-11-20');
30+
insert into xxhash_part (i,d ) values ('3dcd025f-b016-4d1c-aaa8-4f8462f9aa8e', '2024-11-22');
31+
32+
insert into xxhash_part (i,d ) values ('93043bc0-b6d3-4bb6-b1b4-869d2b4a4967', '2024-10-23');
33+
insert into xxhash_part (i,d ) values ('f6a01c78-9ce8-4cc3-a78f-32bebc4ccb4a', '2024-10-21');
34+
insert into xxhash_part (i,d ) values ('b3e31fad-80fa-48df-bcc0-51ffd1594df3', '2024-10-20');
35+
insert into xxhash_part (i,d ) values ('d15707df-f256-49a5-a693-3feda5afe678', '2024-10-22');
36+
37+
38+
SELECT * FROM xxhash_part ORDER BY d /* __spqr__execute_on: sh1 */;
39+
SELECT * FROM xxhash_part ORDER BY d /* __spqr__execute_on: sh2 */;
40+
41+
--TEARDOWN
42+
DROP TABLE xxhash_part;
43+
\c spqr-console
44+
DROP DISTRIBUTION ALL CASCADE;
45+
DROP KEY RANGE ALL;

0 commit comments

Comments
 (0)