Skip to content

Commit

Permalink
Add test t distinct
Browse files Browse the repository at this point in the history
  • Loading branch information
CBists committed Nov 29, 2023
1 parent af71cf5 commit b5f2e91
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/regress/schedule/router
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ test: single_shard_joins
test: multishard
test: error
test: routing_hint
test: distinct
57 changes: 57 additions & 0 deletions test/regress/tests/router/expected/distinct.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
\c spqr-console

SQPR router admin console
Here you can configure your routing rules
------------------------------------------------
You can find documentation here
https://github.com/pg-sharding/spqr/tree/master/docs

ADD SHARDING RULE t1 COLUMNS id;
add sharding rule
----------------------------------------------------------------------
created sharding rule t1 for table (*) with columns [id, hash: x->x]
(1 row)

ADD KEY RANGE krid1 FROM 1 TO 11 ROUTE TO sh1;
add key range
--------------------------------
created key range from 1 to 11
(1 row)

ADD KEY RANGE krid2 FROM 11 TO 101 ROUTE TO sh2;
add key range
----------------------------------
created key range from 11 to 101
(1 row)

\c regress
CREATE TABLE test_dist(id int);
NOTICE: send query to shard(s) : sh1,sh2
INSERT INTO test_dist(id) VALUES(5);
NOTICE: send query to shard(s) : sh1
INSERT INTO test_dist(id) VALUES(5);
NOTICE: send query to shard(s) : sh1
INSERT INTO test_dist(id) VALUES(5);
NOTICE: send query to shard(s) : sh1
INSERT INTO test_dist(id) VALUES(5);
NOTICE: send query to shard(s) : sh1
INSERT INTO test_dist(id) VALUES(5);
NOTICE: send query to shard(s) : sh1
SELECT id FROM test_dist WHERE id=5;
NOTICE: send query to shard(s) : sh1
id
----
5
5
5
5
5
(5 rows)

SELECT DISTINCT id FROM test_dist WHERE id=5;
NOTICE: send query to shard(s) : sh1
id
----
5
(1 row)

19 changes: 19 additions & 0 deletions test/regress/tests/router/expected/routing_hint.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ INSERT INTO test(id, age) VALUES (10, 16) /*sharding_key: 30*/;
NOTICE: send query to shard(s) : sh2
INSERT INTO test(id, age) VALUES (10, 16) /*sharding_key: 3000*/;
NOTICE: send query to shard(s) : sh1
\c spqr-console

SQPR router admin console
Here you can configure your routing rules
------------------------------------------------
You can find documentation here
https://github.com/pg-sharding/spqr/tree/master/docs

DROP KEY RANGE ALL;
drop key range
----------------
(0 rows)

DROP SHARDING RULE ALL;
drop sharding rule
--------------------------
dropped sharding rule t1
(1 row)

16 changes: 16 additions & 0 deletions test/regress/tests/router/sql/distinct.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\c spqr-console

ADD SHARDING RULE t1 COLUMNS id;
ADD KEY RANGE krid1 FROM 1 TO 11 ROUTE TO sh1;
ADD KEY RANGE krid2 FROM 11 TO 101 ROUTE TO sh2;

\c regress

CREATE TABLE test_dist(id int);
INSERT INTO test_dist(id) VALUES(5);
INSERT INTO test_dist(id) VALUES(5);
INSERT INTO test_dist(id) VALUES(5);
INSERT INTO test_dist(id) VALUES(5);
INSERT INTO test_dist(id) VALUES(5);
SELECT id FROM test_dist WHERE id=5;
SELECT DISTINCT id FROM test_dist WHERE id=5;
5 changes: 4 additions & 1 deletion test/regress/tests/router/sql/routing_hint.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ ADD KEY RANGE krid2 FROM 11 TO 101 ROUTE TO sh2;

CREATE TABLE test(id int, age int);
INSERT INTO test(id, age) VALUES (10, 16) /*sharding_key: 30*/;
INSERT INTO test(id, age) VALUES (10, 16) /*sharding_key: 3000*/;
INSERT INTO test(id, age) VALUES (10, 16) /*sharding_key: 3000*/;
\c spqr-console
DROP KEY RANGE ALL;
DROP SHARDING RULE ALL;

0 comments on commit b5f2e91

Please sign in to comment.