mirror of https://github.com/citusdata/citus.git
Fix 7663 by checking if the limit is null when the limit is computed with respect to the offset.
parent
2a263fe69a
commit
7f2c420da9
|
@ -4753,22 +4753,33 @@ WorkerLimitCount(Node *limitCount, Node *limitOffset, OrderByLimitReference
|
|||
if (workerLimitNode != NULL && limitOffset != NULL)
|
||||
{
|
||||
Const *workerLimitConst = (Const *) workerLimitNode;
|
||||
Const *workerOffsetConst = (Const *) limitOffset;
|
||||
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);
|
||||
int64 workerOffsetCount = DatumGetInt64(workerOffsetConst->constvalue);
|
||||
|
||||
workerLimitCount = workerLimitCount + workerOffsetCount;
|
||||
workerLimitNode = (Node *) MakeIntegerConstInt64(workerLimitCount);
|
||||
if (!workerLimitConst->constisnull)
|
||||
{
|
||||
/* Only update the worker limit if the const is not null.*/
|
||||
Const *workerOffsetConst = (Const *) limitOffset;
|
||||
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);
|
||||
int64 workerOffsetCount = DatumGetInt64(workerOffsetConst->constvalue);
|
||||
workerLimitCount = workerLimitCount + workerOffsetCount;
|
||||
workerLimitNode = (Node *) MakeIntegerConstInt64(workerLimitCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* display debug message on limit push down */
|
||||
if (workerLimitNode != NULL)
|
||||
{
|
||||
Const *workerLimitConst = (Const *) workerLimitNode;
|
||||
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);
|
||||
if (!workerLimitConst->constisnull)
|
||||
{
|
||||
int64 workerLimitCount = DatumGetInt64(workerLimitConst->constvalue);
|
||||
|
||||
ereport(DEBUG1, (errmsg("push down of limit count: " INT64_FORMAT,
|
||||
workerLimitCount)));
|
||||
ereport(DEBUG1, (errmsg("push down of limit count: " INT64_FORMAT,
|
||||
workerLimitCount)));
|
||||
}
|
||||
else
|
||||
{
|
||||
ereport(DEBUG1, (errmsg("push down of limit count: ALL")));
|
||||
}
|
||||
}
|
||||
|
||||
return workerLimitNode;
|
||||
|
|
|
@ -521,6 +521,46 @@ SELECT
|
|||
1 | 1
|
||||
(1 row)
|
||||
|
||||
-- check if we can correctly push the limit when it is null
|
||||
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey LIMIT null;
|
||||
DEBUG: push down of limit count: ALL
|
||||
l_orderkey
|
||||
---------------------------------------------------------------------
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
2
|
||||
(7 rows)
|
||||
|
||||
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET 1 LIMIT null;
|
||||
DEBUG: push down of limit count: ALL
|
||||
l_orderkey
|
||||
---------------------------------------------------------------------
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
2
|
||||
(6 rows)
|
||||
|
||||
SELECT count(*) FROM lineitem LIMIT null;
|
||||
DEBUG: push down of limit count: ALL
|
||||
count
|
||||
---------------------------------------------------------------------
|
||||
12000
|
||||
(1 row)
|
||||
|
||||
SELECT count(*) FROM lineitem OFFSET 0 LIMIT null;
|
||||
DEBUG: push down of limit count: ALL
|
||||
count
|
||||
---------------------------------------------------------------------
|
||||
12000
|
||||
(1 row)
|
||||
|
||||
SET client_min_messages TO NOTICE;
|
||||
-- non constants should not push down
|
||||
CREATE OR REPLACE FUNCTION my_limit()
|
||||
|
|
|
@ -222,6 +222,15 @@ SELECT
|
|||
ORDER BY 2 DESC, 1
|
||||
LIMIT 5;
|
||||
|
||||
-- check if we can correctly push the limit when it is null
|
||||
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey LIMIT null;
|
||||
|
||||
SELECT l_orderkey FROM lineitem WHERE l_orderkey < 3 ORDER BY l_orderkey OFFSET 1 LIMIT null;
|
||||
|
||||
SELECT count(*) FROM lineitem LIMIT null;
|
||||
|
||||
SELECT count(*) FROM lineitem OFFSET 0 LIMIT null;
|
||||
|
||||
SET client_min_messages TO NOTICE;
|
||||
|
||||
-- non constants should not push down
|
||||
|
|
Loading…
Reference in New Issue