Skip to content

Commit ff7dbba

Browse files
committed
[yugabyte#25559] YSQL: Fix order in some queries with IN clause
Summary: It was incorrectly assumed that requests with equality conditions on all key columns, when those conditions are converted to ybctid, do not need to keep the row order. It is true in most cases, basically, because those conditions usually produce single ybctid, and yield at most one row. However, there is one exception, when it is not true. If one column's equality condition is an IN operator, it yields multiple ybctids, which order may be important. Fixed by providing the keep_order parameter. Jira: DB-14813 Test Plan: ./yb_build.sh --java-test org.yb.pgsql.TestPgRegressHashInQueries#schedule Reviewers: dmitry, telgersma Reviewed By: telgersma Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D41145
1 parent c00c7a8 commit ff7dbba

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/postgres/src/test/regress/expected/yb_hash_in_queries.out

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -964,12 +964,12 @@ SELECT * FROM in_with_single_asc_key WHERE r IN (1, 3, 2, 102, 103, 101) ORDER B
964964
SELECT * FROM in_with_single_asc_key WHERE r IN (1, 3, 2, 102, 103, 101) ORDER BY r DESC;
965965
r | v
966966
-----+-----
967-
3 | 3
968-
2 | 2
969-
1 | 1
970967
103 | 103
971968
102 | 102
972969
101 | 101
970+
3 | 3
971+
2 | 2
972+
1 | 1
973973
(6 rows)
974974

975975
DROP TABLE in_with_single_asc_key;
@@ -978,12 +978,12 @@ INSERT INTO in_with_single_desc_key VALUES(1, 1), (3, 3), (2, 2), (101, 101), (1
978978
SELECT * FROM in_with_single_desc_key WHERE r IN (1, 3, 2, 102, 103, 101) ORDER BY r ASC;
979979
r | v
980980
-----+-----
981-
101 | 101
982-
102 | 102
983-
103 | 103
984981
1 | 1
985982
2 | 2
986983
3 | 3
984+
101 | 101
985+
102 | 102
986+
103 | 103
987987
(6 rows)
988988

989989
SELECT * FROM in_with_single_desc_key WHERE r IN (1, 3, 2, 102, 103, 101) ORDER BY r DESC;
@@ -1003,12 +1003,12 @@ INSERT INTO in_with_compound_asc_key VALUES(1, 1, 1), (1, 3, 3), (1, 2, 2), (1,
10031003
SELECT * FROM in_with_compound_asc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 DESC, r2 DESC;
10041004
r1 | r2 | v
10051005
----+-----+-----
1006-
1 | 3 | 3
1007-
1 | 2 | 2
1008-
1 | 1 | 1
10091006
1 | 103 | 103
10101007
1 | 102 | 102
10111008
1 | 101 | 101
1009+
1 | 3 | 3
1010+
1 | 2 | 2
1011+
1 | 1 | 1
10121012
(6 rows)
10131013

10141014
SELECT * FROM in_with_compound_asc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 DESC, r2 ASC;
@@ -1025,12 +1025,12 @@ SELECT * FROM in_with_compound_asc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103
10251025
SELECT * FROM in_with_compound_asc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 ASC, r2 DESC;
10261026
r1 | r2 | v
10271027
----+-----+-----
1028-
1 | 3 | 3
1029-
1 | 2 | 2
1030-
1 | 1 | 1
10311028
1 | 103 | 103
10321029
1 | 102 | 102
10331030
1 | 101 | 101
1031+
1 | 3 | 3
1032+
1 | 2 | 2
1033+
1 | 1 | 1
10341034
(6 rows)
10351035

10361036
SELECT * FROM in_with_compound_asc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 ASC, r2 ASC;
@@ -1061,12 +1061,12 @@ SELECT * FROM in_with_compound_desc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 10
10611061
SELECT * FROM in_with_compound_desc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 DESC, r2 ASC;
10621062
r1 | r2 | v
10631063
----+-----+-----
1064-
1 | 101 | 101
1065-
1 | 102 | 102
1066-
1 | 103 | 103
10671064
1 | 1 | 1
10681065
1 | 2 | 2
10691066
1 | 3 | 3
1067+
1 | 101 | 101
1068+
1 | 102 | 102
1069+
1 | 103 | 103
10701070
(6 rows)
10711071

10721072
SELECT * FROM in_with_compound_desc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 ASC, r2 DESC;
@@ -1083,12 +1083,12 @@ SELECT * FROM in_with_compound_desc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 10
10831083
SELECT * FROM in_with_compound_desc_key WHERE r1 = 1 AND r2 IN (1, 3, 2, 102, 103, 101) ORDER BY r1 ASC, r2 ASC;
10841084
r1 | r2 | v
10851085
----+-----+-----
1086-
1 | 101 | 101
1087-
1 | 102 | 102
1088-
1 | 103 | 103
10891086
1 | 1 | 1
10901087
1 | 2 | 2
10911088
1 | 3 | 3
1089+
1 | 101 | 101
1090+
1 | 102 | 102
1091+
1 | 103 | 103
10921092
(6 rows)
10931093

10941094
DROP TABLE in_with_compound_desc_key;

src/yb/yql/pggate/pg_dml_read.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ Status PgDmlRead::SubstitutePrimaryBindsWithYbctids(const PgExecParameters* para
721721
read_req_->mutable_partition_column_values()->clear();
722722
read_req_->mutable_range_column_values()->clear();
723723
RETURN_NOT_OK(InitDocOp(params, /* is_concrete_row_read = */ true));
724-
return UpdateRequestWithYbctids(ybctids);
724+
return UpdateRequestWithYbctids(ybctids, KeepOrder(read_req_->has_is_forward_scan()));
725725
}
726726

727727
// Function builds vector of ybctids from primary key binds.

0 commit comments

Comments
 (0)