@@ -2529,6 +2529,65 @@ func TestIssue46298(t *testing.T) {
2529
2529
tk .MustQuery ("select *, first_value(v) over (partition by p order by o range between 3.1 preceding and 2.9 following) as a from test.first_range;" )
2530
2530
}
2531
2531
2532
+ << << << < HEAD
2533
+ == == == =
2534
+ func TestIssue45044 (t * testing.T ) {
2535
+ store := testkit .CreateMockStore (t )
2536
+ tk := testkit .NewTestKit (t , store )
2537
+ tk .MustExec (`use test` )
2538
+ tk .MustExec (`set tidb_enable_ordered_result_mode = on` )
2539
+ tk .MustExec (`create table t1(c1 int)` )
2540
+ tk .MustQuery (`select * from t1 group by t1.c1 having count(1) > 1 order by count(1) limit 10` ).Check (testkit .Rows ()) // no error
2541
+ }
2542
+
2543
+ func TestIssue46177 (t * testing.T ) {
2544
+ store := testkit .CreateMockStore (t )
2545
+ tk := testkit .NewTestKit (t , store )
2546
+ tk .MustExec (`use test` )
2547
+ tk .MustExec (` CREATE TABLE sbtest (
2548
+ id int(10) unsigned NOT NULL AUTO_INCREMENT,
2549
+ k int(10) unsigned NOT NULL DEFAULT '0',
2550
+ c char(120) NOT NULL DEFAULT '',
2551
+ pad char(60) NOT NULL DEFAULT '',
2552
+ PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */,
2553
+ KEY k (k)
2554
+ )` )
2555
+
2556
+ // cannot choose the best plan with RangeScan.
2557
+ tk .MustExec (`set @@tidb_opt_fix_control = '46177:off'` )
2558
+ tk .MustQuery (`explain format='brief' select row_number() over(order by a.k) from (select * from sbtest where id<10) a` ).Check (testkit .Rows (
2559
+ `Projection 10.00 root Column#6->Column#7` ,
2560
+ `└─Window 10.00 root row_number()->Column#6 over(order by test.sbtest.k rows between current row and current row)` ,
2561
+ ` └─IndexReader 10.00 root index:Selection` ,
2562
+ ` └─Selection 10.00 cop[tikv] lt(test.sbtest.id, 10)` ,
2563
+ ` └─IndexFullScan 10000.00 cop[tikv] table:sbtest, index:k(k) keep order:true, stats:pseudo` ))
2564
+
2565
+ tk .MustExec (`set @@tidb_opt_fix_control = '46177:on'` )
2566
+ tk .MustQuery (`explain format='brief' select row_number() over(order by a.k) from (select * from sbtest where id<10) a` ).Check (testkit .Rows (
2567
+ `Projection 10.00 root Column#6->Column#7` ,
2568
+ `└─Window 10.00 root row_number()->Column#6 over(order by test.sbtest.k rows between current row and current row)` ,
2569
+ ` └─Sort 10.00 root test.sbtest.k` ,
2570
+ ` └─TableReader 10.00 root data:TableRangeScan` ,
2571
+ ` └─TableRangeScan 10.00 cop[tikv] table:sbtest range:[0,10), keep order:false, stats:pseudo` ))
2572
+
2573
+ // cannot choose the range scan plan.
2574
+ tk .MustExec (`set @@tidb_opt_fix_control = '46177:off'` )
2575
+ tk .MustQuery (`explain format='brief' select /*+ stream_agg() */ count(1) from sbtest where id<1 group by k` ).Check (testkit .Rows (
2576
+ `StreamAgg 1.00 root group by:test.sbtest.k, funcs:count(Column#6)->Column#5` ,
2577
+ `└─IndexReader 1.00 root index:StreamAgg` ,
2578
+ ` └─StreamAgg 1.00 cop[tikv] group by:test.sbtest.k, funcs:count(1)->Column#6` ,
2579
+ ` └─Selection 1.00 cop[tikv] lt(test.sbtest.id, 1)` ,
2580
+ ` └─IndexFullScan 10000.00 cop[tikv] table:sbtest, index:k(k) keep order:true, stats:pseudo` ))
2581
+
2582
+ tk .MustExec (`set @@tidb_opt_fix_control = '46177:on'` )
2583
+ tk .MustQuery (`explain format='brief' select /*+ stream_agg() */ count(1) from sbtest where id<1 group by k` ).Check (testkit .Rows (
2584
+ `StreamAgg 1.00 root group by:test.sbtest.k, funcs:count(1)->Column#5` ,
2585
+ `└─Sort 1.00 root test.sbtest.k` ,
2586
+ ` └─TableReader 1.00 root data:TableRangeScan` ,
2587
+ ` └─TableRangeScan 1.00 cop[tikv] table:sbtest range:[0,1), keep order:false, stats:pseudo` ))
2588
+ }
2589
+
2590
+ >> >> >> > 0172 ba0a1ab (planner : fix the issue that the optimizer terminates the optimization process for `DataSource` too early (#48186 ))
2532
2591
// https://github.com/pingcap/tidb/issues/41458
2533
2592
func TestIssue41458 (t * testing.T ) {
2534
2593
store := testkit .CreateMockStore (t )
0 commit comments