Skip to content

Commit

Permalink
addressing review
Browse files Browse the repository at this point in the history
  • Loading branch information
eaydingol committed Jul 31, 2024
1 parent 8eba822 commit 257c2c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/backend/distributed/planner/multi_logical_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4753,11 +4753,14 @@ WorkerLimitCount(Node *limitCount, Node *limitOffset, OrderByLimitReference
if (workerLimitNode != NULL && limitOffset != NULL)
{
Const *workerLimitConst = (Const *) workerLimitNode;

/* Only update the worker limit if the const is not null.*/
if (!workerLimitConst->constisnull)
{
/* Only update the worker limit if the const is not null.*/
Const *workerOffsetConst = (Const *) limitOffset;
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);

/* If the offset is null, it defaults to 0 when cast to int64. */
int64 workerOffsetCount = DatumGetInt64(workerOffsetConst->constvalue);
workerLimitCount = workerLimitCount + workerOffsetCount;
workerLimitNode = (Node *) MakeIntegerConstInt64(workerLimitCount);
Expand Down
23 changes: 23 additions & 0 deletions src/test/regress/expected/multi_limit_clause.out
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,29 @@ DEBUG: push down of limit count: 1
1
(1 row)

-- check if we can correctly push the limit when it is all
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 LIMIT all;
DEBUG: push down of limit count: ALL
l_orderkey
---------------------------------------------------------------------
1
1
1
1
1
1
(6 rows)

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 OFFSET 2 LIMIT all;
DEBUG: push down of limit count: ALL
l_orderkey
---------------------------------------------------------------------
1
1
1
1
(4 rows)

SET client_min_messages TO NOTICE;
-- non constants should not push down
CREATE OR REPLACE FUNCTION my_limit()
Expand Down
5 changes: 5 additions & 0 deletions src/test/regress/sql/multi_limit_clause.sql
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET null LIMIT 1;

-- check if we can correctly push the limit when it is all
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 LIMIT all;

SELECT l_orderkey FROM lineitem WHERE l_orderkey < 2 OFFSET 2 LIMIT all;

SET client_min_messages TO NOTICE;

-- non constants should not push down
Expand Down

0 comments on commit 257c2c8

Please sign in to comment.