@@ -3615,3 +3615,94 @@ func TestIssue35181(t *testing.T) {
3615
3615
tk .MustExec ("set @@tidb_partition_prune_mode = 'dynamic'" )
3616
3616
tk .MustExec (`insert into t select * from t where a=3000` )
3617
3617
}
3618
+ << << << < HEAD
3619
+ == == == =
3620
+
3621
+ func TestIssue21732 (t * testing.T ) {
3622
+ store := testkit .CreateMockStore (t )
3623
+
3624
+ tk := testkit .NewTestKit (t , store )
3625
+ for _ , mode := range []variable.PartitionPruneMode {variable .StaticOnly , variable .DynamicOnly } {
3626
+ testkit .WithPruneMode (tk , mode , func () {
3627
+ tk .MustExec ("create database TestIssue21732" )
3628
+ tk .MustExec ("use TestIssue21732" )
3629
+ tk .MustExec ("drop table if exists p" )
3630
+ tk .MustExec (`create table p (a int, b int GENERATED ALWAYS AS (3*a-2*a) VIRTUAL) partition by hash(b) partitions 2;` )
3631
+ tk .MustExec ("alter table p add unique index idx (a, b);" )
3632
+ tk .MustExec ("insert into p (a) values (1),(2),(3);" )
3633
+ tk .MustExec ("select * from p ignore index (idx);" )
3634
+ tk .MustQuery ("select * from p use index (idx)" ).Sort ().Check (testkit .Rows ("1 1" , "2 2" , "3 3" ))
3635
+ tk .MustExec ("drop database TestIssue21732" )
3636
+ })
3637
+ }
3638
+ }
3639
+
3640
+ func TestIssue39999 (t * testing.T ) {
3641
+ store := testkit .CreateMockStore (t )
3642
+
3643
+ tk := testkit .NewTestKit (t , store )
3644
+
3645
+ tk .MustExec (`create schema test39999` )
3646
+ tk .MustExec (`use test39999` )
3647
+ tk .MustExec (`drop table if exists c, t` )
3648
+ tk .MustExec ("CREATE TABLE `c` (" +
3649
+ "`serial_id` varchar(24)," +
3650
+ "`occur_trade_date` date," +
3651
+ "`txt_account_id` varchar(24)," +
3652
+ "`capital_sub_class` varchar(10)," +
3653
+ "`occur_amount` decimal(16,2)," +
3654
+ "`broker` varchar(10)," +
3655
+ "PRIMARY KEY (`txt_account_id`,`occur_trade_date`,`serial_id`) /*T![clustered_index] CLUSTERED */," +
3656
+ "KEY `idx_serial_id` (`serial_id`)" +
3657
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci " +
3658
+ "PARTITION BY RANGE COLUMNS(`serial_id`) (" +
3659
+ "PARTITION `p202209` VALUES LESS THAN ('20221001')," +
3660
+ "PARTITION `p202210` VALUES LESS THAN ('20221101')," +
3661
+ "PARTITION `p202211` VALUES LESS THAN ('20221201')" +
3662
+ ")" )
3663
+
3664
+ tk .MustExec ("CREATE TABLE `t` ( " +
3665
+ "`txn_account_id` varchar(24), " +
3666
+ "`account_id` varchar(32), " +
3667
+ "`broker` varchar(10), " +
3668
+ "PRIMARY KEY (`txn_account_id`) /*T![clustered_index] CLUSTERED */ " +
3669
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" )
3670
+
3671
+ tk .MustExec ("INSERT INTO `c` (serial_id, txt_account_id, capital_sub_class, occur_trade_date, occur_amount, broker) VALUES ('2022111700196920','04482786','CUST','2022-11-17',-2.01,'0009')" )
3672
+ tk .MustExec ("INSERT INTO `t` VALUES ('04482786','1142927','0009')" )
3673
+
3674
+ tk .MustExec (`set tidb_partition_prune_mode='dynamic'` )
3675
+ tk .MustExec (`analyze table c` )
3676
+ tk .MustExec (`analyze table t` )
3677
+ query := `select
3678
+ /*+ inl_join(c) */
3679
+ c.occur_amount
3680
+ from
3681
+ c
3682
+ join t on c.txt_account_id = t.txn_account_id
3683
+ and t.broker = '0009'
3684
+ and c.occur_trade_date = '2022-11-17'`
3685
+ tk .MustQuery ("explain " + query ).Check (testkit .Rows ("" +
3686
+ "IndexJoin_22 1.00 root inner join, inner:TableReader_21, outer key:test39999.t.txn_account_id, inner key:test39999.c.txt_account_id, equal cond:eq(test39999.t.txn_account_id, test39999.c.txt_account_id)" ,
3687
+ "├─TableReader_27(Build) 1.00 root data:Selection_26" ,
3688
+ "│ └─Selection_26 1.00 cop[tikv] eq(test39999.t.broker, \" 0009\" )" ,
3689
+ "│ └─TableFullScan_25 1.00 cop[tikv] table:t keep order:false" ,
3690
+ "└─TableReader_21(Probe) 1.00 root partition:all data:Selection_20" ,
3691
+ " └─Selection_20 1.00 cop[tikv] eq(test39999.c.occur_trade_date, 2022-11-17 00:00:00.000000)" ,
3692
+ " └─TableRangeScan_19 1.00 cop[tikv] table:c range: decided by [eq(test39999.c.txt_account_id, test39999.t.txn_account_id) eq(test39999.c.occur_trade_date, 2022-11-17 00:00:00.000000)], keep order:false" ))
3693
+ tk .MustQuery (query ).Check (testkit .Rows ("-2.01" ))
3694
+
3695
+ // Add the missing partition key part.
3696
+ tk .MustExec (`alter table t add column serial_id varchar(24) default '2022111700196920'` )
3697
+ query += ` and c.serial_id = t.serial_id`
3698
+ tk .MustQuery (query ).Check (testkit .Rows ("-2.01" ))
3699
+ tk .MustQuery ("explain " + query ).Check (testkit .Rows ("" +
3700
+ `IndexJoin_20 0.80 root inner join, inner:TableReader_19, outer key:test39999.t.txn_account_id, test39999.t.serial_id, inner key:test39999.c.txt_account_id, test39999.c.serial_id, equal cond:eq(test39999.t.serial_id, test39999.c.serial_id), eq(test39999.t.txn_account_id, test39999.c.txt_account_id)` ,
3701
+ `├─TableReader_25(Build) 0.80 root data:Selection_24` ,
3702
+ `│ └─Selection_24 0.80 cop[tikv] eq(test39999.t.broker, "0009"), not(isnull(test39999.t.serial_id))` ,
3703
+ `│ └─TableFullScan_23 1.00 cop[tikv] table:t keep order:false` ,
3704
+ `└─TableReader_19(Probe) 0.80 root partition:all data:Selection_18` ,
3705
+ ` └─Selection_18 0.80 cop[tikv] eq(test39999.c.occur_trade_date, 2022-11-17 00:00:00.000000)` ,
3706
+ ` └─TableRangeScan_17 0.80 cop[tikv] table:c range: decided by [eq(test39999.c.txt_account_id, test39999.t.txn_account_id) eq(test39999.c.serial_id, test39999.t.serial_id) eq(test39999.c.occur_trade_date, 2022-11-17 00:00:00.000000)], keep order:false` ))
3707
+ }
3708
+ >> >> >> > 4 a72171ffb (* : Fix issue 39999 , used wrong column id list for checking partitions (#40003 ))
0 commit comments