diff options
| author | Pavan Deolasee | 2014-12-23 06:07:03 +0000 |
|---|---|---|
| committer | Pavan Deolasee | 2015-04-15 05:46:43 +0000 |
| commit | 9ef33b52031fdd771b5b4da522a52d229f99be19 (patch) | |
| tree | bf203f4d001b63035e7d1536841579bd14f57714 /src | |
| parent | 016817e5297e414a2cf4eae3c275f7ac3df78bd9 (diff) | |
Push down LIMIT clause to the remote side if its a constant
The current code was broken, for example when OFFSET 0 is specified in the
query.
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/optimizer/plan/createplan.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index b3ca7a41b3..e49a07356d 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -6559,8 +6559,22 @@ make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount, node->limitCount = limitCount; #ifdef XCP - if ((limitOffset == NULL || offset_est > 0) && - (limitCount == NULL || count_est > 0)) + /* + * We want to push down LIMTI clause to the remote side in order to limit + * the number of rows that get shipped from the remote side. This can be + * done even if there is an ORDER BY clause, as long as we fetch minimum + * number of rows from all the nodes and then do a local sort and apply the + * final limit. + * + * We can't push down limit clause unless its a constant. Similarly, if the + * OFFSET is specified then it must be a constant too. + * + * Simple expressions get folded into constants by the time we come here. + * So this works well in case of constant expressions such as + * SELECT .. LIMIT (1024 * 1024); + */ + if (limitCount && IsA(limitCount, Const) && + ((limitOffset == NULL) || IsA(limitOffset, Const))) { /* * We may reduce amount of rows sent over the network and do not send more |
