This repository was archived by the owner on May 24, 2024. It is now read-only.
Commit eeea7f1
authored
Optimize MPP FDW LIMIT/OFFSET push down when there is NULL/0. (#17246)
When there are NULL or zero values in OFFSET/LIMIT clause,
we do NOT need to fetch more rows and expression NULL plus others is pointless.
Optimize (N > 0)
LIMIT 0 OFFSET N to LIMIT 0
LIMIT 0 OFFSET NULL to LIMIT 0
LIMIT N OFFSET NULL to LIMIT N
LIMIT N OFFSET 0 to LIMIT N
Example before this fix:
EXPLAIN (VERBOSE, COSTS OFF)
SELECT c1, c2 FROM mpp_ft2 order by c1 limit 0 offset 998;
QUERY PLAN
--------------
Limit
Output: c1, c2
-> Gather Motion 2:1 (slice1; segments: 2)
Output: c1, c2
Merge Key: c1
-> Foreign Scan on public.mpp_ft2
Output: c1, c2
Remote SQL: SELECT c1, c2 FROM "MPP_S 1"."T 2" ORDER BY
c1 ASC NULLS LAST LIMIT (998::bigint + 0::bigint)
We will have to fetch 998 rows from remote, but as we have limit 0,
that's pointless.
With this fix:
EXPLAIN (VERBOSE, COSTS OFF)
SELECT c1, c2 FROM mpp_ft2 order by c1 limit 0 offset 998;
QUERY PLAN
--------------
Limit
Output: c1, c2
-> Gather Motion 2:1 (slice1; segments: 2)
Output: c1, c2
Merge Key: c1
-> Foreign Scan on public.mpp_ft2
Output: c1, c2
Remote SQL: SELECT c1, c2 FROM "MPP_S 1"."T 2" ORDER BY
c1 ASC NULLS LAST LIMIT 0::bigint1 parent cc09dbd commit eeea7f1
4 files changed
Lines changed: 136 additions & 3 deletions
File tree
- contrib/postgres_fdw
- expected
- sql
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3544 | 3544 | | |
3545 | 3545 | | |
3546 | 3546 | | |
| 3547 | + | |
| 3548 | + | |
3547 | 3549 | | |
3548 | 3550 | | |
3549 | 3551 | | |
3550 | 3552 | | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
3551 | 3558 | | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
3552 | 3569 | | |
3553 | 3570 | | |
3554 | | - | |
| 3571 | + | |
3555 | 3572 | | |
3556 | 3573 | | |
3557 | 3574 | | |
| |||
3560 | 3577 | | |
3561 | 3578 | | |
3562 | 3579 | | |
3563 | | - | |
| 3580 | + | |
3564 | 3581 | | |
3565 | 3582 | | |
3566 | 3583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
981 | 981 | | |
982 | 982 | | |
983 | 983 | | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
984 | 1083 | | |
985 | 1084 | | |
986 | 1085 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
236 | 253 | | |
237 | 254 | | |
238 | 255 | | |
| |||
0 commit comments