@@ -1216,16 +1216,27 @@ logical_plan
1216121607)------SubqueryAlias: t2
1217121708)--------Projection: ordered_table.b, ordered_table.c, Int32(NULL) AS a, ordered_table.a0, ordered_table.d
1218121809)----------TableScan: ordered_table projection=[a0, b, c, d]
1219+ physical_plan
1220+ 01)ProjectionExec: expr=[b@0 as b, c@1 as c, a@2 as a, a0@3 as a0]
1221+ 02)--SortPreservingMergeExec: [d@4 ASC NULLS LAST,c@1 ASC NULLS LAST,a@2 ASC NULLS LAST,a0@3 ASC NULLS LAST,b@0 ASC NULLS LAST], fetch=2
1222+ 03)----UnionExec
1223+ 04)------SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST,c@1 ASC NULLS LAST,a@2 ASC NULLS LAST,b@0 ASC NULLS LAST], preserve_partitioning=[false]
1224+ 05)--------ProjectionExec: expr=[b@1 as b, c@2 as c, a@0 as a, NULL as a0, d@3 as d]
1225+ 06)----------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b, c, d], output_ordering=[c@2 ASC NULLS LAST], has_header=true
1226+ 07)------SortExec: TopK(fetch=2), expr=[d@4 ASC NULLS LAST,c@1 ASC NULLS LAST,a0@3 ASC NULLS LAST,b@0 ASC NULLS LAST], preserve_partitioning=[false]
1227+ 08)--------ProjectionExec: expr=[b@1 as b, c@2 as c, NULL as a, a0@0 as a0, d@3 as d]
1228+ 09)----------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a0, b, c, d], output_ordering=[c@2 ASC NULLS LAST], has_header=true
12191229
12201230# Test: run the query from above
1221- # TODO: query fails since the constant columns t1.a0 and t2.a are not in the ORDER BY subquery,
1222- # and SanityCheckPlan does not allow this.
1223- statement error DataFusion error: SanityCheckPlan
1231+ query IIII
12241232select * from (select b, c, a, NULL::int as a0 from ordered_table order by a, c) t1
12251233union all
12261234select * from (select b, c, NULL::int as a, a0 from ordered_table order by a0, c) t2
12271235order by d, c, a, a0, b
12281236limit 2;
1237+ ----
1238+ 0 0 0 NULL
1239+ 0 0 NULL 1
12291240
12301241statement ok
12311242drop table ordered_table;
0 commit comments