Skip to content

Commit 88ee3de

Browse files
committed
[yugabyte#27535] YSQL: Fix PgGate's parallel requests
Summary: Handle the case when all the parallel requests are pruned. In PgGate requests may take bounds from different sources, like target tablet bounds, conditions on the primary key, parallel ranges. When we apply multiple bounds to a request, they may result in empty range. We prune empty range requests. There are rare, but valid cases when all tablet requests are pruned. PgGate did not check that and proceeded with sending zero requests, which triggered assertion failure down the road. In this diff we check if we have any requests before we send, and skip sending if we don't. It is now a valid case now if PgDocOp was executed, but did not sent any requests. It considers that as the end of the execution not as a failure. Jira: DB-17096 Test Plan: ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressIndex#schedule' Reviewers: jason, telgersma Reviewed By: jason Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D44664
1 parent 02e10f8 commit 88ee3de

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/postgres/src/test/regress/expected/yb.orig.index_scan.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,19 @@ SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1,r2,r3) < (1
16511651
----+----+----+---
16521652
(0 rows)
16531653

1654+
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1, r2, r3) > (1,2,3) AND v IS NOT NULL;
1655+
QUERY PLAN
1656+
----------------------------------------------------------------------------------------
1657+
Index Scan using pk_range_int_asc_pkey on pk_range_int_asc (actual rows=0 loops=1)
1658+
Index Cond: ((ROW(r1, r2, r3) <= ROW(1, 1, 5)) AND (ROW(r1, r2, r3) > ROW(1, 2, 3)))
1659+
Storage Filter: (v IS NOT NULL)
1660+
(3 rows)
1661+
1662+
SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1, r2, r3) > (1,2,3) AND v IS NOT NULL;
1663+
r1 | r2 | r3 | v
1664+
----+----+----+---
1665+
(0 rows)
1666+
16541667
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int_asc WHERE (r1, r3) <= (1,3) AND (r1,r2) < (1,3) AND (r1,r2) >= (1,2);
16551668
QUERY PLAN
16561669
---------------------------------------------------------------------------------------------------------

src/postgres/src/test/regress/sql/yb.orig.index_scan.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int
287287
SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,6,5) AND (r1,r2,r3) < (1,6,5);
288288
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1,r2,r3) < (1,2,4) AND (r1,r2,r3) > (1,2,3) AND (r1,r2,r3) < (1,2,4) AND (r1,r2,r3) >= (1,2,3);
289289
SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1,r2,r3) < (1,2,4) AND (r1,r2,r3) > (1,2,3) AND (r1,r2,r3) < (1,2,4) AND (r1,r2,r3) >= (1,2,3);
290+
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1, r2, r3) > (1,2,3) AND v IS NOT NULL;
291+
SELECT * FROM pk_range_int_asc WHERE (r1, r2, r3) <= (1,1,5) AND (r1, r2, r3) > (1,2,3) AND v IS NOT NULL;
290292
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int_asc WHERE (r1, r3) <= (1,3) AND (r1,r2) < (1,3) AND (r1,r2) >= (1,2);
291293
SELECT * FROM pk_range_int_asc WHERE (r1, r3) <= (1,3) AND (r1,r2) < (1,3) AND (r1,r2) >= (1,2);
292294
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM pk_range_int_asc WHERE (r1, r3) <= (1,3) AND (r1,r2) < (1,3) AND (r1,r2) >= (1,2) AND (r1,r2,r3) = (1,2,3);

src/yb/yql/pggate/pg_dml_read.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,9 @@ Status PgDmlRead::Exec(const YbcPgExecParameters* exec_params) {
466466
// No ybctids are provided. Instruct "doc_op_" to abandon the execution and not querying
467467
// any data from tablet server.
468468
doc_op_->AbandonExecution();
469-
} else {
470-
RSTATUS_DCHECK_EQ(
471-
VERIFY_RESULT(doc_op_->Execute()),
472-
RequestSent::kTrue, IllegalState, "YSQL read operation was not sent");
469+
} else if (VERIFY_RESULT(doc_op_->Execute()) != RequestSent::kTrue) {
470+
// Requests weren't sent, there is no data to fetch
471+
doc_op_->AbandonExecution();
473472
}
474473

475474
return Status::OK();

src/yb/yql/pggate/pg_doc_op.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,14 @@ Status PgDocOp::SendRequestImpl(ForceNonBufferable force_non_bufferable) {
372372
// Populate collected information into protobuf requests before sending to DocDB.
373373
RETURN_NOT_OK(CreateRequests());
374374

375-
// Send at most "parallelism_level_" number of requests at one time.
376-
size_t send_count = std::min(parallelism_level_, active_op_count_);
377-
VLOG(1) << "Number of operations to send: " << send_count;
378-
response_ = VERIFY_RESULT(sender_(
379-
pg_session_.get(), pgsql_ops_.data(), send_count, *table_,
380-
HybridTime::FromPB(GetInTxnLimitHt()), force_non_bufferable, IsForWritePgDoc(IsWrite())));
375+
if (active_op_count_ > 0) {
376+
// Send at most "parallelism_level_" number of requests at one time.
377+
size_t send_count = std::min(parallelism_level_, active_op_count_);
378+
VLOG(1) << "Number of operations to send: " << send_count;
379+
response_ = VERIFY_RESULT(sender_(
380+
pg_session_.get(), pgsql_ops_.data(), send_count, *table_,
381+
HybridTime::FromPB(GetInTxnLimitHt()), force_non_bufferable, IsForWritePgDoc(IsWrite())));
382+
}
381383
return Status::OK();
382384
}
383385

0 commit comments

Comments
 (0)