@@ -245,13 +245,13 @@ SELECT * FROM ft1 t1 ORDER BY t1.c3, t1.c1, t1.tableoid OFFSET 100 LIMIT 10;
245
245
246
246
-- whole-row reference
247
247
EXPLAIN (VERBOSE, COSTS false) SELECT t1 FROM ft1 t1 ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10;
248
- QUERY PLAN
249
- ----------------------------------------------------------------------------------------------------------
248
+ QUERY PLAN
249
+ --------------------------------------------------------------------------------------------------------------------------------
250
250
Limit
251
251
Output: t1.*, c3, c1
252
252
-> Foreign Scan on public.ft1 t1
253
253
Output: t1.*, c3, c1
254
- Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" ORDER BY c3 ASC, "C 1" ASC
254
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" ORDER BY c3 ASC NULLS LAST , "C 1" ASC NULLS LAST
255
255
(5 rows)
256
256
257
257
SELECT t1 FROM ft1 t1 ORDER BY t1.c3, t1.c1 OFFSET 100 LIMIT 10;
@@ -382,16 +382,16 @@ SET enable_nestloop TO false;
382
382
-- inner join; expressions in the clauses appear in the equivalence class list
383
383
EXPLAIN (VERBOSE, COSTS false)
384
384
SELECT t1.c1, t2."C 1" FROM ft2 t1 JOIN "S 1"."T 1" t2 ON (t1.c1 = t2."C 1") OFFSET 100 LIMIT 10;
385
- QUERY PLAN
386
- ----------------------------------------------------------------------------
385
+ QUERY PLAN
386
+ ---------------------------------------------------------------------------------------
387
387
Limit
388
388
Output: t1.c1, t2."C 1"
389
389
-> Merge Join
390
390
Output: t1.c1, t2."C 1"
391
391
Merge Cond: (t1.c1 = t2."C 1")
392
392
-> Foreign Scan on public.ft2 t1
393
393
Output: t1.c1
394
- Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC
394
+ Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC NULLS LAST
395
395
-> Index Only Scan using t1_pkey on "S 1"."T 1" t2
396
396
Output: t2."C 1"
397
397
(10 rows)
@@ -415,16 +415,16 @@ SELECT t1.c1, t2."C 1" FROM ft2 t1 JOIN "S 1"."T 1" t2 ON (t1.c1 = t2."C 1") OFF
415
415
-- list but no output change as compared to the previous query
416
416
EXPLAIN (VERBOSE, COSTS false)
417
417
SELECT t1.c1, t2."C 1" FROM ft2 t1 LEFT JOIN "S 1"."T 1" t2 ON (t1.c1 = t2."C 1") OFFSET 100 LIMIT 10;
418
- QUERY PLAN
419
- ----------------------------------------------------------------------------
418
+ QUERY PLAN
419
+ ---------------------------------------------------------------------------------------
420
420
Limit
421
421
Output: t1.c1, t2."C 1"
422
422
-> Merge Left Join
423
423
Output: t1.c1, t2."C 1"
424
424
Merge Cond: (t1.c1 = t2."C 1")
425
425
-> Foreign Scan on public.ft2 t1
426
426
Output: t1.c1
427
- Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC
427
+ Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC NULLS LAST
428
428
-> Index Only Scan using t1_pkey on "S 1"."T 1" t2
429
429
Output: t2."C 1"
430
430
(10 rows)
@@ -1341,21 +1341,21 @@ SELECT t1.ctid, t1, t2, t1.c1 FROM ft1 t1 JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER B
1341
1341
-- SEMI JOIN, not pushed down
1342
1342
EXPLAIN (COSTS false, VERBOSE)
1343
1343
SELECT t1.c1 FROM ft1 t1 WHERE EXISTS (SELECT 1 FROM ft2 t2 WHERE t1.c1 = t2.c1) ORDER BY t1.c1 OFFSET 100 LIMIT 10;
1344
- QUERY PLAN
1345
- ----------------------------------------------------------------------------------
1344
+ QUERY PLAN
1345
+ ---------------------------------------------------------------------------------------------
1346
1346
Limit
1347
1347
Output: t1.c1
1348
1348
-> Merge Semi Join
1349
1349
Output: t1.c1
1350
1350
Merge Cond: (t1.c1 = t2.c1)
1351
1351
-> Foreign Scan on public.ft1 t1
1352
1352
Output: t1.c1
1353
- Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC
1353
+ Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC NULLS LAST
1354
1354
-> Materialize
1355
1355
Output: t2.c1
1356
1356
-> Foreign Scan on public.ft2 t2
1357
1357
Output: t2.c1
1358
- Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC
1358
+ Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC NULLS LAST
1359
1359
(13 rows)
1360
1360
1361
1361
SELECT t1.c1 FROM ft1 t1 WHERE EXISTS (SELECT 1 FROM ft2 t2 WHERE t1.c1 = t2.c1) ORDER BY t1.c1 OFFSET 100 LIMIT 10;
@@ -1376,21 +1376,21 @@ SELECT t1.c1 FROM ft1 t1 WHERE EXISTS (SELECT 1 FROM ft2 t2 WHERE t1.c1 = t2.c1)
1376
1376
-- ANTI JOIN, not pushed down
1377
1377
EXPLAIN (COSTS false, VERBOSE)
1378
1378
SELECT t1.c1 FROM ft1 t1 WHERE NOT EXISTS (SELECT 1 FROM ft2 t2 WHERE t1.c1 = t2.c2) ORDER BY t1.c1 OFFSET 100 LIMIT 10;
1379
- QUERY PLAN
1380
- ----------------------------------------------------------------------------
1379
+ QUERY PLAN
1380
+ ---------------------------------------------------------------------------------------
1381
1381
Limit
1382
1382
Output: t1.c1
1383
1383
-> Merge Anti Join
1384
1384
Output: t1.c1
1385
1385
Merge Cond: (t1.c1 = t2.c2)
1386
1386
-> Foreign Scan on public.ft1 t1
1387
1387
Output: t1.c1
1388
- Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC
1388
+ Remote SQL: SELECT "C 1" FROM "S 1"."T 1" ORDER BY "C 1" ASC NULLS LAST
1389
1389
-> Materialize
1390
1390
Output: t2.c2
1391
1391
-> Foreign Scan on public.ft2 t2
1392
1392
Output: t2.c2
1393
- Remote SQL: SELECT c2 FROM "S 1"."T 1" ORDER BY c2 ASC
1393
+ Remote SQL: SELECT c2 FROM "S 1"."T 1" ORDER BY c2 ASC NULLS LAST
1394
1394
(13 rows)
1395
1395
1396
1396
SELECT t1.c1 FROM ft1 t1 WHERE NOT EXISTS (SELECT 1 FROM ft2 t2 WHERE t1.c1 = t2.c2) ORDER BY t1.c1 OFFSET 100 LIMIT 10;
@@ -1448,21 +1448,21 @@ SELECT t1.c1, t2.c1 FROM ft1 t1 CROSS JOIN ft2 t2 ORDER BY t1.c1, t2.c1 OFFSET 1
1448
1448
-- different server, not pushed down. No result expected.
1449
1449
EXPLAIN (COSTS false, VERBOSE)
1450
1450
SELECT t1.c1, t2.c1 FROM ft5 t1 JOIN ft6 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1 OFFSET 100 LIMIT 10;
1451
- QUERY PLAN
1452
- ----------------------------------------------------------------------------
1451
+ QUERY PLAN
1452
+ ---------------------------------------------------------------------------------------
1453
1453
Limit
1454
1454
Output: t1.c1, t2.c1
1455
1455
-> Merge Join
1456
1456
Output: t1.c1, t2.c1
1457
1457
Merge Cond: (t2.c1 = t1.c1)
1458
1458
-> Foreign Scan on public.ft6 t2
1459
1459
Output: t2.c1, t2.c2, t2.c3
1460
- Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC
1460
+ Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC NULLS LAST
1461
1461
-> Materialize
1462
1462
Output: t1.c1, t1.c2, t1.c3
1463
1463
-> Foreign Scan on public.ft5 t1
1464
1464
Output: t1.c1, t1.c2, t1.c3
1465
- Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC
1465
+ Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC NULLS LAST
1466
1466
(13 rows)
1467
1467
1468
1468
SELECT t1.c1, t2.c1 FROM ft5 t1 JOIN ft6 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1, t2.c1 OFFSET 100 LIMIT 10;
@@ -1746,21 +1746,21 @@ EXECUTE join_stmt;
1746
1746
-- different user mappings
1747
1747
CREATE USER MAPPING FOR view_owner SERVER loopback;
1748
1748
EXPLAIN (COSTS false, VERBOSE) EXECUTE join_stmt;
1749
- QUERY PLAN
1750
- ----------------------------------------------------------------------------
1749
+ QUERY PLAN
1750
+ ---------------------------------------------------------------------------------------
1751
1751
Limit
1752
1752
Output: t1.c1, ft5.c1
1753
1753
-> Merge Join
1754
1754
Output: t1.c1, ft5.c1
1755
1755
Merge Cond: (t1.c1 = ft5.c1)
1756
1756
-> Foreign Scan on public.ft5 t1
1757
1757
Output: t1.c1, t1.c2, t1.c3
1758
- Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC
1758
+ Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC NULLS LAST
1759
1759
-> Materialize
1760
1760
Output: ft5.c1, ft5.c2, ft5.c3
1761
1761
-> Foreign Scan on public.ft5
1762
1762
Output: ft5.c1, ft5.c2, ft5.c3
1763
- Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC
1763
+ Remote SQL: SELECT c1 FROM "S 1"."T 4" ORDER BY c1 ASC NULLS LAST
1764
1764
(13 rows)
1765
1765
1766
1766
EXECUTE join_stmt;
@@ -3813,6 +3813,86 @@ select c2, count(*) from "S 1"."T 1" where c2 < 500 group by 1 order by 1;
3813
3813
407 | 100
3814
3814
(13 rows)
3815
3815
3816
+ -- Above DMLs add data with c6 as NULL in ft1, so test ORDER BY NULLS LAST and NULLs
3817
+ -- FIRST behavior here.
3818
+ -- ORDER BY DESC NULLS LAST options
3819
+ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 ORDER BY c6 DESC NULLS LAST, c1 OFFSET 795 LIMIT 10;
3820
+ QUERY PLAN
3821
+ ---------------------------------------------------------------------------------------------------------------------------------
3822
+ Limit
3823
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
3824
+ -> Foreign Scan on public.ft1
3825
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
3826
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" ORDER BY c6 DESC NULLS LAST, "C 1" ASC NULLS LAST
3827
+ (5 rows)
3828
+
3829
+ SELECT * FROM ft1 ORDER BY c6 DESC NULLS LAST, c1 OFFSET 795 LIMIT 10;
3830
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
3831
+ ------+-----+--------------------+------------------------------+--------------------------+------+------------+-----
3832
+ 960 | 42 | 00960_trig_update | Mon Mar 02 00:00:00 1970 PST | Mon Mar 02 00:00:00 1970 | 0 | 0 | foo
3833
+ 970 | 42 | 00970_trig_update | Thu Mar 12 00:00:00 1970 PST | Thu Mar 12 00:00:00 1970 | 0 | 0 | foo
3834
+ 980 | 42 | 00980_trig_update | Sun Mar 22 00:00:00 1970 PST | Sun Mar 22 00:00:00 1970 | 0 | 0 | foo
3835
+ 990 | 42 | 00990_trig_update | Wed Apr 01 00:00:00 1970 PST | Wed Apr 01 00:00:00 1970 | 0 | 0 | foo
3836
+ 1000 | 42 | 01000_trig_update | Thu Jan 01 00:00:00 1970 PST | Thu Jan 01 00:00:00 1970 | 0 | 0 | foo
3837
+ 1218 | 818 | ggg_trig_update | | | (--; | ft2 |
3838
+ 1001 | 101 | 0000100001 | | | | ft2 |
3839
+ 1003 | 403 | 0000300003_update3 | | | | ft2 |
3840
+ 1004 | 104 | 0000400004 | | | | ft2 |
3841
+ 1006 | 106 | 0000600006 | | | | ft2 |
3842
+ (10 rows)
3843
+
3844
+ -- ORDER BY DESC NULLS FIRST options
3845
+ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 ORDER BY c6 DESC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
3846
+ QUERY PLAN
3847
+ ----------------------------------------------------------------------------------------------------------------------------------
3848
+ Limit
3849
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
3850
+ -> Foreign Scan on public.ft1
3851
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
3852
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" ORDER BY c6 DESC NULLS FIRST, "C 1" ASC NULLS LAST
3853
+ (5 rows)
3854
+
3855
+ SELECT * FROM ft1 ORDER BY c6 DESC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
3856
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
3857
+ ------+-----+-----------------+------------------------------+--------------------------+----+------------+-----
3858
+ 1020 | 100 | 0002000020 | | | | ft2 |
3859
+ 1101 | 201 | aaa | | | | ft2 |
3860
+ 1103 | 503 | ccc_update3 | | | | ft2 |
3861
+ 1104 | 204 | ddd | | | | ft2 |
3862
+ 1208 | 818 | fff_trig_update | | | | ft2 |
3863
+ 9 | 509 | 00009_update9 | Sat Jan 10 00:00:00 1970 PST | Sat Jan 10 00:00:00 1970 | 9 | ft2 | foo
3864
+ 19 | 509 | 00019_update9 | Tue Jan 20 00:00:00 1970 PST | Tue Jan 20 00:00:00 1970 | 9 | ft2 | foo
3865
+ 29 | 509 | 00029_update9 | Fri Jan 30 00:00:00 1970 PST | Fri Jan 30 00:00:00 1970 | 9 | ft2 | foo
3866
+ 39 | 509 | 00039_update9 | Mon Feb 09 00:00:00 1970 PST | Mon Feb 09 00:00:00 1970 | 9 | ft2 | foo
3867
+ 49 | 509 | 00049_update9 | Thu Feb 19 00:00:00 1970 PST | Thu Feb 19 00:00:00 1970 | 9 | ft2 | foo
3868
+ (10 rows)
3869
+
3870
+ -- ORDER BY ASC NULLS FIRST options
3871
+ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 ORDER BY c6 ASC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
3872
+ QUERY PLAN
3873
+ ---------------------------------------------------------------------------------------------------------------------------------
3874
+ Limit
3875
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
3876
+ -> Foreign Scan on public.ft1
3877
+ Output: c1, c2, c3, c4, c5, c6, c7, c8
3878
+ Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" ORDER BY c6 ASC NULLS FIRST, "C 1" ASC NULLS LAST
3879
+ (5 rows)
3880
+
3881
+ SELECT * FROM ft1 ORDER BY c6 ASC NULLS FIRST, c1 OFFSET 15 LIMIT 10;
3882
+ c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
3883
+ ------+-----+-------------------+------------------------------+--------------------------+------+------------+-----
3884
+ 1020 | 100 | 0002000020 | | | | ft2 |
3885
+ 1101 | 201 | aaa | | | | ft2 |
3886
+ 1103 | 503 | ccc_update3 | | | | ft2 |
3887
+ 1104 | 204 | ddd | | | | ft2 |
3888
+ 1208 | 818 | fff_trig_update | | | | ft2 |
3889
+ 1218 | 818 | ggg_trig_update | | | (--; | ft2 |
3890
+ 10 | 42 | 00010_trig_update | Sun Jan 11 00:00:00 1970 PST | Sun Jan 11 00:00:00 1970 | 0 | 0 | foo
3891
+ 20 | 42 | 00020_trig_update | Wed Jan 21 00:00:00 1970 PST | Wed Jan 21 00:00:00 1970 | 0 | 0 | foo
3892
+ 30 | 42 | 00030_trig_update | Sat Jan 31 00:00:00 1970 PST | Sat Jan 31 00:00:00 1970 | 0 | 0 | foo
3893
+ 40 | 42 | 00040_trig_update | Tue Feb 10 00:00:00 1970 PST | Tue Feb 10 00:00:00 1970 | 0 | 0 | foo
3894
+ (10 rows)
3895
+
3816
3896
-- ===================================================================
3817
3897
-- test check constraints
3818
3898
-- ===================================================================
@@ -4630,8 +4710,8 @@ analyze loct1;
4630
4710
-- inner join; expressions in the clauses appear in the equivalence class list
4631
4711
explain (verbose, costs off)
4632
4712
select foo.f1, loct1.f1 from foo join loct1 on (foo.f1 = loct1.f1) order by foo.f2 offset 10 limit 10;
4633
- QUERY PLAN
4634
- ---------------------------------------------------------------------------------------
4713
+ QUERY PLAN
4714
+ --------------------------------------------------------------------------------------------------
4635
4715
Limit
4636
4716
Output: foo.f1, loct1.f1, foo.f2
4637
4717
-> Sort
@@ -4646,7 +4726,7 @@ explain (verbose, costs off)
4646
4726
Output: foo.f1, foo.f2
4647
4727
-> Foreign Scan on public.foo2
4648
4728
Output: foo2.f1, foo2.f2
4649
- Remote SQL: SELECT f1, f2 FROM public.loct1 ORDER BY f1 ASC
4729
+ Remote SQL: SELECT f1, f2 FROM public.loct1 ORDER BY f1 ASC NULLS LAST
4650
4730
-> Index Only Scan using i_loct1_f1 on public.loct1
4651
4731
Output: loct1.f1
4652
4732
(17 rows)
@@ -4670,8 +4750,8 @@ select foo.f1, loct1.f1 from foo join loct1 on (foo.f1 = loct1.f1) order by foo.
4670
4750
-- list but no output change as compared to the previous query
4671
4751
explain (verbose, costs off)
4672
4752
select foo.f1, loct1.f1 from foo left join loct1 on (foo.f1 = loct1.f1) order by foo.f2 offset 10 limit 10;
4673
- QUERY PLAN
4674
- ---------------------------------------------------------------------------------------
4753
+ QUERY PLAN
4754
+ --------------------------------------------------------------------------------------------------
4675
4755
Limit
4676
4756
Output: foo.f1, loct1.f1, foo.f2
4677
4757
-> Sort
@@ -4686,7 +4766,7 @@ explain (verbose, costs off)
4686
4766
Output: foo.f1, foo.f2
4687
4767
-> Foreign Scan on public.foo2
4688
4768
Output: foo2.f1, foo2.f2
4689
- Remote SQL: SELECT f1, f2 FROM public.loct1 ORDER BY f1 ASC
4769
+ Remote SQL: SELECT f1, f2 FROM public.loct1 ORDER BY f1 ASC NULLS LAST
4690
4770
-> Index Only Scan using i_loct1_f1 on public.loct1
4691
4771
Output: loct1.f1
4692
4772
(17 rows)
0 commit comments